Skip to content
Package89 repository health

brotli

Python bindings for Google's Brotli compression library, offering fast one-shot and streaming encode/decode APIs.

Library PyPIv1.2.115,126 stars MIT License
pip install brotli
View source

Repository health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
Excellent
  • Development activity100
  • Maintenance72
  • Community84
  • Maturity60
  • Momentum40

Technical analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
Excellent
  • Architecture80
  • Code quality85
  • Innovation80
  • Learning curve90

Brotli (PyPI: brotli) is the official Python binding for Google’s Brotli compression library, packaging the native C encoder and decoder as a CPython extension module. It implements the algorithm described in RFC 7932 — a combination of LZ77-style matching, Huffman coding, and second-order context modeling — delivering compression density competitive with the best general-purpose codecs while decompressing at speeds comparable to zlib.

The package exposes both a simple one-shot API (compress() / decompress()) and streaming Compressor / Decompressor classes for processing data incrementally, making it a drop-in choice for HTTP content-encoding, asset pipelines, and any workload that needs Brotli-compatible output without shelling out to a CLI.

What You Get

  • One-shot compress/decompress - brotli.compress() and brotli.decompress() for simple byte-string round trips.
  • Streaming Compressor/Decompressor classes - process large payloads incrementally without buffering the whole stream in memory.
  • Tunable quality and window size - quality (0-11) and lgwin (10-24) parameters trade compression speed for density.
  • Mode hints for text and fonts - MODE_TEXT and MODE_FONT let the encoder specialize context modeling for known content types.
  • Native C extension performance - core encode/decode logic runs in Brotli’s shared C codebase used by every other language binding.

Common Use Cases

  • HTTP content-encoding - compress response bodies with br encoding for smaller, faster page loads.
  • Static asset pipelines - pre-compress JS/CSS/font bundles at build time for CDNs that serve .br files.
  • WOFF2 font tooling - Brotli’s font mode underlies the WOFF2 web font compression format.
  • General-purpose archival - swap in for gzip/zlib workloads that need a higher compression ratio at similar speed.

Under The Hood

Architecture

The build (setup.py, pyproject.toml with the setuptools backend) compiles python/_brotli.c into a CPython extension that links directly against the shared C codebase in c/enc, c/dec, and c/common — the same encoder/decoder state machine used by every other language binding in this monorepo (Go, Java, C#, JS/WASM). python/brotli.py is a thin wrapper that re-exports the extension’s Compressor, Decompressor, compress(), and decompress() symbols with Python-friendly defaults and docstrings. Native calls release the GIL during heavy compute (Py_BEGIN_ALLOW_THREADS) and use critical sections under Python 3.13’s free-threaded build, so the binding layer stays a thin, well-isolated shim over a single shared core — a change to the core encoder/decoder state would ripple into every language binding, not just Python’s.

Tech Stack

Pure setuptools build (no build-system extras beyond pkgconfig), with the C extension sourced from the top-level c/ directory shared across the whole repo. The package version is parsed directly out of c/common/version.h rather than duplicated in Python metadata. A USE_SYSTEM_BROTLI environment variable plus pkg-config lookup lets downstream packagers link against an OS-provided libbrotli instead of vendoring and rebuilding the C sources, which is how most Linux distro packages produce this wheel.

Code Quality

Tests live under python/tests/ (compress_test.py, decompress_test.py, compressor_test.py, decompressor_test.py) and use pytest, parametrizing round-trip compress/decompress checks across quality levels, window sizes, and a shared text-input corpus (_test_utils.py) — a solid property-style regression suite for a codec. CI (.github/workflows/) runs multi-platform builds, WASM builds, CodeQL static analysis, continuous OSS-Fuzz fuzzing, lint checks, and an OpenSSF Scorecard job, which is unusually thorough for a compression binding. There’s no static type-checking layer on the thin Python wrapper, but the code follows the Google Python Style Guide with YAPF formatting.

API Design The public API is deliberately minimal and mirrors the stdlib zlib/gzip shape: module-level compress()/decompress() for the common one-shot case, and Compressor/Decompressor classes with process()/finish() for streaming. Sensible defaults (quality=11, lgwin=22) mean import brotli; brotli.compress(data) is a complete, correct usage — there’s essentially no boilerplate or configuration required to get started, and developers coming from zlib need almost no ramp-up.

Used by 8 apps in this directory

Every app whose dependencies include brotli, nine to a page.

Go 58%Apache 2.0

Authgear

2,158

Authentication

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

App
Built with
  • Go 58%
  • HTML 20%
  • TypeScript 19%
Updated yesterdayView details
Python 81%Apache 2.0

changedetection.io

35,933

Monitoring

Self-hosted website change detection with AI-powered smart alerts, browser automation, price tracking, and 85+ notification channels.

App
Built with
  • Python 81%
Updated yesterdayView details
Python 66%Apache 2.0

GPT Researcher

30,806

AI Assistants · Productivity

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

App
Built with
  • Python 66%
  • TypeScript 24%
Updated 1 weeks agoView details
TypeScript 71%Other

highlight.io

9,391

Analytics · Developer Tools · Monitoring

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

App
Built with
  • TypeScript 71%
  • Go 16%
Updated 4 weeks agoView details
Python 56%Other

Onyx

33,492

AI Agents · AI Assistants · Knowledge Management

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

App
Built with
  • Python 56%
  • TypeScript 21%
  • JavaScript 14%
Updated todayView details
Python 55%Other

PostHog

40,995

Ab Testing Experimentation · Analytics · Developer Tools

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

App
Built with
  • Python 55%
  • TypeScript 37%
Updated todayView details
Rust 70%AGPL 3.0

RustDesk

130,537

Networking

Open-source, self-hosted remote desktop built in Rust — your data, your infrastructure, no third-party cloud.

App
Built with
  • Rust 70%
  • Dart 22%
Updated todayView details
Python 57%Other

Sentry

45,808

Analytics · Developer Tools · Monitoring

Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.

App
Built with
  • Python 57%
  • TypeScript 42%
Updated todayView details

Join founders building with open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on SubstackJoin 750+ subscribers