A simple config system where you define your config using dataclasses with defaults, and then can specify overrides on the command line.
There are lots of existing options for this (e.g. typed-argument-parser, Hydra). None of them were quite right for me, so I wrote my own.
- Very simple
- Statically type checkable
- Convert the parsed config to a dict using
dataclasses.asdict()
to pass it to e.g. Weights & Biases
Future plans:
- Allow defining multiple sets of default values
@dataclass
class Config:
subconfig: SubConfig = SubConfig()
option1: int = 3
option2: Optional[str] = None
@dataclass
class SubConfig:
option: tuple[int, int] = (3, 5)
def main(config: Config) -> None:
...
if __name__ == "__main__":
main(typed_configs.parse(Config))
Then, you can override options on the command line: python script.py option1=5 subconfig.option=(1,2)
- Set up environment by installing Poetry and running
poetry install
- Format with
black **/*.py
,isort **/*.py
- Run type checker with
mypy -p typed_configs
- Run tests with
pytest