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.0

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

Source distribution (sdist)

Source distribution for zxtd 0.1.0
File Size Uploaded
zxtd-0.1.0.tar.gz 9.4 kB Details

Built distribution (wheel)

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

Total release size: 382.1 kB

Release files / zxtd-0.1.0.tar.gz

Download URL zxtd-0.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4f837be2b809571bbcdaa0a71bd42f6c3141df6b08a5a5f6393bc21f592383c0
BLAKE2b-256 checksum
How to use checksums
c6f63d71c7395333fcb17d2c02a40592a3e22e6d7593bd0355d667788d8c2271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL zxtd-0.1.0-cp314-cp314-win_amd64.whl
Size 372.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
e9960266294d64107a7068bdd5b9804e4f7b3fe9f086cd17339c1de73bba1924
BLAKE2b-256 checksum
How to use checksums
f338a7aaaf067d80df6d47be671ed19f567f62263819a6085adf29e53d6f1c47
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

0.1.1

1 release file

This release

0.1.0 This release

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