brotli

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

Library
PyPI
v1.2.0
14,856stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity88
Maintenance68
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
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

Go
55%
Apache 2.0

Authgear

Authentication

2,014

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.

View details
88
Repo Health
81
Technical
69
Dependency
Built with
Go55%
HTML25%
TypeScript17%
Updated 4 days ago
Python
79%
Apache 2.0

changedetection.io

Monitoring

33,415

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

View details
92
Repo Health
80
Technical
68
Dependency
Built with
Python79%
Updated today
Python
67%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,203

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.

View details
91
Repo Health
91
Technical
64
Dependency
Built with
Python67%
TypeScript20%
Updated 3 days ago
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,373

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

View details
70
Repo Health
78
Technical
65
Dependency
Built with
TypeScript71%
Go16%
Updated 1 weeks ago
Python
64%
Other

Onyx

AI Assistants · AI Agents · Knowledge Management

31,832

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

View details
92
Repo Health
83
Technical
72
Dependency
Built with
Python64%
TypeScript27%
Updated today
Python
54%
Other

PostHog

Analytics · Monitoring · Developer Tools

39,479

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.

View details
92
Repo Health
80
Technical
66
Dependency
Built with
Python54%
TypeScript36%
Updated today
Rust
68%
AGPL 3.0

RustDesk

Networking

122,141

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

View details
92
Repo Health
84
Technical
71
Dependency
Built with
Rust68%
Dart24%
Updated 2 days ago
Python
58%
Other

Sentry

Security · Developer Tools · Monitoring

44,658

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

View details
95
Repo Health
80
Technical
69
Dependency
Built with
Python58%
TypeScript41%
Updated today

Join founders buildingwith open source

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

Subscribe on Substack
Join 750+ subscribers

Search