Supported backends

The following backends are supported as of version 1.0.1:

  • commandline arguments (using argparse)
  • environment variables
  • ConfigObj files
  • JSON files
  • YAML files (using PyYAML)

backend interface

All backends implement the same interface, which allows for easy addition of new (or external backends).

class omniconf.backends.generic.ConfigBackend(conf=None)[source]

Defines a configuration backend, which provides configuration values based on keys.

classmethod autoconfigure(conf, autoconfigure_prefix)[source]

Called with a ConfigRegistry, the result of this method must be either a new instance of this class, or None. This method is automatically called during the autoconfigure phase.

classmethod autodetect_settings(autoconfigure_prefix)[source]

Returns a tuple of Setting objects, that are required for autoconfigure() to complete successfully.

get_value(key)[source]

Retrieves the value for the given key.

commandline arguments

Command line arguments are implemented using argparse. This backend is enabled by default.

class omniconf.backends.argparse.ArgparseBackend(conf=None, prefix=None)[source]

Uses the current process arguments, and allows values in it to be retrieved using dotted keys with a specific prefix. By default no prefix is assumed.

get_value(key)[source]

Retrieves the value for the given key. Keys are converted as follows:

  • Dots are replaced by dashes (-).
  • The key is lowercased.
  • A prefix is attached to the key, if specified

This means that a key like section.value will be queried like --prefix-section-value. When no prefix is specified, --section-value is queried instead.

environment variables

Environments are read from os.environ. This backend is enabled by default.

class omniconf.backends.env.EnvBackend(conf=None, prefix=None)[source]

Uses the current process Environment, and allows values in it to be retrieved using dotted keys with a specific prefix. By default no prefix is assumed.

get_value(key)[source]

Retrieves the value for the given key. Keys are converted as follows:

  • Dots are replaced by underscores
  • The key is uppercased.
  • A prefix is attached to the key

This means that a key like section.value will be queried like PREFIX_SECTION_VALUE. When no prefix is specified, SECTION_VALUE is queried instead.

ConfigObj files

Files in ConfigObj format are supported. This backend is only enabled if omniconf.configobj.filename is specified during setup.

class omniconf.backends.configobj.ConfigObjBackend(conf)[source]

Uses a ConfigObj file (or StringIO instance) as a backend, and allows values in it to be retrieved using dotted keys.

Dots in the keys denote a section in the ConfigObj document. For instance, the key section.subsection.key will correspond to this document:

[section]
[[subsection]]
key=value

JSON files

Files in JSON format are supported. This backend is only enabled if omniconf.json.filename is specified during setup.

class omniconf.backends.json.JsonBackend(conf)[source]

Uses a JSON string as a backend, and allows values in it to be retrieved using dotted keys.

YAML files

Files in YAML format are supported. This backend is only enabled if omniconf.yaml.filename is specified during setup.

class omniconf.backends.yaml.YamlBackend(conf)[source]

Uses a YAML string as a backend, and allows values in it to be retrieved using dotted keys.