Load a data class from diffrent sources. Including: Environment Variables, YAML files, and, ....
main.py
from dataclasses import dataclass
from dcloader import EnvLoader, Loader, YAMLLoader
@dataclass
class Leaf:
node: str
@dataclass
class Root:
leaf: Leaf
node: int
loader = Loader([EnvLoader(prefix="CONFIG"), YAMLLoader("config.yaml")])
cfg = loader.load(Root)
print(cfg)
config.yaml
leaf:
node: value
$ export CONFIG_NODE=12
$ python main.py