py-zopfli

Python bindings to Google's Zopfli high-ratio DEFLATE compression library.

Library
PyPI
v0.4.3
14 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
31 /100 Needs Attention
Development Activity 12
Maintenance 20
Community 20
Maturity 60
Momentum 12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
72 /100 Good
Architecture 70
Code Quality 72
Innovation 62
Learning Curve 85

zopfli (pyzopfli) provides CPython bindings to Google’s Zopfli, a compression library that produces zlib/DEFLATE- and gzip-compatible output that is smaller than what standard zlib generates. Zopfli trades substantially more CPU time for a better compression ratio, so it is ideal for data that is compressed once and served many times.

The package wraps Zopfli’s ZlibCompress and GzipCompress routines behind simple Python functions, and is maintained under the fontTools organization where it is used to shrink WOFF/WOFF2 web font payloads.

What You Get

  • A zopfli.zlib.compress function producing zlib/DEFLATE-compatible output
  • A zopfli.gzip.compress function producing gzip-compatible output
  • Tunable parameters such as numiterations to trade time for ratio
  • A compiled C extension wrapping the upstream Zopfli implementation

Common Use Cases

  • Pre-compressing web fonts (WOFF) to reduce download size
  • Shrinking static assets that are compressed once and served many times
  • Producing smaller gzip files where extra compression time is acceptable

Under The Hood

Architecture - The package is a thin CPython extension: the upstream Zopfli C sources are vendored and compiled into a native module, and small Python wrappers in the zopfli.zlib and zopfli.gzip modules expose ZlibCompress and GzipCompress with keyword options. Input bytes are passed to the C implementation, which runs Zopfli’s iterative DEFLATE optimization and returns the compressed bytes.

Tech Stack - Roughly 62% Python and 38% C. The Python layer handles the module API and argument marshaling while the C layer is the Zopfli algorithm itself. It requires Python 3.10+, builds against a C compiler at install time (or via prebuilt wheels), and lives under the fontTools GitHub organization.

Code Quality - A mature, focused wrapper maintained since 2017 across 20 releases. Its scope is small and stable, and its use inside the widely deployed fontTools toolchain provides strong real-world validation. Community footprint is modest, reflecting a niche but important utility.

API Design - The API is intentionally minimal: import compress from the relevant submodule and call it on a bytes object, optionally passing integer tuning parameters like numiterations and verbose. The zlib wrapper mirrors zlib’s semantics closely; the gzip wrapper deliberately does not imitate the stdlib gzip module, returning compressed bytes directly.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers