The primary API classes.
The root configuration object.
Any number of sources can be set using sources. These are the sources that will be using when calling
The format of the sources can be set using format. This can be the registered name of a format, such as “ini”, or a
Formatclass or instance.
An encoding can be set using encoding. If encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False).
Strict mode can be enabled by setting strict to True. In strict mode, accessing keys that have not been initialized will raise an
The dict class used internally can be set using dict_type. By default an OrderedDict is used.
Coercercan be set using coercer. If no coercer is passed in, a default will be created. If None is passed in, no coercer will be set and values will be read from and written to sources directly.
This is a subclass of
Returns the formats registered with this class.
Sets the format to use when processing sources.
format can be the registered name of a format, such as “ini”, or a
Formatclass or instance.
Represents a group of configuration options.
This class is not meant to be instantiated directly.
value -> str
Returns the configuration’s keys and values as a dictionary.
If flat is True, returns a single-depth dict with
If dict_type is not None, it should be the mapping class to use for the result. Otherwise, the dict_type set by
__init__()will be used.
str -> value
Get the section’s default value.
If key exists, returns the value. Otherwise, returns default.
If default is not given, it defaults to None, so that this method never raises an exception.
init(key, default, type=None, comment=None)¶
Initializes key to the given default value.
If type is not provided, the type of the default value will be used.
If a value is already set for the section at key, it will be coerced to type.
If a comment is provided, it may be written out to the config file in a manner consistent with the active
Reads config values.
If sources are provided, read only from those sources. Otherwise, write to the sources in
sources. A format for sources can be set using format.
Resets this section to it’s default value, leaving it in the same state as after a call to
If recurse is True, does the same to all the section’s children. If clean is True, also clears the dirty flag on all sections.
Returns a section object for key.
create will default to False when in strict mode. Otherwise it defaults to True.
If there is no existing section for key, and create is False, an
Returns the sections that are children to this section.
If recurse is True, returns grandchildren as well. If only_valid is True, returns only valid sections.
Set the section’s default value.
Set the section’s value.
Reads from sources and writes any changes back to the first source.
If sources are provided, syncs only those sources. Otherwise, syncs the sources in
format can be used to override the format used to read/write from the sources.
Get the section’s value.
Writes config values.
If source is provided, write only to that source. Otherwise, write to the first source in
sources. A format for source can be set using format. format is otherwise ignored.
True if this section’s value has changed since the last write. Read-only.
True if this section has child sections. Read-only.
True if this section has a default value and its current value is equal to the default value. Read-only.
The section’s key. Read-only.
The section’s name. Read-only.
The section’s parent or None. Read-only.
The type used for coercing the value for this section. Read only.
True if this section has a valid value. Read-only.
Formats define de/serialization specifics.
open(cfg, source, mode=u'r', binary=True)¶
Returns a file object.
If source is a file object, returns source. mode can be ‘r’ or ‘w’. If mode is ‘w’, The file object will be truncated. If binary is True, the file will be opened in binary mode (‘rb’ or ‘wb’).
Reads file to update cfg. Must be implemented in a subclass.
write(cfg, file, values=None)¶
Writes cfg to file. Must be implemented in a subclass.
Specifies how the format should react to errors raised when processing a source.
Must be one of the following:
- ignore - Ignore all errors completely.
- warning - Log a warning for any errors.
- exception - Raise an exception for any error.
Only ‘exception’ will cause the format to stop processing a source.
error_modes= frozenset([u'ignore', u'exception', u'warning'])¶
The supported error modes.
A convenient name for the format.
Implements reading/writing configurations from/to INI formatted files.
A header will be written for each section in the root config object.
Implements reading/writing configurations from/to the Windows registry.
Sections with children will be created as keys. Those without children will be created as values.
Keys will be created relative to
RegistryFormat.base_key, which defaults to HKEY_CURRENT_USER.
A Coercer handles the conversion of values to/from a human-readable string representation.
The coercer class, with which adapters and converters can be registered.
Adapt a value from the given type (type to string). If type is not provided the type of the value will be used.
Convert a value to the given type (string to type).
register(type, adapter, converter)¶
Register an adapter and converter for the given type.
Register an adapter (type to string) for the given type.
Registers an adapter and converter for a choice of values. Values passed into
convert()for type will have to be one of the choices. choices must be a dict that maps converted->adapted representations.
Register a converter (string to type) for the given type.