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, cps_by_ext=(('ini', [<class 'anyconfig.backend.ini.Parser'>]), ('js', [<class 'anyconfig.backend.json.Parser'>]), ('jsn', [<class 'anyconfig.backend.json.Parser'>]), ('json', [<class 'anyconfig.backend.json.Parser'>]), ('pickle', [<class 'anyconfig.backend.pickle.Parser'>]), ('pkl', [<class 'anyconfig.backend.pickle.Parser'>]), ('properties', [<class 'anyconfig.backend.properties.Parser'>]), ('toml', [<class 'anyconfig.backend.toml.Parser'>]), ('xml', [<class 'anyconfig.backend.xml.Parser'>]), ('yaml', [<class 'anyconfig.backend.yaml.Parser'>]), ('yml', [<class 'anyconfig.backend.yaml.Parser'>])), cps_by_type=(('configobj', [<class 'anyconfig.backend.configobj.Parser'>]), ('ini', [<class 'anyconfig.backend.ini.Parser'>]), ('json', [<class 'anyconfig.backend.json.Parser'>]), ('pickle', [<class 'anyconfig.backend.pickle.Parser'>]), ('properties', [<class 'anyconfig.backend.properties.Parser'>]), ('shellvars', [<class 'anyconfig.backend.shellvars.Parser'>]), ('toml', [<class 'anyconfig.backend.toml.Parser'>]), ('xml', [<class 'anyconfig.backend.xml.Parser'>]), ('yaml', [<class 'anyconfig.backend.yaml.Parser'>])), 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
  • forced_type – Forced type of parser to load or dump
Returns:

anyconfig.globals.IOInfo object :: namedtuple

Raises:

ValueError, UnknownParserTypeError, UnknownFileTypeError

anyconfig.backends.find_parser_by_type(forced_type, cps_by_ext=(('ini', [<class 'anyconfig.backend.ini.Parser'>]), ('js', [<class 'anyconfig.backend.json.Parser'>]), ('jsn', [<class 'anyconfig.backend.json.Parser'>]), ('json', [<class 'anyconfig.backend.json.Parser'>]), ('pickle', [<class 'anyconfig.backend.pickle.Parser'>]), ('pkl', [<class 'anyconfig.backend.pickle.Parser'>]), ('properties', [<class 'anyconfig.backend.properties.Parser'>]), ('toml', [<class 'anyconfig.backend.toml.Parser'>]), ('xml', [<class 'anyconfig.backend.xml.Parser'>]), ('yaml', [<class 'anyconfig.backend.yaml.Parser'>]), ('yml', [<class 'anyconfig.backend.yaml.Parser'>])), cps_by_type=(('configobj', [<class 'anyconfig.backend.configobj.Parser'>]), ('ini', [<class 'anyconfig.backend.ini.Parser'>]), ('json', [<class 'anyconfig.backend.json.Parser'>]), ('pickle', [<class 'anyconfig.backend.pickle.Parser'>]), ('properties', [<class 'anyconfig.backend.properties.Parser'>]), ('shellvars', [<class 'anyconfig.backend.shellvars.Parser'>]), ('toml', [<class 'anyconfig.backend.toml.Parser'>]), ('xml', [<class 'anyconfig.backend.xml.Parser'>]), ('yaml', [<class 'anyconfig.backend.yaml.Parser'>])))

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

Parameters:
  • forced_type – Forced parser type
  • cps_by_type – A list of pairs (parser_type, [parser_class])
Returns:

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

Raises:

UnknownParserTypeError

anyconfig.backends.find_parser(obj, 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, UnknownParserTypeError, UnknownFileTypeError

anyconfig.backends.list_types(cps=(('configobj', [<class 'anyconfig.backend.configobj.Parser'>]), ('ini', [<class 'anyconfig.backend.ini.Parser'>]), ('json', [<class 'anyconfig.backend.json.Parser'>]), ('pickle', [<class 'anyconfig.backend.pickle.Parser'>]), ('properties', [<class 'anyconfig.backend.properties.Parser'>]), ('shellvars', [<class 'anyconfig.backend.shellvars.Parser'>]), ('toml', [<class 'anyconfig.backend.toml.Parser'>]), ('xml', [<class 'anyconfig.backend.xml.Parser'>]), ('yaml', [<class 'anyconfig.backend.yaml.Parser'>])))

List available config types.