envclasses
is a library to map fields on dataclass object to environment variables.
pip install envclasses
Declare a class with dataclass
and envclass
decorators.
from envclasses import envclass, load_env
from dataclasses import dataclass
@envclass
@dataclass
class Foo:
v: int
foo = Foo(v=10)
load_env(foo, prefix='foo')
print(foo)
Run the script
$ python foo.py
Foo(v=10)
Run with environment variable
$ FOO_V=100 python foo.py
Foo(v=100)