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'
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.
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.
Pluggable secrets extraction. Ships with:
HashiCorp Vault support via envconsul.
INI files, because secrets in env variables are icky.
Pass any dictionary into environ.to_config(AppConfig, {"your": "config"}) instead of loading from the environment.
Built in dynamic help documentation generation via environ.generate_help.
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
20.1.0 (2020-03-23)
Backward-incompatible changes:
none
Deprecations:
none
Changes:
Configurations can be immutable now. #12
Credits
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.
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-20.1.0.tar.gz
.
File metadata
- Download URL: environ-config-20.1.0.tar.gz
- Upload date:
- Size: 38.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3167feda073bd3cd3457a3e5fa7c2836b6574c046cd0dcd79385ce3284e837bd |
|
MD5 | 529d01100a504fad4c496714dee941b0 |
|
BLAKE2b-256 | 1b7e21d2777fd3a144027b1996aa6f09358a32c3b9f46d396e4fdded21647832 |
File details
Details for the file environ_config-20.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: environ_config-20.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e300307520c1e6a5424018b7f70246a2c7f4cb5cc5cbbebccc6a982eb1767cb |
|
MD5 | 275b4abe5111fb3c10ec8594b0b7d7f8 |
|
BLAKE2b-256 | ebbdca1dea3acce3a626bf6954301cc6c60d893a34abbcdaf8cf6d7517470532 |