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

Question:

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

Asked By: Rylan Schaeffer

||

Answers:

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'}
Answered By: Omry Yadan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.