pymlconf Package¶
config_manager Module¶
-
class
pymlconf.config_manager.ConfigManager(init_value=None, dirs=None, files=None, filename_as_namespace=True, extension='.conf', root_file_name='root', missing_file_behavior=2, encoding='utf-8', context=None, builtin=None)[source]¶ Bases:
pymlconf.config_nodes.ConfigDictThe main class which exposes pymlconf package.
Example:
from pymlconf import ConfigManager from os import path config = ConfigManager(''' server: host: localhost port: 4455 ''','conf','builtins/defaults.conf') print config.server.host print config.server.port
Parameters: - init_value (str or dict) – Initial configuration value that you can pass it before reading the files and directories.can be ‘yaml string’ or python dictionary.
- dirs (str or list) – Python list or a string that contains semi-colon separated list of directories which contains configuration files with specified extension(default *.conf).
- files (str or list) – Python list or a string that contains semi-colon separated list of files which contains yaml configuration entries.
- filename_as_namespace (bool) – when loading dirs, use the filename as a namespace. default: true.
- extension (str) – File extension to search for configuration files, in dirs parameter, default ‘.conf’
- root_file_name (str) – Filename to treat as root configuration file, so it loads first, and do not uses the filename as namespaces.
- missing_file_behavior (integer 0:ignore, 1:throw error, 2:warning) – What should do when a file was not found, set to 0 (zero) to ignore. default to
warning(2) - context (dict) – dictionary to format the yaml before parsing in pre processor.
- builtin (str or dict) – Same as the
init_value, but it will be loaded before the loading theinit_value, helps to implement builtin config pattern.
New in version 0.6.0a: The
builtinparameter was added.-
default_extension= '.conf'¶
-
load_dirs(dirs, filename_as_namespace=True)[source]¶ load directories which contains configuration files with specified extension, and merge it by current ConfigManager instance
Parameters: - dirs (list,string) – Dirs to search for configuration files.
- filename_as_namespace (bool) – when loading dirs, use the filename as a namespace. default: true.
-
load_files(files, filename_as_namespace=False)[source]¶ load files which contains yaml configuration entries.and merge it by current ConfigManager instance
Parameters: - files (list) – files to load and merge into existing configuration instance
- filename_as_namespace (bool) – when loading files, use the filename as a namespace. default: false.
-
loaddirs(dirs, filename_as_namespace=True)¶ load directories which contains configuration files with specified extension, and merge it by current ConfigManager instance
Parameters: - dirs (list,string) – Dirs to search for configuration files.
- filename_as_namespace (bool) – when loading dirs, use the filename as a namespace. default: true.
-
loadfiles(files, filename_as_namespace=False)¶ load files which contains yaml configuration entries.and merge it by current ConfigManager instance
Parameters: - files (list) – files to load and merge into existing configuration instance
- filename_as_namespace (bool) – when loading files, use the filename as a namespace. default: false.
config_nodes Module¶
-
class
pymlconf.config_nodes.ConfigDict(*args, **kwargs)[source]¶ Bases:
collections.OrderedDict,pymlconf.config_nodes.MergableConfiguration node that represents python dictionary data.
-
class
pymlconf.config_nodes.ConfigList(*args, **kwargs)[source]¶ Bases:
list,pymlconf.config_nodes.MergableConfiguration node that represents the python list data.
-
class
pymlconf.config_nodes.ConfigNamespace(*args, **kwargs)[source]¶ Bases:
pymlconf.config_nodes.ConfigDict,pymlconf.config_nodes.MergableConfiguration node that represents the configuration namespace node.
-
class
pymlconf.config_nodes.Mergable(data=None, context=None)[source]¶ Bases:
objectBase class for all configuration nodes, so all configuration nodes are mergable
Parameters: data (list or dict) – Initial value to constract a mergable instance. default: None. -
can_merge(data)[source]¶ Determines whenever can merge with the passed argument or not.
Parameters: data (any) – An object to test. Returns: bool
-
classmethod
empty()[source]¶ When implemented, returns an empty instance of drived
Mergableclass.Returns: Mergable
-
errors Module¶
-
exception
pymlconf.errors.ConfigKeyError(key)[source]¶ Bases:
pymlconf.errors.ConfigurationError,AttributeError
-
exception
pymlconf.errors.ConfigurationMergeError(message)[source]¶ Bases:
pymlconf.errors.ConfigurationError,ValueError