Skip to content

Define configs using Python dataclasses and override them on the CLI

License

Notifications You must be signed in to change notification settings

oscarkey/typed-configs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typed-configs

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.

Features

  • 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

Usage

@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)

Dev

  • 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

About

Define configs using Python dataclasses and override them on the CLI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages