Skip to main content
Version: Next

A hierarchical static configuration

Β Example (Click Here)

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

from dataclasses import dataclass

import hydra
from hydra.core.config_store import ConfigStore

class MySQLConfig:
host: str = "localhost"
port: int = 3306

class UserInterface:
title: str = "My app"
width: int = 1024
height: int = 768

class MyConfig:
db: MySQLConfig = field(default_factory=MySQLConfig)
ui: UserInterface = field(default_factory=UserInterface)

cs = ConfigStore.instance()"config", node=MyConfig)

@hydra.main(version_base=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__":