Skip to main content
Version: 1.0

Read-only config

Example application


Sometimes you want to prevent a config node from being changed accidentally.


Structured Configs can enable it by passing frozen=True in the dataclass definition. Using Structured Configs, you can annotate a dataclass as frozen. This is recursive and applies to all child nodes.

This will prevent modifications via code, command line overrides and config composition.
@dataclass(frozen=True)class SerialPort:    baud_rate: int = 19200    data_bits: int = 8    stop_bits: int = 1

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

@hydra.main(config_name="config")def my_app(cfg: SerialPort) -> None:    print(cfg)

if __name__ == "__main__":    my_app()
$ python data_bits=10Error merging override data_bits=10Cannot change read-only config container    full_key: data_bits    reference_type=Optional[SerialPort]    object_type=SerialPort