Available sources¶
Hardcoded defaults¶
Environment variables¶
- 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)
Command-line parameters¶
- class layeredconfig.Commandline(commandline=None, parser=None, sectionsep='-', add_help=True, **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".
If an initialized ArgumentParser object is provided, the defined parameters in that object is used for supporting short form options (eg. '-f' instead of '--force'), typing information and help text. The standards argparse feature of printing a helpful message when the ‘-h’ option is given is retained.
Parameters: - commandline (list) – Command line arguments, in list form like sys.argv. If not provided, uses the real sys.argv.
- parser (argparse.ArgumentParser) – An initialized/configured argparse object
- sectionsep (str) – An alternate section separator instead of -.
- add_help (bool) – Same as for ArgumentParser()
- rest = []¶
The remainder of the command line, containing all parameters that couldn’t be turned into configuration settings.
INI files¶
- 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
JSON files¶
- 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:
YAML files¶
- 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:
PList files¶
- 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:
Python files¶
- class layeredconfig.PyFile(pyfilename, **kwargs)¶
Loads configuration from a python source file. Any variables defined in that file will be interpreted as configuration keys. The class Subsection is automatically imported into the context when the file is executed, and represents a subsection of the configuration. Any attribute set on such an object is treated as a configuration parameter on that subsection.
Note
The python source file is loaded and interpreted once, when creating the PyFile object. If a value is set by eg. calling a function, that function will only be called at load time, not when accessing the parameter.
Parameters: pyfile (str) – The name of a file containing valid python code.
etcd stores¶
- class layeredconfig.EtcdStore(baseurl='http://127.0.0.1:4001/v2/', **kwargs)¶
Loads configuration from a etcd store.
Parameters have the same meaning and default values as etcd.Client.
etcd has no concept of typed values, so all data from this source are returned as strings.