fusionsc.structio

This module can be used to perform import and export operations between python objects (dicts, lists, data readers / builders, numpy arrays) and self-describing nested data formats (currently JSON, YAML, CBOR, BSON, MSGPACK, and UBJSON).

Functions

dump(data, file[, lang, compact])

Write the object into a file object.

dumps(data[, lang, compact, binary])

Write the object into a bytes or str representation according to 'lang'.

load(src[, dst, lang])

Load the formatted data.

recursiveDump(data, file[, lang, compact])

Like dump(...), but also serializes nested DataRefs.

recursiveDumps(data[, lang, compact, binary])

Like dumps(...), but also serializes nested DataRefs.

Functions

fusionsc.structio.dump(data, file, lang='json', compact=False)

Write the object into a file object. The object needs to have a fileno method returning a C file descriptor.

Arguments:
  • data: Target object to serialize

  • file: File-like object

  • lang: Name of the output language (must be json, yaml, cbor, msgpack, ubjson, or bson)

  • compact: Whether to write outputs in a short-handed notation where possible.

fusionsc.structio.dumps(data, lang='json', compact=False, binary=None) str | bytes

Write the object into a bytes or str representation according to ‘lang’.

Arguments:
  • data: Target object to serialize

  • lang: Name of the output language (must be json, yaml, cbor, msgpack, ubjson, or bson)

  • compact: Whether to write outputs in a short-handed notation where possible.

  • binary; Whether to return the result as bytes instead of str (default is False for string languages and True for binary languages)

Returns:

A bytes or str object holding the stored data according to the requested format.

fusionsc.structio.load(src, dst=None, lang='json')

Load the formatted data. Can either deserialize the input as a nested structure of bytes, str, dict, and list, or alternatively deserialize INTO a target object (returning the result in either case).

Deserializing into a target object allows a large amount of conversions based on the destination types (shorthand notations for struct, decoding base64-encoded binary data, etc.) and reduces the amount of intermediate copies required. Target objects can be nested structures of dicts, lists, and struct builders.

Arguments:
  • src: file (with fileno. attribute), str, or bytes-like object serving as data source

  • dst: Optional target to deserialize into

  • lang: Language in which the source data is stored (must be json, yaml, cbor, msgpack, ubjson, or bson)

Returns:
  • The deserialized data. If “dst” is specified, this same object is returned.

fusionsc.structio.recursiveDump(data, file, lang='json', compact=False) Any

Like dump(…), but also serializes nested DataRefs.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]

fusionsc.structio.recursiveDumps(data, lang='json', compact=False, binary=None) str | bytes

Like dumps(…), but also serializes nested DataRefs.

Note Has asynchronous variant ‘.asnc(…)’ that returns Promise[…]