Config

class lsst.daf.butler.Config(other=None)

Bases: collections.abc.MutableMapping

Implements a datatype that is used by Butler for configuration parameters.

It is essentially a dict with key/value pairs, including nested dicts (as values). In fact, it can be initialized with a dict. This is explained next:

Config extends the dict api so that hierarchical values may be accessed with delimited notation or as a tuple. If a string is given the delimiter is picked up from the first character in that string. For example, foo.getValue(".a.b.c"), foo["a"]["b"]["c"], foo["a", "b", "c"], foo[".a.b.c"], and foo["/a/b/c"] all achieve the same outcome. If the first character is alphanumeric, no delimiter will be used. foo["a.b.c"] will be a single key a.b.c as will foo[":a.b.c"]. Unicode characters can be used as the delimiter for distinctiveness if required.

If a key in the hierarchy starts with a non-alphanumeric character care should be used to ensure that either the tuple interface is used or a distinct delimiter is always given in string form.

Finally, the delimiter can be escaped if it is part of a key and also has to be used as a delimiter. For example, foo[r".a.b\.c"] results in a two element hierarchy of a and b.c. For hard-coded strings it is always better to use a different delimiter in these cases.

Note that adding a multi-level key implicitly creates any nesting levels that do not exist, but removing multi-level keys does not automatically remove empty nesting levels. As a result:

>>> c = Config()
>>> c[".a.b"] = 1
>>> del c[".a.b"]
>>> c["a"]
Config({'a': {}})

Storage formats supported:

  • yaml: read and write is supported.
Parameters:
other : str or Config or dict

Other source of configuration, can be:

  • (str) Treated as a path to a config file on disk. Must end with “.yaml”.
  • (Config) Copies the other Config’s values into this one.
  • (dict) Copies the values from the dict into this Config.

If None is provided an empty Config will be created.