environ-config: Application Configuration With Env Variables
![Downloads / Month](https://static.pepy.tech/personalized-badge/environ-config?period=month&units=international_system&left_color=grey&right_color=blue&left_text=Downloads%20/%20Month)
environ-config allows you to load your application's configuration from environment variables – as recommended in The Twelve-Factor App methodology – with elegant, boilerplate-free, and declarative code:
>>> import environ
>>>
>>> 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)
... user = environ.var("default_user")
... password = vault.secret()
...
... env = environ.var()
... lang = environ.var(name="LANG")
... 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",
...
... "SECRET_YOUR_APP_DB_PASSWORD": "s3kr3t",
... })
>>> 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 maintained by Hynek Schlawack and is released under the Apache License 2.0 license.
Development takes place on GitHub.
The development is kindly supported by Variomedia AG and all my amazing GitHub Sponsors.
environ-config wouldn't be possible without the attrs project.
environ-config for Enterprise
Available as part of the Tidelift Subscription.
The maintainers of environ-config and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications.
Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
Learn more.
Release Information
Added
-
Support for Python 3.13.
-
Support for Moto 5.
#76
Removed
Full Changelog →