loki.config module

class Configuration(name=None)

Bases: OrderedDict

Dictionary class that holds global configuration parameters.

In addition to sanity checking this dict also allows callbacks to be used to propagate values to the relevant parts of the system.

Example usage:

config = Configuration('Loki')
config.register('log-level', 'INFO', env_variable='LOKI_LOGGING')
...

config.initialize()
logging = config['log-level']
initialize()

Initialize all registered entries by either using the value given via environemnt variables or the default.

register(key, default, env_variable=None, preprocess=None, callback=None)

Register configuration option with optional default value and callback function.

Parameters:
  • key (str) – Internal name of the configuration option

  • default – Default value if unspecified in environment

  • env_variable (str) – Name of environment variable to check for value

  • preprocess – Optional preprocess function that turns string-based values into the correct format (eg. for env variables)

  • callback – Optional callback function to trigger on updates

print_state()

Print the current configuration state.

config_override(settings)

Simple context manager for testing purposes that temporarily overrides config options with :param:`settings` and restores the original after.