Skip to content

envclasses is a library to map fields on dataclass object to environment variables.

License

Notifications You must be signed in to change notification settings

yukinarit/envclasses

Repository files navigation

envclasses

image image Test

envclasses is a library to map fields on dataclass object to environment variables.

Installation

pip install envclasses

Usage

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)