Python compression libraries

Updated Nov 2026

Python compression libraries shrink data for storage or transfer and restore it byte for byte. Each codec trades compression ratio against speed, from fast codecs for streaming to slow codecs that maximize savings. These libraries let data pipelines, web servers, and file formats cut storage and bandwidth costs.

Popularity

python-zstandard has the most monthly downloads in this comparison, at 188.2M.

LibraryMonthly downloadsStarsLast releaseLicense
zstandard
194.6M
649Sep 2025BSD-3-Clause
Brotli
123.5M
15.1KOct 2026MIT
LZ4
84.9M
306Nov 2025BSD-3-Clause
backports.zstd
59.1M
31Oct 2026PSF-2.0
Zopfli
44.9M
16Jun 2026Apache-2.0
cramjam
31.9M
130Oct 2026MIT
inflate64
12.0M
2Nov 2025LGPL-2.1-or-later
PyPPMd
11.6M
12Nov 2025LGPL-2.1-or-later
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Exposes Zstandard compression through one-shot and streaming Python APIs.

Downloads / mo
194.6M
Stars
649
Last release
0.25.0
License
BSD-3-Clause

Strengths

  • Reuses compression contexts. Reuse a compressor for repeated operations instead of recreating it.
  • Supports shared compression dictionaries. Improve compression for small inputs that share recurring structure.

Limitations

  • Concurrent operations need separate contexts. Create a separate context for each simultaneously active operation.
  • One-shot operations hold both buffers. Use streaming when input and output cannot fit in memory together.

Quickstart

From compressor.html
$ python -m pip install zstandard
import zstandard as zstd

compressed = zstd.compress(b"hello")
print(compressed)

zstandard examples

From open-source projects on GitHub
def zstd_decode(payload):
    if not zstd:
        raise NotImplementedError("Zstd codec is not available")
    with zstd.ZstdDecompressor().stream_reader(io.BytesIO(payload), read_across_frames=True) as reader:
        return reader.read()

Binds the Brotli compression library for Python.

Downloads / mo
123.5M
Stars
15.1K
Last release
1.2.1
License
MIT

Quickstart

From brotli.py
$ python -m pip install brotli
import brotli

compressed = brotli.compress(b"hello")
print(compressed)

Brotli examples

From open-source projects on GitHub
def decode(self, data: bytes) -> bytes:
        if not data:
            return b""
        self.seen_data = True
        try:
            return self._decompress(data)
        except brotli.error as exc:
            raise DecodingError(str(exc)) from exc

Provides Python bindings for interoperable LZ4 frame compression.

Downloads / mo
84.9M
Stars
306
Last release
4.4.5
License
BSD-3-Clause

Strengths

  • Produces interoperable LZ4 frames. Use frame bindings when exchanging compressed data with other implementations.
  • Processes data in chunks. Compress and decompress incrementally instead of holding the full input.

Limitations

  • Checksums are disabled by default. Enable content_checksum when frame content needs checksum validation.
  • Buffered chunks can delay output. Enable auto_flush when each compression call needs immediate output.

Quickstart

From quickstart.rst
$ python -m pip install lz4
import lz4.frame

compressed = lz4.frame.compress(b"hello")
print(compressed)

LZ4 examples

From open-source projects on GitHub
def compressor_file(self, fileobj, compresslevel=None):
        """Returns an instance of a compressor file object."""
        self._check_versions()
        if compresslevel is None:
            return self.fileobj_factory(fileobj, "wb")
        else:
            return self.fileobj_factory(fileobj, "wb", compression_level=compresslevel)

backports.zstd

Backports the compression.zstd module.

Downloads / mo
59.1M
Stars
31
Last release
1.8.0
License
PSF-2.0

Quickstart

From README.md
$ python -m pip install "backports.zstd; python_version < '3.14'"
import sys

if sys.version_info >= (3, 14):
    from compression import zstd
else:
    from backports import zstd

compressed = zstd.compress(b"hello")
print(compressed)

backports.zstd examples

From open-source projects on GitHub

Provides the Zopfli compressor for Python.

Downloads / mo
44.9M
Stars
16
Last release
0.4.3
License
Apache-2.0

Quickstart

From README.rst
$ python -m pip install zopfli
from zopfli.zlib import compress

compressed = compress(b"hello")
print(compressed)

Zopfli examples

From open-source projects on GitHub

cramjam

Bundles multiple compression algorithms behind Python bindings.

Downloads / mo
31.9M
Stars
130
Last release
2.14.0
License
MIT

Strengths

  • Offers multiple codec families. Choose Snappy, Brotli, LZ4, Zstandard, and other codecs through one package.
  • Writes into supplied buffers. Use compress_into and decompress_into with existing output storage.

Limitations

  • Experimental codecs require source builds. Enable each experimental feature when building from source.
  • Finishing consumes the streaming compressor. Create another compressor after calling finish.

Quickstart

From README.md
$ python -m pip install cramjam
import cramjam

compressed = bytes(cramjam.snappy.compress(b"hello"))
print(compressed)

Compresses and decompresses Deflate64 data.

Downloads / mo
12.0M
Stars
2
Last release
1.0.4
License
LGPL-2.1-or-later

Quickstart

From README.rst
$ python -m pip install inflate64
import inflate64

compressor = inflate64.Deflater()
compressed = compressor.deflate(b"hello") + compressor.flush()
print(compressed)

inflate64 examples

From open-source projects on GitHub

Compresses and decompresses PPMd data.

Downloads / mo
11.6M
Stars
12
Last release
1.3.1
License
LGPL-2.1-or-later

Quickstart

From __init__.py
$ python -m pip install pyppmd
import pyppmd

compressed = pyppmd.compress(b"hello")
print(compressed)

PyPPMd examples

From open-source projects on GitHub
def decompress(self, data: bytes | bytearray | memoryview, max_length=-1) -> bytes:
        if len(data) == 0 and self.decoder.needs_input:
            return self.decoder.decode(b"\0", max_length)
        return self.decoder.decode(data, max_length)

FAQ

zstandard suits general compression with a strong ratio at high speed. LZ4 suits workloads that need the fastest compression and decompression. Brotli suits web assets served to browsers.

Brotli usually compresses text smaller than gzip at a similar decompression speed. Browsers accept both encodings for HTTP responses.

Zstandard compresses faster than gzip at a similar or higher ratio and decompresses much faster. gzip remains the choice where only the standard library or older tools are available.

The standard library includes zlib, gzip, and lzma modules. Recent releases add a Zstandard module, and backports.zstd brings that module to older versions.

cramjam bundles many compression algorithms, including Snappy, Brotli, and Zstandard, behind one set of Rust-backed bindings.

For coding agents

Found your compression library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official