Handlers¶
-
class
file_config.handlers.INIHandler[source]¶ The INI serialization handler.
Important
INI files cannot support arrays of mappings. Using these in your config and trying to dump to ini will throw a
ValueErrorand will fail serialization.If you need to use a config with arrays of mappings use toml instead. This use case is one of the many things toml does better than traditional config files.
-
name= 'ini'¶
-
on_configparser_dumps(configparser, config, dictionary, **kwargs)[source]¶ The
configparserdumps method.- Parameters
configparser (module) – The
configparsermoduleconfig (class) – The instance’s config class
dictionary (dict) – The dictionary instance to serialize
root (str) – The top-level section of the ini file, defaults to
config.__name__, optionaldelimiter (str) – The delimiter character used for representing nested dictionaries, defaults to “:”, optional
- Returns
The ini serialization of the given
dictionary- Return type
-
on_configparser_loads(configparser, config, content, **kwargs)[source]¶ The
configparserloads method.
-
options= {'delimiter': ':', 'empty_sections': False, 'root': None}¶
-
packages= ('configparser',)¶
-
-
class
file_config.handlers.XMLHandler[source]¶ The XML serialization handler.
-
name= 'xml'¶
-
on_lxml_dumps(lxml, config, dictionary, **kwargs)[source]¶ The lxml dumps method.
- Parameters
lxml (module) – The
lxmlmoduleconfig (class) – The instance’s config class
dictionary (dict) – The dictionary to serialize
root (str) – The root tag of the xml document, defaults to the config instance’s name, optional
pretty (bool) – Pretty format the resulting xml document, defaults to False, optional
xml_declaration (bool) – Add the xml declaration header to the resulting xml document, defaults to False, optional
encoding (str) – The encoding to use for the resulting xml document, defaults to “utf-8”, optional
- Returns
The XML serialization
- Return type
-
options= {'encoding': 'utf-8', 'pretty': False, 'root': None, 'xml_declaration': False}¶
-
packages= ('lxml',)¶
-
-
class
file_config.handlers.JSONHandler[source]¶ The JSON serialization handler.
-
name= 'json'¶
-
on_rapidjson_dumps(rapidjson, config, dictionary, **kwargs)[source]¶ The rapidjson dumps method.
- Parameters
- Returns
The json serialization of the given
dictionary- Return type
-
on_ujson_dumps(ujson, config, dictionary, **kwargs)[source]¶ The ujson dumps method.
- Parameters
- Returns
The json serialization of the given
dictionary- Return type
-
options= {'indent': None, 'sort_keys': False}¶
-
packages= ('rapidjson', 'json', 'ujson')¶
-
-
class
file_config.handlers.TOMLHandler[source]¶ The TOML serialization handler.
-
name= 'toml'¶
-
on_toml_dumps(toml, config, dictionary, **kwargs)[source]¶ The toml dumps method.
- Parameters
- Returns
The TOML serialization
- Return type
Dumping inline tables uses
fnmatchto compare.delimited dictionary path glob patterns to filter tables>>> config.dumps_toml(prefer="toml") name = "My Project" type = "personal-project" keywords = [ "example", "test",] [dependencies.a-dependency] name = "A Dependency" version = "v12" >>> config.dumps_toml(prefer="toml", inline_tables=["dependencies"]) name = "My Project" type = "personal-project" keywords = [ "example", "test",] dependencies = {a-dependency = {name = "A Dependency",version = "v12"} } >>> config.dumps_toml(prefer="toml", inline_tables=["dependencies.*"]) name = "My Project" type = "personal-project" keywords = [ "example", "test",] [dependencies] a-dependency = { name = "A Dependency", version = "v12" }
-
on_tomlkit_dumps(tomlkit, config, dictionary, **kwargs)[source]¶ The tomlkit dumps method.
- Parameters
- Returns
The TOML serialization
- Return type
Dumping inline tables uses
fnmatchto compare.delimited dictionary path glob patterns to filter tables>>> config.dumps_toml(prefer="tomlkit") name = "My Project" type = "personal-project" keywords = ["example", "test"] [dependencies] [dependencies.a-dependency] name = "A Dependency" version = "v12" >>> config.dumps_toml(prefer="tomlkit", inline_tables=["dependencies"]) name = "My Project" type = "personal-project" keywords = ["example", "test"] dependencies = {a-dependency = {name = "A Dependency",version = "v12"}} >>> config.dumps_toml(prefer="tomlkit", inline_tables=["dependencies.*"]) name = "My Project" type = "personal-project" keywords = ["example", "test"] [dependencies] a-dependency = {name = "A Dependency",version = "v12"}
-
options= {'inline_tables': []}¶
-
packages= ('tomlkit', 'toml', 'pytoml')¶
-
-
class
file_config.handlers.YAMLHandler[source]¶ The YAML serialization handler.
-
name= 'yaml'¶
-
options= {}¶
-
packages= ('yaml',)¶
-
-
class
file_config.handlers.PickleHandler[source]¶ The Pickle serialization handler.
-
name= 'pickle'¶
-
options= {}¶
-
packages= ('pickle',)¶
-
-
class
file_config.handlers.MsgpackHandler[source]¶ The Message Pack serialization handler.
-
name= 'msgpack'¶
-
options= {}¶
-
packages= ('msgpack',)¶
-