blosc2.pack(obj, clevel=9, filter=Filter.SHUFFLE, codec=Codec.BLOSCLZ)#

Pack (compress) a Python object.

  • 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 is Filter.SHUFFLE.

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


out – The packed object in form of a Python str / bytes object.

Return type:

str / bytes

  • 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.


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


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