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.
- class Dict(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any])[source]
Bases:
AbstractLoader
- class Environment(data: MutableMapping[str, Any], defaults: MutableMapping[str, Any])[source]
Bases:
AbstractLoader
- 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.
- 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_hookis an optional function that will be called with the result of any object literal decode (adict). The return value ofobject_hookwill be used instead of thedict. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).object_pairs_hookis an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value ofobject_pairs_hookwill be used instead of thedict. This feature can be used to implement custom decoders. Ifobject_hookis also defined, theobject_pairs_hooktakes priority.To use a custom
JSONDecodersubclass, specify it with theclskwarg; otherwiseJSONDecoderis 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
objas a JSON formatted stream tofp(a.write()-supporting file-like object).If
skipkeysis true thendictkeys that are not basic types (str,int,float,bool,None) will be skipped instead of raising aTypeError.If
ensure_asciiis false, then the strings written tofpcan contain non-ASCII characters if they appear in strings contained inobj. Otherwise, all such characters are escaped in JSON strings.If
check_circularis false, then the circular reference check for container types will be skipped and a circular reference will result in anRecursionError(or worse).If
allow_nanis false, then it will be aValueErrorto serialize out of rangefloatvalues (nan,inf,-inf) in strict compliance of the JSON specification, instead of using the JavaScript equivalents (NaN,Infinity,-Infinity).If
indentis 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.Noneis the most compact representation.If specified,
separatorsshould be an(item_separator, key_separator)tuple. The default is(', ', ': ')if indent isNoneand(',', ': ')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
JSONEncodersubclass (e.g. one that overrides the.default()method to serialize additional types), specify it with theclskwarg; otherwiseJSONEncoderis 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.
- 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.
- 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.
- 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.