Skip to main content

Overview

Zstandard is implemented as a C library, but language bindings are available for many popular programming languages. These bindings provide idiomatic APIs for each language while leveraging the performance of the native C implementation.

Official Implementations

The reference implementation is provided as an open-source dual BSD OR GPLv2 licensed C library.

Reference C Library

The official C implementation includes:
  • libzstd - Core compression/decompression library
  • zstd - Command-line utility
  • Complete API documentation in lib/zstd.h

Language Bindings Directory

For projects requiring other programming languages, a comprehensive list of known ports and bindings is provided on the Zstandard homepage.
Language bindings are maintained by the community and may vary in features, performance, and API design. Always check the specific binding’s documentation for details.

Finding Bindings

The Zstandard homepage provides an up-to-date directory of bindings for:
  • Python - Multiple implementations available
  • Java - JNI bindings and pure Java implementations
  • Go - Native Go and CGo implementations
  • Rust - Safe Rust wrappers
  • JavaScript/Node.js - Native module bindings
  • Ruby - Gem packages
  • PHP - PECL extensions
  • C#/.NET - Managed wrappers
  • Perl - CPAN modules
  • Haskell - Hackage packages
  • Lua - LuaRocks modules
  • Erlang/Elixir - Hex packages
  • And many more…

Browse All Bindings

Visit the official Zstandard homepage for the complete list of language bindings and their current status.
While the official list is maintained on the Zstandard homepage, here are some commonly used bindings:

Python

Multiple Python packages are available providing different feature sets:
  • python-zstandard - Full-featured Python bindings
  • zstd - Simple compression/decompression interface

Java

Java implementations include:
  • zstd-jni - JNI bindings to native library
  • Pure Java implementations for environments where native code isn’t available

Go

Go has several options:
  • CGo bindings for performance
  • Pure Go implementations for portability

Rust

Rust bindings provide safe wrappers around the C library:
  • zstd crate on crates.io
  • Safe Rust API with zero-cost abstractions

Integration Approaches

Native Bindings

Direct bindings to the C library provide maximum performance and feature completeness.Pros:
  • Best performance
  • Full feature support
  • Synchronized with C library updates
Cons:
  • Requires native compilation
  • Platform-specific binaries

Pure Implementations

Native language implementations without C dependencies.Pros:
  • No compilation required
  • Easy deployment
  • Platform-independent
Cons:
  • May have limited features
  • Potentially slower
  • Separate maintenance

FFI (Foreign Function Interface)

For languages not listed on the official bindings page, you can create your own FFI wrapper to the C library:

Requirements

  1. Install libzstd: System-wide installation of the Zstandard library
  2. FFI Support: Your language must support calling C functions
  3. Header Access: Access to zstd.h for API definitions

Example Approach

Most FFI implementations follow this pattern:
  1. Link to libzstd.so (Linux), libzstd.dylib (macOS), or libzstd.dll (Windows)
  2. Declare function signatures from lib/zstd.h
  3. Create idiomatic wrappers for your language
  4. Handle memory management appropriately
import ctypes

# Load library
libzstd = ctypes.CDLL('libzstd.so')

# Declare function
libzstd.ZSTD_versionNumber.restype = ctypes.c_uint

# Call function
version = libzstd.ZSTD_versionNumber()
print(f"Zstd version: {version}")

Package Managers

Many language-specific package managers include Zstandard bindings:
pip install zstandard
# or
pip install zstd

Using Language Bindings

Common Features

Most language bindings provide:
  • Simple API: One-shot compression/decompression
  • Streaming API: For large files or streams
  • Dictionary Training: Create custom dictionaries
  • Dictionary Compression: Use dictionaries for better compression
  • Frame Parameters: Access frame content size, checksums, etc.

Feature Compatibility

When choosing a binding, verify:

Compatibility

Format Stability

Zstandard’s format is stable and documented in RFC 8878. All compliant implementations can decompress data compressed by any other compliant implementation.
Starting from v0.8.0, all versions of Zstandard produce frames compliant with the specification and are therefore compatible with each other.

Multiple Independent Implementations

The stable format has enabled multiple independent implementations across different languages and platforms, all maintaining interoperability.

Best Practices

Use Official Bindings

When available, prefer bindings listed on the official Zstandard homepage for better maintenance and community support.

Check Version Support

Ensure the binding supports the Zstandard version and features you need.

Test Performance

Benchmark different bindings if performance is critical - native bindings typically outperform pure implementations.

Verify Maintenance

Check that the binding is actively maintained and compatible with recent Zstandard versions.

Contributing Bindings

If you’ve created a Zstandard binding for a language:
  1. Ensure compatibility with the Zstandard specification (RFC 8878)
  2. Include comprehensive tests
  3. Document the API clearly
  4. Submit your binding to be listed on the Zstandard homepage

Next Steps

Official Bindings List

Browse the complete list of available language bindings

C/C++ Integration

Learn about the reference C implementation

Build Systems

Integrate the C library into your build system

Zstandard RFC

Read the official format specification

Build docs developers (and LLMs) love