Skip to main content

Envier

Python application configuration from the environment

Synopsis

Envier is a Python library for extracting configuration from environment variables in a declarative and (eventually) 12-factor-app-compliant way.

Usage

The following example shows how to declare the configuration for an application that uses the MYAPP_DEBUG, MYAPP_SERVICE_HOST and MYAPP_SERVICE_PORT variables from the environment.

>>> from envier import Env
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     service_host = Env.var(str, "service.host", default="localhost")
>>>     service_port = Env.var(int, "service.port", default=3000)
>>> 
>>>     _is_default_port = Env.der(bool, lambda c: c.service_port == c.spec.service_port.default)
>>> 
>>> config = GlobalConfig()
>>> config.service_port
3000
>>> config._is_default_port
True

Configurations can also be nested to create namespaces:

>>> from envier import Env
>>> 
>>> class ServiceConfig(Env):
>>>     __prefix__ = "service"
>>> 
>>>     host = Env.var(str, "host", default="localhost")
>>>     port = Env.var(int, "port", default=3000)
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     service = ServiceConfig
>>> 
>>> config = GlobalConfig()
>>> config.service.port
3000

The same configuration can be obtained with implicit nesting by declaring the ServiceConfig subclass inside GlobalConfig, and setting the class attribute __item__ to the name of the item the sub-configuration should be assigned to, viz.

>>> from envier import Env
>>> 
>>> class GlobalConfig(Env):
>>>     __prefix__ = "myapp"
>>>     
>>>     debug_mode = Env.var(bool, "debug", default=False)
>>> 
>>>     class ServiceConfig(Env):
>>>         __item__ = __prefix__ = "service"
>>>         
>>>         host = Env.var(str, "host", default="localhost")
>>>         port = Env.var(int, "port", default=3000)
>>> 
>>> config = GlobalConfig()
>>> config.service.port
3000

Type Checking

The library ships with a mypy plugin to allow for type checking. If you want to use it, either install the library with the mypy extra or ensure that mypy is installed, and then add envier.mypy to the list of extra plugins in the mypy configuration.

Roadmap

  • Add support for environment files.
  • Rely on type hints as support for older versions of Python is dropped.
  • Derivations might require an evaluation order.

Metadata

Release files for envier 0.6.1

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

Source distribution (sdist)

Source distribution for envier 0.6.1
File Size Uploaded
envier-0.6.1.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envier 0.6.1
File Interpreter ABI Platform
envier-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / envier-0.6.1.tar.gz

Download URL envier-0.6.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3309a01bb3d8850c9e7a31a5166d5a836846db2faecb79b9cb32654dd50ca9f9
BLAKE2b-256 checksum
How to use checksums
19e74fe4d3f6e21213cea9bcddc36ba60e6ae4003035f9ce8055e6a9f0322ddb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release files / envier-0.6.1-py3-none-any.whl

Download URL envier-0.6.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73609040a76be48bbcb97074d9969666484aa0de706183a6e9ef773156a8a6a9
BLAKE2b-256 checksum
How to use checksums
56e930493b1cc967f7c07869de4b2ab3929151a58e6bb04495015554d24b61db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.2

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

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