Constriction Library

entropy coders for research and production

The constriction library for Python and Rust provides a collection of highly optimized entropy coders with a clear and consistent API.

constriction speeds up the transition from research to production. Start by experimenting on a new entropy model with your favorite machine learning framework and constriction's simple Python API. Then turn your working prototype into an efficient standalone binary, library, or WebAssembly module with constriction's optimized and highly flexible Rust API.

Quick Start

For Data Scientists:

Install constriction for Python:

pip install --upgrade pip
pip install constriction

Then try out this example.

For Systems Engineers:

Use constriction in your Rust project:

[dependencies] # (in Cargo.toml)
constriction = "0.3.5"

Then try out this example.

Demos

Documentation

What's Included?

Python logoconstriction
for Python
Rust logoconstriction
for Rust
Range Coding (example) (details)
Asym­met­ric Numeral Systems (ANS) (example) (example)
Chain Coding (experimental new method, see proposal) (example) (example)
Huffman Coding (example) (example)
Efficient and exactly invertible entropy models (list) (list)
Adapters for custom entropy models (details) (example)
Compatible with scipy​.stats (details) n/a
Compile-time configuration of coder details (optional) (details)
no_std support (e.g., for Web­Assembly) n/a (demo)

Benchmarks

See detailed benchmark results in the readme.

In brief, constriction's stream codes are optimized for low bit rate and fast encoding and decoding. With default settings in a real-world scenario, the provided stream codes (both Range Coding and Asymmetric Numeral Systems) achieve a bit rate that is less than 0.1 % above the theoretically achievable minimum bit rate while being considerably faster than arithmetic coding. Users of constriction's Rust API can optionally specify more advanced coder and model settings at compile time to trade off between bit rate, memory usage, and run time (see documentation).

Cite

I'd appreciate attribution if you use constriction in your scientific work. You can cite the following paper, which announces constriction (Section 5.1) and analyzes its compression performance and runtime efficiency (Section 5.2):

R. Bamler, Understanding Entropy Coding With Asymmetric Numeral Systems (ANS): a Statistician's Perspective, arXiv preprint arXiv:2201.01741.

BibTex: (copy to clipboard)

Contribute

Issues and pull requests are very welcome in our code repository.

What's With the Name?

constriction is a compression library with bindings for Rust and Python. Pythons are a family of nonvenomous snakes that subdue their prey by “compressing” it, a method known as constriction.