blosc2.pack#

blosc2.pack(obj: object, clevel: int = 9, filter: Filter = Filter.SHUFFLE, codec: Codec = Codec.BLOSCLZ) str | bytes#

Pack (compress) a Python object.

Parameters:
  • obj (object) – The Python object to be packed. It must have an itemsize attribute.

  • clevel (int (optional)) – The compression level from 0 (no compression) to 9 (maximum compression). The default is 9.

  • filter (Filter (optional)) – The filter to be activated. The default is Filter.SHUFFLE.

  • codec (Codec (optional)) – The compressor used internally in Blosc. The default is Codec.BLOSCLZ.

Returns:

out – The packed object as a Python str or bytes object.

Return type:

str or bytes

Raises:
  • AttributeError – If obj does not have an itemsize attribute. If obj does not have an size attribute.

  • ValueError – If the pickled object size is larger than the maximum allowed buffer size. If typesize is not within the allowed range. If clevel is not within the allowed range. If codec is not within the supported compressors.

Notes

The cname and shuffle parameters in python-blosc API have been replaced by codec and filter respectively. To set codec and filter, use the enumerations Codec and Filter instead of the python-blosc API variables such as blosc.SHUFFLE for filter or strings like “blosclz” for codec.

Examples

>>> import numpy as np
>>> a = np.arange(1e6)
>>> parray = blosc2.pack(a)
>>> len(parray) < a.size * a.itemsize
True