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("")
...        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 =
...    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

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


  • 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.2.0 (2021-05-17)

Backward-incompatible changes:



  • This is the last release supporting Python versions older than 3.7.


Full changelog.


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.

Download files

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

Files for environ-config, version 21.2.0
Filename, size File type Python version Upload date Hashes
Filename, size environ_config-21.2.0-py2.py3-none-any.whl (19.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size environ-config-21.2.0.tar.gz (43.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page