Skip to main content
Version: 1.1

Using the config object

 Example

Here are some basic features of the Hydra Configuration Object:

config.yaml
node: # Config is hierarchical
loompa: 10 # Simple value
zippity: ${node.loompa} # Value interpolation
do: "oompa ${node.loompa}" # String interpolation
waldo: ??? # Missing value, must be populated prior to access
main.py
@hydra.main(config_path=".", config_name="config")
def my_app(cfg: DictConfig):
assert cfg.node.loompa == 10 # attribute style access
assert cfg["node"]["loompa"] == 10 # dictionary style access
assert cfg.node.zippity == 10 # Value interpolation
assert isinstance(cfg.node.zippity, int) # Value interpolation type
assert cfg.node.do == "oompa 10" # string interpolation
cfg.node.waldo # raises an exception

Outputs:

$ python my_app.py
Traceback (most recent call last):
File "my_app.py", line 32, in my_app
cfg.node.waldo
omegaconf.errors.MissingMandatoryValue: Missing mandatory value: node.waldo
full_key: node.waldo
object_type=dict

Hydra's configuration object is an instance of OmegaConf's DictConfig. You can learn more about OmegaConf here.

Last updated on by Jasha10