BrotliCFFI provides Python CFFI bindings to Google's high-performance Brotli compression library. It allows Python applications to leverage the Brotli compression algorithm efficiently across various Python interpreters, including PyPy. The current version is 1.2.0.1, and it maintains an active release cadence with regular updates to the underlying Brotli library and Python compatibility.
pip install brotlicffiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic compression and decompression of a byte string using `brotlicffi.compress()` and `brotlicffi.decompress()`.
Update your `pip install` command to `pip install brotlicffi` and change all `import brotli` statements to `import brotlicffi`.
Remove the `dictionary` parameter from calls to `compress()` or `Compressor` instantiation.
Upgrade your Python environment to Python 3.8 or newer.
Ensure that `Compressor` and `Decompressor` instances are not shared concurrently between threads. Create a new instance per thread or use appropriate locking mechanisms if sharing is unavoidable.
This bug was resolved in version 0.6.0. Ensure you are using version 0.6.0 or newer. For older versions, explicitly check the length of the decompressed data.
Consider upgrading to version 1.2.0.0 or later and utilizing the `output_buffer_limit` parameter when decompressing untrusted data.
Replace `brotlicffi.error` with `brotlicffi.Error` in your exception handling. Ensure you are using a compatible version of `brotlicffi` that provides the `Error` exception.
Reinstall `brotlicffi` cleanly using `pip uninstall brotlicffi` followed by `pip install brotlicffi`. If the issue persists, ensure your C compiler toolchain is up-to-date and compatible with your Python version and operating system. On macOS, issues with `libstdc++` might require specific compiler configurations or system updates.
If you intend to use `brotlicffi`, change your import statement from `import brotli` to `import brotlicffi`. If you need both or prefer the `brotli` package for CPython, install it via `pip install brotli`. A common pattern for cross-implementation compatibility is `try: import brotlicffi as brotli except ImportError: import brotli`.
Ensure a single, consistent version of `cffi` is installed and used. Try `pip uninstall cffi` multiple times until it reports no package found, then reinstall with `pip install cffi`. If using a package manager like `conda`, ensure `cffi` is managed consistently within your environment. Sometimes, explicitly downgrading `cffi` to match an expected version can also resolve this.