Skip to main content
Version: Next

A hierarchical static configuration

 Example

Dataclasses can be nested and then accessed via a common root. The entire tree is type checked.

@dataclassclass MySQLConfig:    host: str = "localhost"    port: int = 3306
@dataclassclass UserInterface:    title: str = "My app"    width: int = 1024    height: int = 768
@dataclassclass MyConfig:    db: MySQLConfig = MySQLConfig()    ui: UserInterface = UserInterface()
cs = ConfigStore.instance()cs.store(name="config", node=MyConfig)
@hydra.main(config_path=None, config_name="config")def my_app(cfg: MyConfig) -> None:    print(f"Title={cfg.ui.title}, size={cfg.ui.width}x{cfg.ui.height} pixels")
if __name__ == "__main__":    my_app()