Python 3.14+compression.zstdterm
compression.zstd.CompressionParameter
compression parameters
An enum of fine-grained zstd compression settings used as keys of the options dict: level, window, strategy, checksum, threads.
Syntax
options={CompressionParameter.<имя>: значение}; CompressionParameter.<имя>.bounds()
These are IntEnum keys, not values: options={CompressionParameter.checksum_flag: 1}. Each parameter's valid range depends on the libzstd version and is reported by bounds(); going outside it raises ValueError. checksum_flag appends a 4-byte checksum to the frame, which decompression verifies. content_size_flag=0 drops the size from the header, so get_frame_info no longer reports it. nb_workers > 0 works only if libzstd was built with threading support.
Examples
# Python 3.14+
from compression import zstd # → ? нужна сборка CPython с libzstd
P = zstd.CompressionParameter
data = b'hello zstd ' * 100
plain = zstd.compress(data)
checked = zstd.compress(data, options={P.checksum_flag: 1})
print(len(checked) - len(plain)) # → 4 — байты контрольной суммы
print(P.compression_level.bounds()) # → ? (-131072, 22) — зависит от версии libzstd
try:
zstd.compress(data, options={P.window_log: 100})
except ValueError:
print('ValueError') # → ValueError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy