Skip to main content

Boilerplate-free configuration with env variables.

Project description

Documentation Status CI Status Test Coverage Code style: black

environ-config allows you to configure your applications using environment variables – as recommended in The Twelve-Factor App methodology – with elegant, boilerplate-free, and declarative code:

>>> import environ
>>> # Extracts secrets from Vault-via-envconsul: 'secret/your-app':
>>> vault = environ.secrets.VaultEnvSecrets(vault_prefix="SECRET_YOUR_APP")
>>> @environ.config(prefix="APP")
... class AppConfig:
...    @environ.config
...    class DB:
...        name = environ.var("default_db")
...        host = environ.var("default.host")
...        port = environ.var(5432, converter=int)  # Use attrs's converters and validators!
...        user = environ.var("default_user")
...        password = vault.secret()
...
...    env = environ.var()
...    lang = environ.var(name="LANG")  # It's possible to overwrite the names of variables.
...    db = environ.group(DB)
...    awesome = environ.bool_var()
>>> cfg = environ.to_config(
...     AppConfig,
...     environ={
...         "APP_ENV": "dev",
...         "APP_DB_HOST": "localhost",
...         "LANG": "C",
...         "APP_AWESOME": "yes",  # true and 1 work too, everything else is False
...         # Vault-via-envconsul-style var name:
...         "SECRET_YOUR_APP_DB_PASSWORD": "s3kr3t",
... })  # Uses os.environ by default.
>>> cfg
AppConfig(env='dev', lang='C', db=AppConfig.DB(name='default_db', host='localhost', port=5432, user='default_user', password=<SECRET>), awesome=True)
>>> cfg.db.password
's3kr3t'

AppConfig.from_environ({...}) is equivalent to the code above, depending on your taste.

Features

  • Declarative & boilerplate-free.

  • Nested configuration from flat environment variable names.

  • Default & mandatory values: enforce configuration structure without writing a line of code.

  • Built on top of attrs which gives you data validation and conversion for free.

  • Pluggable secrets extraction. Ships with:

  • Helpful debug logging that will tell you which variables are present and what environ-config is looking for.

  • Built-in dynamic help documentation generation.

You can find the full documentation including a step-by-step tutorial on Read the Docs.

Project Information

environ-config is released under the Apache License 2.0 license. It targets Python 2.7, 3.5 and newer, and PyPy. Development takes place on GitHub.

Release Information

21.1.0 (2021-04-14)

Backward-incompatible changes:

none

Deprecations:

none

Changes:

  • Fixed environment variables’ names when prefix is empty. #14

  • Added the optional keyword argument to environ.group() #17

  • Added DirectorySecrets secret reader, which can read secrets from a directory of files. Useful for Docker or Kubernetes mounted secrets inside a container. #19

Full changelog.

Credits

environ-config is written and maintained by Hynek Schlawack – why not buy him a coffee for all the years of maintenance?

The development is kindly supported by Variomedia AG.

A full list of contributors can be found in GitHub’s overview.

environ-config wouldn’t be possible without the attrs project.

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

environ-config-21.1.0.tar.gz (42.2 kB view details)

Uploaded Source

Built Distribution

environ_config-21.1.0-py2.py3-none-any.whl (17.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file environ-config-21.1.0.tar.gz.

File metadata

  • Download URL: environ-config-21.1.0.tar.gz
  • Upload date:
  • Size: 42.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for environ-config-21.1.0.tar.gz
Algorithm Hash digest
SHA256 d82fa2f760ac031fb9f434be56a0a83e98dbeba8151cdd96feaf86cd17417dd9
MD5 de23d46ed5d2e12b000be48dd01c03c4
BLAKE2b-256 c03483416d86dbdf5dbc63087e6362571573a70defe8fd12bcf676e80e1c413a

See more details on using hashes here.

File details

Details for the file environ_config-21.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: environ_config-21.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for environ_config-21.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0d90ebafbc46b00d60d11694e3157d866833be250e7163bff27fed946192f1ed
MD5 5e130f0955fdccb301f527c56c15d61e
BLAKE2b-256 50245fe1603df06d97e5fe69435df3b8de709d49d3d7bbfc3e38983e4e2a9a11

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