blosc2.pack¶
- blosc2.pack(obj: object, clevel: int = 9, filter: Filter = Filter.SHUFFLE, codec: Codec = Codec.BLOSCLZ) str | bytes[source]¶
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 isFilter.SHUFFLE.codec¶ (
Codec(optional)) – The compressor used internally in Blosc. The default isCodec.BLOSCLZ.
- Returns:
out – The packed object as a Python str or bytes object.
- Return type:
str or bytes
- Raises:
AttributeError – If
objdoes not have an itemsize attribute. Ifobjdoes 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
clevelis not within the allowed range. Ifcodecis not within the supported compressors.
Notes
The cname and shuffle parameters in python-blosc API have been replaced by
codecandfilterrespectively. To setcodecandfilter, use the enumerationsCodecandFilterinstead of the python-blosc API variables such as blosc.SHUFFLE forfilteror strings like “blosclz” forcodec.Examples
>>> import numpy as np >>> a = np.arange(1e6) >>> parray = blosc2.pack(a) >>> len(parray) < a.size * a.itemsize True