Boilerplate-free configuration with env variables.
Project description
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:
HashiCorp Vault support via envconsul.
INI files, because secrets in env variables are icky.
Project Information
environ_config is released under the MIT license. It targets Python 2.7, 3.5 and newer, and PyPy.
Release Information
18.2.0 (2018-01-12)
Backward-incompatible changes:
Use RawConfigParser for ini-style secrets to avoid interpolation errors.
Changes:
none
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file environ_config-18.2.0.tar.gz
.
File metadata
- Download URL: environ_config-18.2.0.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45600572905e9785b0911ce0a563c2a8f6e589824f50d8d3541bd413f432e13e |
|
MD5 | cd13ad3fbc363995f46c51e607259bbc |
|
BLAKE2b-256 | 389fcffa1812244170ccafee0177884eab5a4bdff02002aaa9a59fbea604ff9c |
File details
Details for the file environ_config-18.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: environ_config-18.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bdec05c515676e0de2b794c10de4ceee9709b416945646a1f5bed5714a9cc29 |
|
MD5 | 5c251e41fb8300cf8a639db4420cb5e4 |
|
BLAKE2b-256 | 1f5cd507de8792b716caa6949272368a46a951c260db31673376b09ba1420fdb |