Guide · Open source
How to use Brotli: install, compress and decompress data
Updated · written with AI from the project's own documentation and checked against our catalogue data
Brotli is a general-purpose lossless compression algorithm, defined in RFC 7932, that makes data smaller without losing any of it. This guide is for developers and engineers who want to install Brotli and decide whether it fits their compression work. By the end you will know how to install it with pip, apt, Homebrew or CMake, and what the format does and does not guarantee.
Quick start
- 1Pick your install route. Choose pip for Python, apt for Debian-based Linux, Homebrew for macOS, or CMake to build from source.
- 2Install the package. Run the matching command from the README, such as pip install brotli.
- 3Check the install. Confirm the module or binary is available in your environment before writing code against it.
- 4Compress your data. Use the Python module or the built C library to compress the data you need smaller.
- 5Decompress and verify. Decompress the stream with the same library and confirm the output matches what you expect.
- 6Add integrity checks if needed. Because Brotli streams have no checksums or length metadata, add your own verification where corruption matters.
What Brotli is and how it works
Brotli is a generic-purpose lossless compression algorithm. It combines a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling. According to the project README, its compression ratio is comparable to the best currently available general-purpose compression methods.
The README says Brotli is similar in speed to deflate but produces denser output, so the compressed files are smaller at a similar speed. The format is specified in RFC 7932 and the project is open-sourced under the MIT License.
Install Brotli on Linux, macOS or with Python
On most Linux distributions, the package manager is the simplest route. On Debian-based systems, install it with apt. On macOS, use Homebrew. If you work in Python, install the Python module with pip. The README notes that the Python module requires Python.
To build from source, the README uses CMake. Building from source requires CMake.
- Debian-based Linux: install the brotli package with apt
- macOS: install brotli with Homebrew
- Python: install the module with pip
- Source build: use CMake, which the README describes
pip install brotli
apt install brotli
brew install brotliBuild Brotli from source with CMake
The README gives basic CMake commands to build and install Brotli. Create an output directory, configure it with a Release build type and an install prefix, then build the install target. You can use other CMake configuration options as well.
This route suits maintainers who need a C build to embed compression in their own software.
mkdir out && cd out
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed ..
cmake --build . --config Release --target installGet the latest development version with pip
The README says pip installs the latest release. To install the tip-of-the-tree version from the repository, use the git URL form shown in the README. For details on installing from source, development and testing, see the Python readme in the project.
pip install --upgrade git+https://github.com/google/brotliKnow the limits before you rely on Brotli
Brotli is a stream format. It does not contain meta-information such as checksums or uncompressed data length. The README warns that you can modify raw ranges of a compressed stream and the decoder will not notice.
If your pipeline needs corruption detection or length metadata, add that yourself or choose a format that provides it. The README does not describe an end-user archiving tool, so for simply opening archives, use an existing application.
Choose Brotli or a comparable project
The README names no direct comparisons in its prose, but the related projects listed for this item include zlib, zstd, LZ4 and gzip. Brotli's stated advantage is denser output than deflate at a similar speed. Benchmarks are linked from the README, including the Squash Compression Benchmark and the Large Text Compression Benchmark, so you can check results for your own data.
What people use it for
- Shrinking web payloads compared with deflate, in tools that need a standardized format
- Building a tool that needs an MIT-licensed, RFC 7932 compression format
- Calling Brotli from Python code after installing the pip module
- Embedding compression in a C program by building the library with CMake
Frequently asked questions
How do I install Brotli?
On Debian-based Linux run apt install brotli, on macOS run brew install brotli with Homebrew, and for Python run pip install brotli. The README also describes building from source with CMake.
What are the requirements for Brotli?
The README lists Python for the pip module and CMake for building from source. Other requirements are not described in the source.
Is Brotli free to use?
Brotli is open-sourced under the MIT License, as stated in the README. See the LICENSE file in the repository for the full terms.
Is Brotli better than gzip?
The README says Brotli is similar in speed to deflate but offers denser compression. It does not give a direct gzip comparison, so check the linked benchmarks for your data.
Does Brotli check for corrupted data?
No. The README notes Brotli streams contain no checksums or uncompressed length, and modified raw ranges may not be detected by the decoder. Add your own integrity check if you need one.
What are the alternatives to Brotli?
Comparable projects listed for this item are zlib, zstd, LZ4 and gzip. Pick based on whether you need denser output, speed, or an existing format for your tools.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Brotli suits developers and tool builders who want denser compression than deflate under an MIT licence, and it installs easily with pip, apt or Homebrew. It is a poor fit if you only need to open zip files or if you need built-in checksums, since the stream format has neither. In those cases use an archiving app or a format with integrity metadata.
Install options & downloads