Skip to main content

environ-config: Application Configuration With Env Variables

Documentation License: Apache 2.0 PyPI version Downloads / Month

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:

  • 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

Fixed

  • Type hints for environ.config() now allow for arguments (e.g. @environ.config(prefix="")). #56

Full Changelog

Release files for environ-config 23.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for environ-config 23.2.0
File Size Uploaded
environ_config-23.2.0.tar.gz 44.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for environ-config 23.2.0
File Interpreter ABI Platform
environ_config-23.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.5 kB

Release files / environ_config-23.2.0.tar.gz

Download URL environ_config-23.2.0.tar.gz
Size 44.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e83fa15efbd7ab7130268c33992d9d42747232315d05586e5276c96ee89020f9
BLAKE2b-256 checksum
How to use checksums
b31faff64afe6692596238c564dada1631cf472124cdeb57654f5f95f32cbefb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / environ_config-23.2.0-py3-none-any.whl

Download URL environ_config-23.2.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20a60f90a0a9e80d7d5ed92060a8fbb9b7b016ba34bda85361ec376340013be9
BLAKE2b-256 checksum
How to use checksums
da286ad9ff2b4dc27bd12ab46c57adfae7f34f42bf17595b5426b667f3f7bb61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

26.1.0

2 release files

This release

23.2.0 This release

2 release files

23.1.0

2 release files

21.2.0

2 release files

21.1.0

2 release files

20.1.0

2 release files

18.2.0

2 release files

17.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page