monty.serialization module

This module implements serialization support for common formats such as json and yaml.

dumpfn(obj, fn, *args, **kwargs)[source]

Dump to a json/yaml directly by filename instead of a File-like object. File may also be a BZ2 (“.BZ2”) or GZIP (“.GZ”, “.Z”) compressed file. For YAML, ruamel.yaml must be installed. The file type is automatically detected from the file extension (case insensitive). YAML is assumed if the filename contains “.yaml” or “.yml”. Msgpack is assumed if the filename contains “.mpk”. JSON is otherwise assumed.

Parameters
  • obj (object) – Object to dump.

  • fn (str/Path) – filename or pathlib.Path.

  • *args – Any of the args supported by json/yaml.dump.

  • **kwargs – Any of the kwargs supported by json/yaml.dump.

Returns

(object) Result of json.load.

loadfn(fn, *args, **kwargs)[source]

Loads json/yaml/msgpack directly from a filename instead of a File-like object. File may also be a BZ2 (“.BZ2”) or GZIP (“.GZ”, “.Z”) compressed file. For YAML, ruamel.yaml must be installed. The file type is automatically detected from the file extension (case insensitive). YAML is assumed if the filename contains “.yaml” or “.yml”. Msgpack is assumed if the filename contains “.mpk”. JSON is otherwise assumed.

Parameters
  • fn (str/Path) – filename or pathlib.Path.

  • *args – Any of the args supported by json/yaml.load.

  • **kwargs – Any of the kwargs supported by json/yaml.load.

Returns

(object) Result of json/yaml/msgpack.load.