Skip to main content

Boilerplate-free configuration with env variables.

Project description

CI status Test Coverage

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'

Features

  • Declarative & boilerplate-free.

  • Nested config from flat env variable names.

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

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

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

  • Plugable secrets extraction. Ships with:

Project Information

environ_config is released under the MIT license. It targets Python 2.7, 3.5 and newer, and PyPy.

Release Information

18.1.0 (2018-01-04)

Backward-incompatible changes:

  • convertconverter

Deprecations:

none

Changes:

  • Fix for attrs 17.4.0.

Full changelog.

Credits

environ_config is written and maintained by Hynek Schlawack.

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-18.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

environ_config-18.1.0-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file environ_config-18.1.0.tar.gz.

File metadata

File hashes

Hashes for environ_config-18.1.0.tar.gz
Algorithm Hash digest
SHA256 a556edd81edfedd049598e47b781e2164445d4001126fff9f7b7755de7542df3
MD5 c124b15a0d8a54de3b599ac7e1bd1e46
BLAKE2b-256 14c9f51d513e414537cbf6407a4783692a07bca54da115b5f47f6eaad444b417

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for environ_config-18.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0b0847a950dde43101f17ba640ce3c801467dbe9641838f09c83703321b26667
MD5 0157e348b8d0af90450dc3d12ea52d9d
BLAKE2b-256 974a90b57bdb834259aa3c89eca03ff72cb55dd8861aba76b60006b1335713d3

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