pyzstd: Zstandard Compression

0.19.1 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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")

view raw JSON →