Registry / serialization / pyzstd

pyzstd

JSON →
library0.19.1pypypi✓ verified 27d ago

pyzstd provides high-performance Python bindings for the Zstandard (zstd) lossless compression algorithm. It enables fast compression and decompression for bytes-like objects and file streams, leveraging the C zstd library. The current stable version is 0.19.1, and it is actively maintained with regular releases.

pip install pyzstd
INSTALL
IMPORT
SIG · PYZSTD
P
pyzstd
serializationpythonv0.19.1
Install
1.9s avg
Import
48ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.19.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.050s · 19.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.046s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pyzstd
import pyzstd
import zstd
EndlessZstdDecompressor
from pyzstd import EndlessZstdDecompressor
from zstd import EndlessZstdDecompressor
SeekableZstdFile
from pyzstd import SeekableZstdFile
from zstd import SeekableZstdFile

This quickstart demonstrates basic compression and decompression of bytes-like objects using the top-level `zstd.compress` and `zstd.decompress` functions, including specifying a compression level.

import zstd original_data = b"This is some sample data that will be compressed using Zstandard!" # Compress data with default level (3) compressed_data = zstd.compress(original_data) print(f"Original size: {len(original_data)} bytes") print(f"Compressed size: {len(compressed_data)} bytes") # Decompress data decompressed_data = zstd.decompress(compressed_data) # Verify data integrity assert original_data == decompressed_data print("Data decompressed successfully and matches original.") # Example with a specific compression level compressed_level_20 = zstd.compress(original_data, 20) print(f"Compressed size (level 20): {len(compressed_level_20)} bytes")
Debug
Known issues
breakingIn version 0.17.0, the `zstd.compress_file` and `zstd.decompress_file` functions were removed, and the signature of `zstd.open` was changed significantly. Direct file handling methods are no longer available at the top level.
fix
For file-like objects, use `zstd.ZstdCompressor().compress_stream()` or `zstd.ZstdDecompressor().decompress_stream()`. Alternatively, use `zstd.open_compressed_file()` for stream-based file I/O.
affects: >=0.17.0
gotchaThe top-level `zstd.compress()` and `zstd.decompress()` functions are designed for bytes-like objects in memory. Attempting to pass file objects directly to them will result in errors or unexpected behavior.
fix
For efficient processing of file-like objects (e.g., `io.BytesIO`, file handles), instantiate `zstd.ZstdCompressor()` or `zstd.ZstdDecompressor()` and use their `compress_stream()` or `decompress_stream()` methods.
affects: All versions
gotchaCompression levels in `pyzstd` range from 1 to 22 (inclusive), with 3 being the default. Higher levels offer better compression but require significantly more CPU time. Using a value outside this range will raise an error.
fix
Carefully select compression levels based on your application's balance of compression ratio and performance requirements. Always ensure the level is within the valid range [1, 22].
affects: All versions
Upgrade
Version history
0.19.1latest on PyPI · released Dec 13, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
pyzstd — pip install pyzstd · libregistry