Registry / serialization / environ-config

environ-config

JSON →
library24.1.0pypypi✓ verified 86d ago

A Python library for boilerplate-free configuration using environment variables. Current version 24.1.0 (released 2024-10-27) with type annotations, minimal setup, and a decorator-based approach. Maintenance release with tests/docs updates.

pip install environ-config
INSTALL
IMPORT
SIG · ENVIRON-CONFIG
E
environ-config
serializationpythonv24.1.0
Install
1.6s avg
Import
116ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.118s · 18.4MB
glibc
py 3.103.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}')
Debug
Known issues
gotchaEnvironment variables are read at class instantiation time, not import time. The values are fixed once the object is created; subsequent changes to env vars require a new instance.
fix
Create a fresh config object when you need updated values, or use a singleton pattern that re-reads on each access.
affects: all
deprecatedAs of 23.1.0, type annotations are required for all fields. Omitting type hint will raise a TypeError.
fix
Always add type annotations to config fields, e.g., host: str.
affects: >=23.1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'environ_config'
The package name is 'environ-config' but the import module is 'environ'.
fix
Use '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.
fix
Ensure 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.
fix
Set 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.

Agent activity
2 hits · last 30 days
node
2
Resources
environ-config — pip install environ-config · libregistry