Skip to main content

zxtd

High-performance Zstandard compression/decompression library with dictionary support, multi-threading, and Python bindings.

Author: Quadrium

Features

  • Fast compression/decompression using Facebook's Zstandard (zstd) library
  • Dictionary support for better compression ratios on small data
  • Multi-threaded compression for improved performance on large data
  • Streaming API for memory-efficient processing of large files
  • Frame inspection to detect dictionary IDs and content sizes
  • Checksum verification for data integrity
  • Python bindings via PyO3/maturin
  • Async support (optional feature)

Installation

pip install zxtd

Python Usage

import zxtd

# Basic compression/decompression
data = b"Hello, Zstandard! " * 100
compressed = zxtd.compress(data, 3)  # level 1-22
decompressed = zxtd.decompress(compressed)
assert decompressed == data

# Dictionary compression (better for small, similar data)
dict_data = b"common prefix that repeats often "
dictionary = zxtd.Dictionary.from_bytes(dict_data)

original = b"common prefix that repeats often - unique part"
compressed = zxtd.compress_with_dict(original, 3, dictionary)
decompressed = zxtd.decompress_with_dict(compressed, dictionary)

# Custom compression parameters
params = zxtd.CompressionParams(6)
params.with_threads(4)           # Use 4 threads
params.with_checksum(True)       # Enable checksum
compressed = zxtd.compress_with_params(data, params)

# Frame inspection
info = zxtd.frame_info(compressed)
print(f"Magic: 0x{info.magic:x}, Dict ID: {info.dict_id}")

# Detect dictionary ID from frame
dict_id = zxtd.Dictionary.detect_dict_id(compressed)

# Compression levels
levels = zxtd.compression_levels()
# {'FASTEST': 1, 'FAST': 3, 'DEFAULT': 3, 'BETTER': 6, 'BEST': 9, 'ULTRA': 22}

# Verify checksum
decompressed = zxtd.decompress_verify(compressed)

Rust Usage

Add to Cargo.toml:

zxtd = { path = "../zstd-decompress", features = ["async"] }
use zxtd::{compress, decompress, CompressionParams, Dictionary};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let data = b"Hello, Zstandard!";
    
    // Basic usage
    let compressed = compress(data, 3)?;
    let decompressed = decompress(&compressed)?;
    assert_eq!(data, &decompressed[..]);
    
    // With dictionary
    let dict = Dictionary::new(b"common prefix ".to_vec())?;
    let compressed = compress_with_dict(data, 3, &dict)?;
    let decompressed = decompress_with_dict(&compressed, &dict)?;
    
    // Custom params with multi-threading
    let params = CompressionParams::new(6).with_threads(4);
    let compressed = compress_with_params(data, &params, None)?;
    
    // Streaming
    let mut decompressor = StreamingDecompressor::new(compressed)?;
    let mut buf = [0u8; 1024];
    while let Ok(n) = decompressor.read(&mut buf) {
        if n == 0 { break; }
        // process buf[..n]
    }
    
    Ok(())
}

Performance

  • Multi-threaded compression scales linearly with cores
  • Dictionary compression can achieve 2-5x better ratios on small similar data
  • Streaming API uses constant memory regardless of input size
  • Zero-copy decompression where possible

License

MIT

Release files for zxtd 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for zxtd 0.1.1
File Interpreter ABI Platform
zxtd-0.1.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details

Release files / zxtd-0.1.1-cp314-cp314-win_amd64.whl

Download URL zxtd-0.1.1-cp314-cp314-win_amd64.whl
Size 374.3 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
2da8efb87cd58f0dab5ffb514740567b3cb551342bc8f77cd39b9062450d4b7f
BLAKE2b-256 checksum
How to use checksums
2c68bec8890225acd794998b27cec04b04367f05dd8046500c643b31b79a653e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

0.1.2

1 release file

This release

0.1.1 This release

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page