Config containers
OmegaConf.create() with no argument makes an empty DictConfig. A
dictionary also becomes a DictConfig, while a list becomes a ListConfig.
These containers can be nested. Each key or list position is a node, but
reading it gives you its value. For example:
>>> from omegaconf import OmegaConf
>>> cfg = OmegaConf.create({
... "server": {
... "host": "localhost",
... "port": 80,
... },
... "users": ["a", "b"],
... })
>>> cfg.server.port
80
>>> cfg["server"]["port"]
80
>>> cfg.users[0]
'a'
Use attribute access for keys that work as Python attributes. Item access also
works for other keys and for list positions. You can change a value or add a
key to a DictConfig created from a plain dictionary:
>>> cfg.server.port = 8080
>>> cfg.server["public-host"] = "example.org"
>>> cfg.server["public-host"]
'example.org'
Use .get("key", default) when a mapping key may not exist. To pass a config
to code expecting plain Python containers, use
OmegaConf.to_container().
Dictionary keys may be str, int, bool, float, bytes, or Enum members.
An integer path element can refer to either the integer key 1 or the string
key "1"; a DictConfig cannot contain both because the path would be
ambiguous. This fallback does not infer other non-string key types from path
text.
Sequence containers
Lists become mutable ListConfig values. In 2.4, tuples become immutable
TupleConfig values. Use a list when you need to change individual elements;
replace the whole tuple when you need different tuple contents. The
tuple migration guide explains the change from
earlier releases.
Next, learn how to mark a value as missing when it must be provided later.