Boilerplate-free configuration with env variables.
Project description
environ-config: Application Configuration With Env Variables
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.
-
Built on top of attrs which gives you data validation and conversion for free.
-
Pluggable secrets extraction. Ships with:
- HashiCorp Vault support via envconsul.
- AWS Secrets Manager (needs boto3)
- INI files, because secrets in env variables are icky.
-
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. It targets Python 3.7 and newer, and PyPy. Development takes place on GitHub.
The development is kindly supported by Variomedia AG.
environ-config wouldn't be possible without the attrs project.
environ-config for Enterprise
Available as part of the Tidelift Subscription.
The maintainers of structlog 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
Backwards-incompatible Changes
none
Deprecations
none
Changes
environ.secrets.DirectorySecrets.from_path()
now works when loading fromos.environ
. #45- Public APIs now carry type hints (except in-class methods like
AppConfig.from_environ()
). #49
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-23.1.0.tar.gz
.
File metadata
- Download URL: environ_config-23.1.0.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c7013910c1d4738df6b4cf379f597c6ea58b5f272cea0382b24f1eb51bff689 |
|
MD5 | 13c399749faa1bf86877e6d57f803ced |
|
BLAKE2b-256 | 6ee8fd351b5e920fe0a9c55d1e7557e89829cdb2f336c2e4fa07d79bb123757d |
File details
Details for the file environ_config-23.1.0-py3-none-any.whl
.
File metadata
- Download URL: environ_config-23.1.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 545162734328d5dd228e7ca48081db099eb9b0a8d4b5394e3c65f7a267c79c5f |
|
MD5 | 502a7a2f544485fde675baf87646fd5a |
|
BLAKE2b-256 | fda361b65f959f829064476cb97b396f1dbddecf235f9257e27f5acf4080dc1b |