Configuration with env variables for Python
Switch branches/tags
Nothing to show
Clone or download
Latest commit 69b1c8a Jan 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/environ Start new development cycle Jan 12, 2018
tests Use RawConfigParser Jan 12, 2018
.coveragerc Initial Jan 11, 2017
.gitignore Fix prefix handling Feb 13, 2017
.travis.yml Test PyPy 3 Dec 11, 2017
AUTHORS.rst Initial Jan 11, 2017
CHANGELOG.rst Prepare 18.2.0 Jan 12, 2018
LICENSE Initial Jan 11, 2017
MANIFEST.in Initial Jan 11, 2017
README.rst Fix for attrs 17.4 Jan 4, 2018
conftest.py Prepare for public release Dec 14, 2017
setup.cfg Show warnings Dec 16, 2017
setup.py Fix for attrs 17.4 Jan 4, 2018
tox.ini Fix for attrs 17.4 Jan 4, 2018

README.rst

environ_config: Configuration with env variables for Python.

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.