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 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
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
, use the enumerationsCodec
andFilter
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