Install & Compatibility
Where this runs
tested against v24.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.118s · 18.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.114s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
environ-config
✓ import environ
✗ import environ_config
The package name on PyPI is 'environ-config' but the import module is 'environ'. Using 'environ_config' will raise ModuleNotFoundError.
environ.config
✓ from environ import config
✗ import environ; environ.config()
Common but the correct way is to import the config class directly. Both work, but direct import is idiomatic.
Define a configuration class with a decorator. Annotate fields; they are automatically populated from environment variables with the given prefix. Defaults are allowed.
import os
from environ import config
@config
class MyConfig:
prefix = 'MYAPP'
host: str
port: int = 8080
cfg = MyConfig()
print(f'Host: {cfg.host}, Port: {cfg.port}')
os.environ['MYAPP_HOST'] = 'example.com'
os.environ['MYAPP_PORT'] = '9090'
cfg2 = MyConfig()
print(f'Host: {cfg2.host}, Port: {cfg2.port}')
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'environ_config'
The package name is 'environ-config' but the import module is 'environ'.
fixUse 'import environ' instead.
TypeError: __init_subclass__() missing 1 required positional argument: 'cls'
Using @config on a class that is a subclass of something other than object, or misusing the decorator.
fixEnsure the class decorated with @config does not inherit from another class unless it's also a config class.
AttributeError: 'MyConfig' object has no attribute 'host'
The environment variable is not set and there is no default value.
fixSet the environment variable or provide a default in the field definition (e.g., host: str = 'localhost').
Upgrade
Version history
24.1.0latest on PyPI · released Aug 8, 2024
Audit
Dependencies
No dependency data recorded yet.