Python bindings for the Brotli compression library. It offers high-performance lossless compression, often achieving better ratios than gzip, particularly for text-based data. The library's releases are typically synchronized with updates to the underlying C Brotli reference implementation.
pip install brotliVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic one-shot compression and decompression, as well as a simple streaming compression and decompression using `brotli.Compressor` and `brotli.Decompressor`. It also shows how to handle the `output_buffer_limit` introduced in v1.2.0 for security.
Upgrade to brotli v1.2.0 or newer. For streaming decompression, actively use the `output_buffer_limit` parameter in `Decompressor.process()` and handle `brotli.error` if the limit is exceeded.
Upgrade to brotli v1.0.9 or newer.
Wrap decompression calls in a `try...except brotli.error` block to gracefully handle invalid input.
Always call `compressor.finish()` after feeding all data chunks to `compressor.process()` to ensure all remaining data is emitted.
Always open files for Brotli operations with `b` in the mode string (e.g., `open('file.br', 'wb')`).Check the `Content-Encoding` header or the documentation of your HTTP client to determine if automatic decompression is occurring before attempting manual decompression.
Do not call `finish()` on a `brotli.Decompressor` object. For streaming decompression, feed all compressed data chunks into `decompressor.process()` until all data is decompressed.
Remove calls to `decompressor.finish()`. Ensure all output from `decompressor.process()` is collected during streaming decompression. When all input is processed, any remaining decompressed data will have been emitted by the last `decompressor.process()` call.
Ensure you have the Microsoft Visual C++ Build Tools installed (available through Visual Studio Installer). Then, try uninstalling and reinstalling brotli: `pip uninstall brotli` followed by `pip install brotli`. It is also recommended to use a virtual environment.
First, try updating or reinstalling `brotli`: `pip install --upgrade brotli`. If the issue persists, explicitly uninstall both `brotli` and `brotlipy`/`brotlicffi` and then reinstall only `brotli`: `pip uninstall brotli brotlipy brotlicffi` then `pip install brotli`.
On Windows, install the Microsoft Visual C++ Build Tools. On Linux, ensure you have build essentials (e.g., `sudo apt-get install build-essential` or `sudo yum groupinstall 'Development Tools'`). Then retry `pip install brotli`.
Verify the integrity and completeness of the Brotli-compressed data you are trying to decompress. Ensure the data source is reliable and that the entire compressed stream is received before attempting decompression. If fetching from a server, check server-side compression settings and content delivery.
No dependency data recorded yet.