Skip to main content

Boilerplate-free configuration with env variables.

Project description

environ-config: Application Configuration With Env Variables

Documentation License: Apache 2.0 PyPI version No AI slop inside. Downloads / Month

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
>>> # 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. 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.

Release Information

Removed

  • Support for Python 3.8 and 3.9. #134

  • Support for attrs older than 21.3.0 (the one that introduced the attrs namespace). #134

Added

  • Support for Python 3.14 and 3.15. #134

Changed

  • environ-config now uses @attrs.define et al instead of @attr.s to help with typing support. This should not make any difference in practice, but people doing weird things (I know y'all are out there!) might run into paper cuts. #134

  • Secrets are now handled like environment variables in optional groups, so that if all secrets (and environment variables) are missing, the group becomes None. This change also causes the MissingSecretError exceptions to include all missing secrets, not just the first one. #100

Fixed

  • Type hints for environ.group() now respects the optional argument. #98

Full Changelog →

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

environ_config-26.1.0.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

environ_config-26.1.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file environ_config-26.1.0.tar.gz.

File metadata

  • Download URL: environ_config-26.1.0.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for environ_config-26.1.0.tar.gz
Algorithm Hash digest
SHA256 7fe80885d22dd50218664c1e4e2c098429129387ddbb6e51318a3883639ae8b4
MD5 58c5e83fe148947159dfd2bbc0dd747e
BLAKE2b-256 ee893522cca1a75b061e2d92ffbaf285beaf9866ee452ac78c0c6de84c7ff118

See more details on using hashes here.

Provenance

The following attestation bundles were made for environ_config-26.1.0.tar.gz:

Publisher: pypi-package.yml on hynek/environ-config

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file environ_config-26.1.0-py3-none-any.whl.

File metadata

  • Download URL: environ_config-26.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for environ_config-26.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5920e1c25f301c252f2e7eff0d64538b78a668311d730492664ee39f746b7dc
MD5 4d30ec9ffcbfb7441133ed48a308b28a
BLAKE2b-256 7ad82c7722de2e8719d0aed0e4b5380258ea0df3ee2b29aaef7baf1d5e79a7b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for environ_config-26.1.0-py3-none-any.whl:

Publisher: pypi-package.yml on hynek/environ-config

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page