scistag.filestag.bundle.Bundle¶
- class Bundle[source]¶
Bases:
objectThe bundle class is able to store a list, a tuple or a dictionary in a zip file. In case of a dictionary only the “first” level can be used for the storage of “advanced” data types such as images, DataFrames, numpy arrays etc.
With help of the Bundle class function parameters can easily be passed between different processes, clients and servers without the need to pickle them and in consequence without being bound to fully compatible module versions by using common interchange formats such as parquet files or json files.
Methods
Stores a dictionary, a list or a tuple in a zip file in memory and returns its bytes string representation which can then for example be passed to another process, client or server and extracted there or just be dumped to a database or a disk.
Converts an object from it's byte representation back to its normal form.
Registers a new bundling helper function
Registers a new unpacking helper function
Converts an element to its storable bytes representation
Unpacks a previously bundled data package to it's original form
Attributes
__annotations____dict____doc____module____weakref__list of weak references to the object (if defined)
Configuration access lock
Defines if the base types were registered
Registered functions to convert an of type key to it's bytes representation
Registered functions to convert an object from a known type and it's bytes representation back to it's original form such as a dictionary, numpy array or pandas DataFrame
- classmethod bundle(elements, compression=None)[source]¶
Stores a dictionary, a list or a tuple in a zip file in memory and returns its bytes string representation which can then for example be passed to another process, client or server and extracted there or just be dumped to a database or a disk.
- Parameters
elements (dict[str, Any] | list[Any] | tuple) – The elements to be stored. Supported data types are
(w/o extensions which may be registered) dictionaries, lists, tuples, strings, floats, booleans, Pandas DataFrames, DataSeries, numpy arrays and byte strings. :type compression: int | None :param compression: The compression level (from 0 to 99) (fast to small) :rtype: bytes :return: The bytes dump of the zip archive.
- classmethod from_bytes(data_type, data, options)[source]¶
Converts an object from it’s byte representation back to its normal form.
- Parameters
data_type (
str) – The data type as returned from to_bytesdata (
bytes) – The dataoptions (
UnpackOptions) – Advanced unpacking options
- Return type
- Returns
The reconstructed object
- classmethod register_unpacker(data_type, callback)[source]¶
Registers a new unpacking helper function
- Parameters
data_type (
str) – The data type as string to look out for (as stored in the dictionary of the bundled data and returned by the corresponding BundleToBytesCallback)callback (
Callable[[bytes,UnpackOptions],Any]) – The function be called to unpack the data
- classmethod to_bytes(element, options)[source]¶
Converts an element to its storable bytes representation
- Parameters
element (
Any) – The element to convert to bytesoptions (
BundlingOptions) – Advanced bundling options
- Return type
- Returns
The data type to be stored in the bundle and the bytes string
- _access_lock = <scistag.common.mt.stag_lock.StagLock object>¶
Configuration access lock
- _base_types_registered = False¶
Defines if the base types were registered