{"id":3914,"library":"brotlipy","title":"Brotlipy: Python Bindings to Brotli Compression","description":"brotlipy is a Python library that provides CFFI-based bindings to Google's Brotli lossless compression algorithm. It enables Python applications to efficiently compress and decompress data using Brotli, supporting both one-shot and streaming operations. Version 0.7.0 is the final release of this library, as the project has been archived and its development continues under the `brotlicffi` package.","status":"renamed","version":"0.7.0","language":"en","source_language":"en","source_url":"https://github.com/python-hyper/brotlipy/","tags":["compression","brotli","performance","archived","cffi"],"install":[{"cmd":"pip install brotlipy","lang":"bash","label":"Basic Installation"},{"cmd":"sudo apt-get install build-essential python-dev libffi-dev","lang":"bash","label":"Linux Build Dependencies (Debian/Ubuntu)"},{"cmd":"sudo yum install gcc libffi-devel python-devel","lang":"bash","label":"Linux Build Dependencies (Red Hat/CentOS)"}],"dependencies":[{"reason":"Runtime dependency for the CFFI bindings.","package":"cffi","optional":false}],"imports":[{"note":"The package installs as `brotlipy` but exposes its functionality under the `brotli` module name, which can lead to conflicts with other `brotli` packages.","wrong":"import brotlipy","symbol":"brotli","correct":"import brotli"},{"note":"For one-shot compression.","symbol":"compress","correct":"brotli.compress(data)"},{"note":"For one-shot decompression.","symbol":"decompress","correct":"brotli.decompress(data)"},{"note":"For streaming compression.","symbol":"Compressor","correct":"brotli.Compressor()"},{"note":"For streaming decompression.","symbol":"Decompressor","correct":"brotli.Decompressor()"},{"note":"Exception raised for compression/decompression errors.","symbol":"Error","correct":"brotli.Error"}],"quickstart":{"code":"import brotli\n\noriginal_data = b\"This is some data to be compressed using Brotli. It can be any bytes string.\"\n\n# One-shot compression and decompression\ncompressed_data = brotli.compress(original_data, quality=11) # quality from 0-11\ndecompressed_data = brotli.decompress(compressed_data)\n\nprint(f\"Original size: {len(original_data)} bytes\")\nprint(f\"Compressed size: {len(compressed_data)} bytes\")\nprint(f\"Decompressed data matches original: {original_data == decompressed_data}\")\n\n# Streaming compression\ncompressor = brotli.Compressor(quality=5)\ncompressed_stream = b''\nchunk_size = len(original_data) // 2\n\ncompressed_stream += compressor.compress(original_data[:chunk_size])\ncompressed_stream += compressor.compress(original_data[chunk_size:])\ncompressed_stream += compressor.finish()\n\n# Streaming decompression\ndecompressor = brotli.Decompressor()\ndecompressed_stream = b''\n\ndecompressed_stream += decompressor.decompress(compressed_stream[:chunk_size])\ndecompressed_stream += decompressor.decompress(compressed_stream[chunk_size:])\ndecompressed_stream += decompressor.flush() # flush() is deprecated for Decompressor since 0.4.0 but shown in older docs\n\nprint(f\"Streaming decompression matches original: {original_data == decompressed_stream}\")","lang":"python","description":"This quickstart demonstrates both one-shot and streaming compression/decompression using `brotlipy`. For one-shot operations, `brotli.compress()` and `brotli.decompress()` are used. For streaming, `brotli.Compressor()` and `brotli.Decompressor()` objects are initialized, and data is processed in chunks. Remember that `brotli.compress()` and `brotli.decompress()` expect and return byte strings."},"warnings":[{"fix":"Migrate to `brotlicffi`: `pip install brotlicffi`. Update imports from `import brotli` to `import brotlicffi`. Refer to `brotlicffi` documentation for any API changes.","message":"The `brotlipy` package has been archived and is deprecated. All further development and updates have moved to the `brotlicffi` package. Users are strongly advised to migrate to `brotlicffi` for continued support and new features.","severity":"breaking","affected_versions":"0.7.0 and earlier"},{"fix":"Be aware of potential module name collisions. When migrating to `brotlicffi`, the import path changes to `import brotlicffi`.","message":"The `brotlipy` library installs as `brotlipy` but its main module is imported as `brotli`. This can create import conflicts if another Python package also provides a top-level `brotli` module (e.g., the pure-Python `brotli` package). The successor `brotlicffi` addresses this by using `import brotlicffi`.","severity":"gotcha","affected_versions":"All versions of brotlipy"},{"fix":"Install the necessary system-level development packages before running `pip install brotlipy`. Examples: `sudo apt-get install build-essential python-dev libffi-dev` (Debian/Ubuntu) or `sudo yum install gcc libffi-devel python-devel` (Red Hat/CentOS).","message":"On Linux systems, `brotlipy` is a CFFI-based binding that requires compilation during installation. This necessitates having a C compiler (e.g., `build-essential` or `gcc`), Python development headers (`python-dev` or `python-devel`), and the `libffi` development library (`libffi-dev` or `libffi-devel`) installed on the system.","severity":"gotcha","affected_versions":"All versions of brotlipy"},{"fix":"Ensure dictionary bytes are identical for corresponding compression and decompression operations. Store and manage dictionaries carefully.","message":"When using dictionaries with the compression and decompression APIs, it is crucial that the *exact same dictionary* is provided to both the compressor and the decompressor. A mismatch will lead to decompression errors or corrupted output.","severity":"gotcha","affected_versions":"0.5.0 and later"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}