blosc2.compress2(src, **kwargs)#

Compress src with the given compression params (if given)

  • src (bytes-like object (supporting the buffer interface))

  • kwargs (dict, optional) –

    Keyword arguments supported:

    codec: Codec

    The compressor code. Default is Codec.BLOSCLZ.

    codec_meta: int

    The metadata for the compressor code, 0 by default.

    clevel: int

    The compression level from 0 (no compression) to 9 (maximum compression). Default: 5.

    use_dict: bool

    Use dicts or not when compressing (only for blosc2.Codec.ZSTD). By default False.

    typesize: int from 1 to 255

    The data type size. Default: 8.

    nthreads: int

    The number of threads to use internally (1 by default).

    blocksize: int

    The requested size of the compressed blocks. If 0 (the default) blosc2 chooses it automatically.

    splitmode: SplitMode

    The split mode for the blocks. The default value is SplitMode.FORWARD_COMPAT_SPLIT.

    filters: Filter list

    The sequence of filters. Default: {0, 0, 0, 0, 0, Filter.SHUFFLE}.

    filters_meta: list

    The metadata for filters. Default: {0, 0, 0, 0, 0, 0}.

    tuner: Tuner

    The tuner to use. Default: Tuner.STUNE.


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

Return type:



RuntimeError – If the data cannot be compressed into dst. If an internal error occurred, probably because some parameter is not a valid parameter.