Python bindings to the Zopfli Compression Algorithm, offering higher compression ratios than standard zlib or gzip at the cost of significantly slower compression time. It is primarily designed for pre-compressing static assets for web applications or other scenarios where file size is critical and compression is a one-off or build-time operation. Current version 0.4.1 requires Python 3.10+ and maintains an active release cadence, primarily driven by Python version compatibility and updates to the upstream C library.
pip install zopfliVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic Zopfli compression using both zlib and gzip formats, including decompression with standard library modules. Also provides a commented example for PNG optimization.
Upgrade Python to 3.10+ or pin `zopfli` to a compatible version (e.g., `<0.3.0` for Python 3.8/3.9).
Most users should be unaffected. If you encounter issues, verify your build chain or environment's compatibility with `abi3` wheels. Rebuilding from source might be necessary in niche cases.
Use Zopfli for pre-compressing static assets during a build process or deployment, rather than during a user request. Serve pre-compressed files with appropriate `Content-Encoding` headers.
Experiment with `numiterations` to find the optimal balance for your specific use case. Be mindful of the performance implications.
When decompressing output from `zopfli.gzip.compress`, use `gzip.GzipFile(fileobj=io.BytesIO(compressed_data)).read()` to ensure correct handling.
Upgrade to `zopfli` v0.4.1 or newer to benefit from the bug fix and ensure compatibility on strict-alignment architectures.
Install 'Build Tools for Visual Studio' from Microsoft's website, ensuring to select the 'Desktop development with C++' workload. Alternatively, try upgrading `pip` and `setuptools` and then `pip install zopfli` to attempt to use pre-compiled wheels.
Install the Python development package for your specific Python version (e.g., `sudo apt-get install python3-dev` on Debian/Ubuntu, `sudo dnf install python3-devel` on Fedora/CentOS, or ensure a full Python installation via Homebrew on macOS).
Ensure `zopfli` is correctly installed by running `pip install zopfli`. If installation errors occur, address those first. Verify you are using the Python interpreter where `zopfli` was installed.
Encode the string to bytes before compression (e.g., `my_string.encode('utf-8')`) and decode the resulting bytes back to a string after decompression (e.g., `decompressed_bytes.decode('utf-8')`).No dependency data recorded yet.