pypeec.io

Module for serialization and deserialization.
  • load JSON/YAML input files

  • load and write JSON/Pickle data files

For YAML files, the following custom extensions are used:
  • “!path” - parse relative paths (with respect to the YAML file)

  • “!include” - include other YAML files (recursion possible)

  • “!env” - include YAML string from environment variables

  • “!merge_dict” - merge a list of dicts

  • “!merge_list” - merge a list of lists

For JSON files, the following custom extensions are used:
  • “__complex__” - allows the serialization of complex numbers

  • “__numpy__” - allows the serialization of NumPy arrays

The JSON/YAML files with the custom extensions are still valid JSON/YAML files.

The JSON files can be serialized/deserialized as/from:
  • text files

  • gzip files

Warning

  • Pickling data is not secure.

  • Only load pickle files that you trust.

pypeec.io.load_input(filename)

Load an input file (JSON or YAML).

Parameters:

filename (string)) – Name and path of the file to be loaded. The file type is determined by the extension. For YAML files, the extension should be “yaml” or “yml”. For JSON files, the extension should be “json” or “js”. For GZIP/JSON files, the extension should be “gzip” or “gz”.

Returns:

data – Python data contained in the file content

Return type:

data

pypeec.io.load_data(filename)

Load a data file (JSON or Pickle).

Parameters:

filename (string)) – Name and path of the file to be loaded. The file type is determined by the extension. For JSON files, the extension should be “json” or “js”. For GZIP/JSON files, the extension should be “gzip” or “gz”. For Pickle files, the extension should be “pck”.

Returns:

data – Python data contained in the file content

Return type:

data

pypeec.io.write_data(filename, data)

Write a data file (JSON or Pickle).

Parameters:
  • filename (string)) – Name and path of the file to be created. The file type is determined by the extension. For JSON files, the extension should be “json” or “js”. For GZIP/JSON files, the extension should be “gzip” or “gz”. For Pickle files, the extension should be “pck”.

  • data (data) – Python data to be saved.