blosc2.pack#
- blosc2.pack(obj, clevel=9, filter=Filter.SHUFFLE, codec=Codec.BLOSCLZ)#
Pack (compress) a Python object.
- Parameters:
obj¶ (Python object with itemsize attribute) – The Python object to be packed.
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 in form of a Python str / bytes object.
- Return type:
str / bytes
- Raises:
AttributeError – If
obj
does not have an itemsize attribute. Ifobj
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. Ifcodec
is not within the supported compressors.
Notes
The cname and shuffle parameters in python-blosc API have been replaced by
codec
andfilter
respectively. To setcodec
andfilter
, the enumeratesCodec
andFilter
have to be used instead of the python-blosc API variables such as blosc.SHUFFLE forfilter
or strings like “blosclz” forcodec
.Examples
>>> import numpy as np >>> a = np.arange(1e6) >>> parray = blosc2.pack(a) >>> len(parray) < a.size * a.itemsize True