Compressors (zarr.compressors)

This module contains compressor classes for use with Zarr. Note that normally there is no need to use these classes directly, they are used under the hood by Zarr when looking up an implementation of a particular compression.

Other compressors can be registered dynamically with Zarr. All that is required is to implement a class that provides the same interface as the classes listed below, and then to add the class to the compressor registry. See the source code of this module for details.

class zarr.compressors.BloscCompressor(compression_opts)

Provides compression using the blosc meta-compressor. Registered under the name ‘blosc’.

Parameters:

compression_opts : dict

A dictionary with keys ‘cname’, ‘clevel’ and ‘shuffle’. The value of the ‘cname’ key should be a string naming one of the compression algorithms available within blosc, e.g., ‘blosclz’, ‘lz4’, ‘zlib’ or ‘snappy’. The value of the ‘clevel’ key should be an integer between 0 and 9 specifying the compression level. The value of the ‘shuffle’ key should be 0 (no shuffle), 1 (byte shuffle) or 2 (bit shuffle).

Examples

>>> import zarr
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='blosc',
...                compression_opts=dict(cname='lz4', clevel=3, shuffle=2))
class zarr.compressors.ZlibCompressor(compression_opts)

Provides compression using zlib via the Python standard library. Registered under the name ‘zlib’.

Parameters:

compression_opts : int

An integer between 0 and 9 inclusive specifying the compression level.

Examples

>>> import zarr
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='zlib', compression_opts=1)
class zarr.compressors.BZ2Compressor(compression_opts)

Provides compression using BZ2 via the Python standard library. Registered under the name ‘bz2’.

Parameters:

compression_opts : int

An integer between 1 and 9 inclusive specifying the compression level.

Examples

>>> import zarr
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='bz2', compression_opts=1)
class zarr.compressors.LZMACompressor(compression_opts)

Provides compression using lzma via the Python standard library (only available under Python 3). Registered under the name ‘lzma’.

Parameters:

compression_opts : dict

A dictionary with keys ‘format’, ‘check’, ‘preset’ and ‘filters’. The value of the ‘format’ key should be an integer specifying one of the lzma format codes, e.g., lzma.FORMAT_XZ. The value of the ‘check’ key should be an integer specifying one of the lzma check codes, e.g., lzma.CHECK_NONE. The value of the ‘preset’ key should be an integer between 0 and 9 inclusive, specifying the compression level. The value of the ‘filters’ key should be a list of dictionaries specifying compression filters. If filters are provided, ‘preset’ must be None.

Examples

Simple usage:

>>> import zarr
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='lzma',
...                compression_opts=dict(preset=1))

Custom filter pipeline:

>>> import lzma
>>> filters = [dict(id=lzma.FILTER_DELTA, dist=4),
...            dict(id=lzma.FILTER_LZMA2, preset=1)]
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='lzma',
...                compression_opts=dict(filters=filters))
class zarr.compressors.NoCompressor(compression_opts)

No compression, i.e., pass bytes through. Registered under the name ‘none’.

Examples

>>> import zarr
>>> z = zarr.zeros((10000, 10000), chunks=(1000, 1000), dtype='i4',
...                compression='none')