API

Config

class configly.Config(value=None, _src_input=None, _loader=None, _registry=<configly.registry.Registry object>)

Container for configuration.

>>> config = Config({"a": 1, "b": {"c": 2}})
>>> config.a
1
>>> config.b.c
2
classmethod from_json(file, registry=<configly.registry.Registry object>)

Open a toml file and load it into the resulting config object.

classmethod from_toml(file, registry=<configly.registry.Registry object>)

Open a toml file and load it into the resulting config object.

classmethod from_yaml(file, registry=<configly.registry.Registry object>)

Open a yaml file and load it into the resulting config object.

refresh()

Reevaluate the interpolation of variable values in the given sub-config.

This will be particularly useful for values which are coming from sources where the value might change.

to_dict()

Return a dict equivalent of the config object.

Roughly equivalent to >>> dict(Config({1:1})) == Config({1:1}).to_dict() True

class configly.Interpolator

ABC to define the interface required by an interpolator.

It is not required to subclass Interpolator, but it does provide the interface and ensures the class implements it.

__getitem__(name)

Override this method to implement a method to get the value for a piece of config.

This method should return a KeyError when the value cannot be found.

get(name, default=None)

Implement get operation with a default.

Override this method to get more tailored behavior.

class configly.Registry

A registry to allow for non-bundled interpolators and config loaders to be added.

By default Config uses a global registry, to which you can register_interpolator.

If you need more flexibility, you can pass registry to any of the from_* classmethods to use your own registry.

>>> from configly import Config
>>> local_registry = Registry()
>>> config = Config.from_yaml('readthedocs.yml', registry=local_registry)
register_interpolator(name, interpolator_cls, overwrite=False)

Register a new interpolator for loading configuration from different sources.

By default Config classes read from a global registry of interpolators. This function registers new interpolators to that global registry.

For example, internally configly registers environment interpolation through a call like:

>>> from configly import EnvVarInterpolator
>>> register_interpolator("ENV", EnvVarInterpolator, overwrite=True)