Skip to main content

No project description provided

Project description

Envolved

Envolved is a library to make environment variable parsing powerful and effortless.

documentation: https://envolved.readthedocs.io/en/latest/

from envolved import env_var, EnvVar

# create an env var with an int value
foo: EnvVar[int] = env_var('FOO', type=int, default=0)
value_of_foo = foo.get()  # this method will check for the environment variable FOO, and parse it as an int

# we can also have some more complex parsers
from typing import List, Optional
from envolved.parsers import CollectionParser

foo = env_var('FOO', type=CollectionParser(',', int))
foo.get()  # now we will parse the value of FOO as a comma-separated list of ints

# we can also use schemas to combine multiple environment variables
from dataclasses import dataclass


@dataclass
# say we want the environment to describe a ConnectionSetting
class ConnectionSetting:
    host: str
    port: int
    user: Optional[str]
    password: Optional[str]


connection_settings: EnvVar[ConnectionSetting] = env_var('service_', type=ConnectionSetting, args={
    'host': env_var('hostname'),
    # we now define an env var as an argument. Its suffix will be "hostname", and its type will be inferred from the
    # type's annotation
    'port': env_var('port'),
    'user': env_var('username', type=str),  # for most types, we can infer the type from the annotation, though we can
    # also override it if we want
    'password': env_var('password', type=str, default=None)  # we can also set a default value per arg
})
service_connection_settings: ConnectionSetting = connection_settings.get()
# this will look in 4 environment variables:
# host will be extracted from service_hostname
# port will be extracted from service_port, then converted to an int
# user will be extracted from service_username
# password will be extracted from service_password, and will default to None
# finally, ConnectionSetting will be called with the parameters

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

envolved-1.6.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

envolved-1.6.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file envolved-1.6.0.tar.gz.

File metadata

  • Download URL: envolved-1.6.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure

File hashes

Hashes for envolved-1.6.0.tar.gz
Algorithm Hash digest
SHA256 b4002dc5b5a49f3a29c81eb162904c7e39899d382493de638fedb2fd0f58d4b2
MD5 951abb51edb118e42ae3de754a3d6b78
BLAKE2b-256 2aa1772161cf2664d0b659dbb7af229faa85f3bda5e38befe1326e24f2f02556

See more details on using hashes here.

File details

Details for the file envolved-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: envolved-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.5.0-1021-azure

File hashes

Hashes for envolved-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4542f69617970abe90c303b76a45a0d66d74d680b3201b33da85e204c53bf10
MD5 6874f6589153c9dc7f8b44e71a812399
BLAKE2b-256 f561cba5eb10abe7b5bb2796c9867baeefa52065e47a3409b866585d0d6dabc4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page