config_framework.loaders package

Submodules

class Composite(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], loaders: Tuple[AbstractLoader, ...])[source]

Bases: AbstractLoader

loaders: Tuple[AbstractLoader, ...]
classmethod load(*loaders: AbstractLoader, defaults: Optional[MutableMapping[str, Any]] = None)[source]

Initializes composite loader.

Parameters
  • loaders – any number of different config sources that can be used for providing configuration.

  • defaults – default values.

Returns

instance of composite loader.

dump(include_defaults: bool = False) None[source]

Method that is used to dump all values to some storage.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class Dict(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any])[source]

Bases: AbstractLoader

classmethod load(data: MutableMapping[str, Any], defaults: Optional[MutableMapping[str, Any]] = None)[source]

Wrapper for dicts usage as config source.

Parameters
  • data – argument expects dictionary that will be used as source.

  • defaults – default values.

Returns

instance of dict loader.

dump(include_defaults: bool = False) None[source]

This method doesn’t change anything since dict is updated whenever values are changed.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class Environment(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any])[source]

Bases: AbstractLoader

classmethod load(defaults: Optional[MutableMapping[str, Any]] = None)[source]

Loads data from environment.

Parameters

defaults – default values.

Returns

instance of env loader.

dump(include_defaults: bool = False) None[source]

This method doesn’t change env variables at all because not many types, convert properly into string env variable and can be loaded back.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class Json(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], path: Union[PathLike, Path], encoding: str, json_loader: Callable, json_dumper: Callable)[source]

Bases: AbstractLoader

json_loader: Callable
json_dumper: Callable
path: Union[PathLike, Path]
encoding: str
classmethod load(path: ~typing.Union[~os.PathLike, ~pathlib.Path], defaults: ~typing.Optional[~typing.MutableMapping[str, ~typing.Any]] = None, encoding: str = 'utf8', json_loader=<function load>, json_dumper=functools.partial(<function dump>, ensure_ascii=False, indent=4))[source]

Loads json file from path into loader.

Parameters
  • path – where file with json is located.

  • defaults – default values.

  • encoding – which encoding does config file has (defaults to utf-8).

  • json_loader – function that loads json file.

  • json_dumper – function that dumps to json file.

Returns

instance of json loader.

dump(include_defaults: bool = False) None[source]

Method that is used to dump all values to some storage.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class JsonString(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], encoding: str, json_loader: Callable, json_dumper: Callable)[source]

Bases: AbstractLoader

json_loader(*, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)

Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object.

object_hook is an optional function that will be called with the result of any object literal decode (a dict). The return value of object_hook will be used instead of the dict. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).

object_pairs_hook is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

To use a custom JSONDecoder subclass, specify it with the cls kwarg; otherwise JSONDecoder is used.

json_dumper(fp, *, skipkeys=False, ensure_ascii=False, check_circular=True, allow_nan=True, cls=None, indent=4, separators=None, default=None, sort_keys=False, **kw)

Serialize obj as a JSON formatted stream to fp (a .write()-supporting file-like object).

If skipkeys is true then dict keys that are not basic types (str, int, float, bool, None) will be skipped instead of raising a TypeError.

If ensure_ascii is false, then the strings written to fp can contain non-ASCII characters if they appear in strings contained in obj. Otherwise, all such characters are escaped in JSON strings.

If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an RecursionError (or worse).

If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity).

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (', ', ': ') if indent is None and (',', ': ') otherwise. To get the most compact JSON representation, you should specify (',', ':') to eliminate whitespace.

default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.

If sort_keys is true (default: False), then the output of dictionaries will be sorted by key.

To use a custom JSONEncoder subclass (e.g. one that overrides the .default() method to serialize additional types), specify it with the cls kwarg; otherwise JSONEncoder is used.

classmethod load(data_string: str, encoding: str = 'utf8', defaults: ~typing.Optional[~typing.MutableMapping[str, ~typing.Any]] = None, json_loader=<function loads>, json_dumper=functools.partial(<function dumps>, ensure_ascii=False, indent=4))[source]

Loads json file from path into loader.

Parameters
  • data_string – string with valid json formatted text.

  • defaults – default values.

  • encoding – which encoding does config file has (defaults to utf-8).

  • json_loader – function that loads json from string.

  • json_dumper – function that dumps to json string.

Returns

instance of json string loader.

dump(include_defaults: bool = False) None[source]

This method doesn’t change anything at all because strings are unchangeable.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class Toml(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], path: Union[PathLike, Path], encoding: str, toml_loader: Callable, toml_dumper: Callable)[source]

Bases: TomlReadOnly

path: Union[PathLike, Path]
encoding: str
toml_loader: Callable
toml_dumper: Callable
classmethod load(path: Union[PathLike, Path], defaults: Optional[MutableMapping[str, Any]] = None, loader_kwargs: Optional[Dict[Any, Any]] = None, dumper_kwargs: Optional[Dict[Any, Any]] = None, encoding: str = 'utf8')[source]

Initializes loader for read only toml.

Parameters
  • path – path that is used to load config.

  • defaults – default values.

  • loader_kwargs – used for specifying parameters, according to toml documentation of toml.load function.

  • dumper_kwargs – used for specifying parameters, according to toml documentation of toml.dump function.

  • encoding – which encoding should be used for a file.

Returns

instance of TomlReadOnly class.

dump(include_defaults: bool = False) None[source]

Method that is used to dump all values to some storage.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class TomlReadOnly(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], path: Union[PathLike, Path], encoding: str, toml_loader: Callable, toml_dumper: Callable)[source]

Bases: AbstractLoader

toml_loader: Callable
toml_dumper: Callable
path: Union[PathLike, Path]
encoding: str
classmethod load(path: Union[PathLike, Path], defaults: Optional[MutableMapping[str, Any]] = None, loader_kwargs: Optional[Dict[Any, Any]] = None, dumper_kwargs: Optional[Dict[Any, Any]] = None, encoding: str = 'utf8')[source]

Initializes loader for read only toml.

Parameters
  • path – path that is used to load config.

  • defaults – default values.

  • loader_kwargs – used for specifying parameters, according to tomllib documentation of tomllib.load function.

  • dumper_kwargs – not used.

  • encoding – which encoding should be used for a file.

Returns

instance of TomlReadOnly class.

dump(include_defaults: bool = False) None[source]

Method that is used to dump all values to some storage.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.

class Yaml(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any], path: Union[PathLike, Path], encoding: str, yaml_loader: Callable, yaml_dumper: Callable)[source]

Bases: AbstractLoader

yaml_loader: Callable
yaml_dumper: Callable
path: Union[PathLike, Path]
encoding: str
classmethod load(path: ~typing.Union[~os.PathLike, ~pathlib.Path], defaults: ~typing.Optional[~typing.MutableMapping[str, ~typing.Any]] = None, encoding: str = 'utf8', yaml_loader=functools.partial(<function load>, Loader=<class 'yaml.cyaml.CLoader'>), yaml_dumper=functools.partial(<function dump>, Dumper=<class 'yaml.cyaml.CDumper'>))[source]

Loads yaml from file.

Parameters
  • path – where is yaml file to load data from.

  • defaults – default values for config.

  • encoding – which encoding does config file has (defaults to utf-8).

  • yaml_loader – function that is used for loading data from file.

  • yaml_dumper – function that is used for saving data to file.

Returns

instance of yaml loader.

dump(include_defaults: bool = False) None[source]

Method that is used to dump all values to some storage.

Parameters

include_defaults – specifies if you want to have default variables to be dumped.

Returns

nothing.