Search code examples
pythonfb-hydraomegaconf

Convert hydra/omegaconf config to python nested dict/list?


I'd like to convert a OmegaConf/Hydra config to a nested dictionary/list. How can I do this?


Solution

  • See OmegaConf.to_container().

    Usage snippet:

    >>> conf = OmegaConf.create({"foo": "bar", "foo2": "${foo}"})
    >>> assert type(conf) == DictConfig
    >>> primitive = OmegaConf.to_container(conf)
    >>> show(primitive)
    type: dict, value: {'foo': 'bar', 'foo2': '${foo}'}
    >>> resolved = OmegaConf.to_container(conf, resolve=True)
    >>> show(resolved)
    type: dict, value: {'foo': 'bar', 'foo2': 'bar'}