anyconfig.backends

A module to aggregate config parser (loader/dumper) backends.

anyconfig.backends.is_parser(obj)
Returns:True if given obj is an instance of parser.
>>> is_parser("ini")
False
>>> is_parser(anyconfig.backend.base.Parser)
False
>>> is_parser(anyconfig.backend.base.Parser())
True
anyconfig.backends.inspect_io_obj(obj, prs=None, forced_type=None)

Inspect a given object obj which may be a path string, file / file-like object, pathlib.Path object or ~anyconfig.globals.IOInfo namedtuple object, and find out appropriate parser object to load or dump from/to it along with other I/O information.

Parameters:
  • obj – a file path string, file / file-like object, pathlib.Path object or ~anyconfig.globals.IOInfo object
  • prs – A list of parser classes
  • forced_type – Forced type of parser to load or dump
Returns:

anyconfig.globals.IOInfo object :: namedtuple

Raises:

ValueError, UnknownProcessorTypeError, UnknownFileTypeError

anyconfig.backends.find_parser_by_type(forced_type, prs=None)

Find out appropriate parser object to load inputs of given type.

Parameters:
  • forced_type – Forced parser type
  • prs – A list of parser classes
Returns:

An instance of Parser or None means no appropriate parser was found

Raises:

UnknownProcessorTypeError

anyconfig.backends.find_parser(obj, prs=None, forced_type=None)

Find out appropriate parser object to load from a file of given path or file/file-like object.

Parameters:
  • obj – a file path string, file / file-like object, pathlib.Path object or ~anyconfig.globals.IOInfo object
  • forced_type – Forced configuration parser type
Returns:

A tuple of (Parser class or None, “” or error message)

Raises:

ValueError, UnknownProcessorTypeError, UnknownFileTypeError

anyconfig.backends.list_types(cps=None)

List available types parsers support.