Available sources

class layeredconfig.Defaults(defaults=None, **kwargs)

This source is initialized with a dict.

Parameters:defaults (dict) – A dict with configuration keys and values. If any values are dicts, these are turned into nested config objects.
class layeredconfig.Environment(environ=None, prefix=None, lower=True, sectionsep='_', **kwargs)

Loads settings from environment variables. If prefix is set to MYAPP_, the value of the environment variable MYAPP_HOME will be available as the configuration setting home.

Parameters:
  • environ (dict) – Environment variables, in dict form like os.environ. If not provided, uses the real os.environ.
  • prefix (str) – Since the entire environment is not suitable to use as a configuration, only variables starting with this prefix are used.
  • lower (True) – If true, lowercase the name of environment variables (since these typically uses uppercase)
class layeredconfig.Commandline(commandline=None, sectionsep='-', **kwargs)

Load configuration from command line options. Any long-style parameters are turned into configuration values, and parameters containing the section separator (by default "-") are turned into nested config objects (i.e. --module-parameter=foo results in self.module.parameter == "foo".

Parameters:
  • commandline (list) – Command line arguments, in list form like sys.argv. If not provided, uses the real sys.argv.
  • sectionsep (str) – An alternate section separator instead of -.
rest = []

The remainder of the command line, containing all parameters that couldn’t be turned into configuration settings.

class layeredconfig.INIFile(inifilename=None, rootsection='__root__', writable=True, **kwargs)

Loads and optionally saves configuration files in INI format, as handled by configparser.

Parameters:
  • inifile (str) – The name of a ini-style configuration file. The file should have a top-level section, by default named __root__, whose keys are turned into top-level configuration parameters. Any other sections in this file are turned into nested config objects.
  • rootsection (str) – An alternative name for the top-level section. See note below.
  • writable (bool) – Whether changes to the LayeredConfig object that has this INIFile object amongst its sources should be saved in the INI file.

Note

Since this source uses configparser, and since that module handles sections named [DEFAULT] differently, this module will have a sort-of automatic cascading feature for subsections if DEFAULT is used as rootsection

class layeredconfig.JSONFile(jsonfilename=None, writable=True, **kwargs)

Loads and optionally saves configuration files in JSON format. Since JSON has some support for typed values (supports numbers, lists, bools, but not dates or datetimes), data from this source are sometimes typed, sometimes only available as strings.

Parameters:
  • jsonfile (str) – The name of a JSON file, whose root element should be a JSON object (python dict). Nested objects are turned into nested config objects.
  • writable (bool) – Whether changes to the LayeredConfig object that has this JSONFile object amongst its sources should be saved in the JSON file.
class layeredconfig.YAMLFile(yamlfilename=None, writable=True, **kwargs)

Loads and optionally saves configuration files in YAML format. Since YAML (and the library implementing the support, PyYAML) has automatic support for typed values, data from this source are typed.

Parameters:
  • yamlfile (str) – The name of a YAML file. Nested sections are turned into nested config objects.
  • writable (bool) – Whether changes to the LayeredConfig object that has this YAMLFile object amongst its sources should be saved in the YAML file.
class layeredconfig.PListFile(plistfilename=None, writable=True, **kwargs)

Loads and optionally saves configuration files in PList format. Since PList has some support for typed values (supports numbers, lists, bools, datetimes but not dates), data from this source are sometimes typed, sometimes only available as strings.

Parameters:
  • plistfile (str) – The name of a PList file. Nested sections are turned into nested config objects.
  • writable (bool) – Whether changes to the LayeredConfig object that has this PListFile object amongst its sources should be saved in the PList file.