ZstdCompressionParameters

Zstandard offers a high-level compression level that maps to lower-level compression parameters. For many consumers, this numeric level is the only compression setting you’ll need to touch.

But for advanced use cases, it might be desirable to tweak these lower-level settings.

The ZstdCompressionParameters type represents these low-level compression settings.

class zstandard.ZstdCompressionParameters(format=0, compression_level=0, window_log=0, hash_log=0, chain_log=0, search_log=0, min_match=0, target_length=0, strategy=-1, write_content_size=1, write_checksum=0, write_dict_id=0, job_size=0, overlap_log=-1, force_max_window=0, enable_ldm=0, ldm_hash_log=0, ldm_min_match=0, ldm_bucket_size_log=0, ldm_hash_rate_log=-1, threads=0)

Low-level zstd compression parameters.

This type represents a collection of parameters to control how zstd compression is performed.

Instances can be constructed from raw parameters or derived from a base set of defaults specified from a compression level (recommended) via ZstdCompressionParameters.from_level().

>>> # Derive compression settings for compression level 7.
>>> params = zstandard.ZstdCompressionParameters.from_level(7)
>>> # With an input size of 1MB
>>> params = zstandard.ZstdCompressionParameters.from_level(7, source_size=1048576)

Using from_level(), it is also possible to override individual compression parameters or to define additional settings that aren’t automatically derived. e.g.:

>>> params = zstandard.ZstdCompressionParameters.from_level(4, window_log=10)
>>> params = zstandard.ZstdCompressionParameters.from_level(5, threads=4)

Or you can define low-level compression settings directly:

>>> params = zstandard.ZstdCompressionParameters(window_log=12, enable_ldm=True)

Once a ZstdCompressionParameters instance is obtained, it can be used to configure a compressor:

>>> cctx = zstandard.ZstdCompressor(compression_params=params)

Some of these are very low-level settings. It may help to consult the official zstandard documentation for their behavior. Look for the ZSTD_p_* constants in zstd.h (https://github.com/facebook/zstd/blob/dev/lib/zstd.h).

property chain_log
property compression_level
property enable_ldm
estimated_compression_context_size()

Estimated size in bytes needed to compress with these parameters.

property force_max_window
property format
static from_level(level, source_size=0, dict_size=0, **kwargs)

Create compression parameters from a compression level.

Parameters:
  • level – Integer compression level.

  • source_size – Integer size in bytes of source to be compressed.

  • dict_size – Integer size in bytes of compression dictionary to use.

Returns:

ZstdCompressionParameters

property hash_log
property job_size
property ldm_bucket_size_log
property ldm_hash_log
property ldm_hash_rate_log
property ldm_min_match
property min_match
property overlap_log
property search_log
property strategy
property target_length
property threads
property window_log
property write_checksum
property write_content_size
property write_dict_id