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
|
Numpy arrays can have multiple in-file representations. |
|
Write the object into a file object. |
|
Write the object into a bytes or str representation according to 'lang'. |
|
Load the formatted data. |
|
Like dump(...), but also serializes nested DataRefs. |
|
Like dumps(...), but also serializes nested DataRefs. |
Functions
- fusionsc.structio.asarray(x)
Numpy arrays can have multiple in-file representations. 1-D arrays are stored as lists and deserialize either as lists (if they contain object types) or as 1-D numpy arrays. N-D arrays (N>1) are stored as mappings holding the flattened array and its shape.
This function converts all possible numpy array representations back into an appropriate numpy array.
- 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 | dict | list | Builder = None, lang: str = '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[…]