deflate
raw JSON → 0.8.1 verified Sat May 09 auth: no python
Python wrapper for libdeflate, providing fast compression and decompression for raw deflate, zlib, and gzip formats. Current version: 0.8.1. Release cadence: irregular, with recent updates focusing on CMake/scikit-build-core migration.
pip install deflate Common errors
error AttributeError: module 'deflate' has no attribute 'Deflate' ↓
cause Importing `import deflate` then using `deflate.Deflate` works, but older code may mistakenly try `from deflate import Deflate` after upgrading from version <0.7 where symbols were different.
fix
Use
from deflate import Deflate (this works in 0.7+). If you have an old version, upgrade to 0.8.1. error ValueError: Invalid header for gzip format ↓
cause Data is not valid gzip. The library raises ValueError (since 0.7.0) instead of the old DeflateError.
fix
Ensure data is actually gzip-compressed, or catch ValueError.
error deflate.DeflateError: ... ↓
cause Using an older version (<0.7.0) where DeflateError existed. Upgrading to 0.7+ removes this exception.
fix
Upgrade to 0.8.1 and change exception handling to ValueError.
Warnings
breaking In version 0.7.0, DeflateError was removed; invalid gzip data now raises ValueError instead of DeflateError. If your code catches DeflateError, it will break. ↓
fix Replace `except DeflateError` with `except ValueError`.
gotcha Compression level 0 means no compression, not default. Level 6 is the default. If you pass level=0 expecting 'fastest', you get uncompressed data. ↓
fix Use level=6 for default compression, or any level 1-12 for libdeflate (12 is maximum).
deprecated The function `deflate.deflate` and `deflate.inflate` are deprecated since 0.7.0. Use the Deflate class instead. ↓
fix Replace `deflate.deflate(data)` with `Deflate.compress(data, format='deflate')`.
Imports
- Deflate wrong
import deflatecorrectfrom deflate import Deflate - DEFLATE
from deflate import DEFLATE
Quickstart
from deflate import Deflate
data = b'Hello, world! ' * 1000
compressed = Deflate.compress(data, format='deflate')
decompressed = Deflate.decompress(compressed, format='deflate')
assert data == decompressed
print('Success!')