{"id":2419,"library":"brotlicffi","title":"BrotliCFFI","description":"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.","status":"active","version":"1.2.0.1","language":"en","source_language":"en","source_url":"https://github.com/python-hyper/brotlicffi","tags":["compression","brotli","cffi","data-science","network"],"install":[{"cmd":"pip install brotlicffi","lang":"bash","label":"Install from PyPI"},{"cmd":"conda install -c conda-forge brotlicffi","lang":"bash","label":"Install with Conda"}],"dependencies":[{"reason":"Provides the Foreign Function Interface for Python to call C code.","package":"cffi","optional":false},{"reason":"The underlying Brotli compression library (shared library, typically installed as a system dependency or bundled).","package":"libbrotli1","optional":false}],"imports":[{"note":"Prior to version 0.8.0, the import namespace was 'brotli', which conflicted with Google's native 'brotli' package. The correct import is now 'brotlicffi'.","wrong":"import brotli","symbol":"brotlicffi","correct":"import brotlicffi"}],"quickstart":{"code":"import brotlicffi\n\noriginal_data = b\"This is some sample data that will be compressed using Brotli!\"\n\n# Compress data\ncompressed_data = brotlicffi.compress(original_data)\nprint(f\"Original size: {len(original_data)} bytes\")\nprint(f\"Compressed size: {len(compressed_data)} bytes\")\n\n# Decompress data\ndecompressed_data = brotlicffi.decompress(compressed_data)\n\nprint(f\"Decompressed data: {decompressed_data}\")\nassert original_data == decompressed_data\nprint(\"Compression and decompression successful!\")","lang":"python","description":"This quickstart demonstrates basic compression and decompression of a byte string using `brotlicffi.compress()` and `brotlicffi.decompress()`."},"warnings":[{"fix":"Update your `pip install` command to `pip install brotlicffi` and change all `import brotli` statements to `import brotlicffi`.","message":"Package renamed from `brotlipy` to `brotlicffi` and import namespace changed from `brotli` to `brotlicffi` to avoid conflicts with Google's official Brotli C bindings.","severity":"breaking","affected_versions":"<0.8.0"},{"fix":"Remove the `dictionary` parameter from calls to `compress()` or `Compressor` instantiation.","message":"The `dictionary` parameter was removed from `brotlicffi.compress()` and `brotlicffi.Compressor`.","severity":"breaking","affected_versions":">=1.0.9.0"},{"fix":"Upgrade your Python environment to Python 3.8 or newer.","message":"Support for Python 2.7, 3.5, and 3.6 was explicitly removed.","severity":"breaking","affected_versions":">=1.1.0.0"},{"fix":"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.","message":"Concurrent sharing of `Compressor` or `Decompressor` objects across multiple threads (especially with Python 3.14's free-threaded build) now raises an exception.","severity":"breaking","affected_versions":">=1.2.0.1"},{"fix":"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.","message":"`decompress()` would return an empty bytestring instead of erroring if the provided bytestring was too small or malformed.","severity":"gotcha","affected_versions":"<0.6.0"},{"fix":"Consider upgrading to version 1.2.0.0 or later and utilizing the `output_buffer_limit` parameter when decompressing untrusted data.","message":"The `output_buffer_limit` parameter was added to `Decompressor.decompress()` and `Decompressor.process()` methods to mitigate potential security concerns from maliciously crafted compressed data leading to excessive memory usage.","severity":"gotcha","affected_versions":"<1.2.0.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}