brotli-asgi
A compression AGSI middleware using brotli
What it is and what it does
BrotliMiddleware is an ASGI middleware that automatically compresses HTTP responses using Brotli encoding. It integrates directly into Starlette and other ASGI frameworks, intercepting responses and applying compression before they reach the client. The middleware respects Accept-Encoding headers and can fall back to gzip for clients that don't support Brotli.
You configure it by adding it to your application's middleware stack, optionally tuning compression quality (0–11), mode (generic, text, or font), window size, block size, and minimum response size threshold. It skips responses that already have Content-Encoding set to avoid double-encoding, and it's designed as a direct replacement for the GZipMiddleware shipped with Starlette.
Use it for:
- Reduce bandwidth for JSON APIs and web services by compressing responses with Brotli instead of gzip
- Serve static HTML and text content over the web with better compression density than gzip
- Add compression to ASGI applications without writing custom middleware
- Optimize WOFF 2.0 font delivery using Brotli's font-specific compression mode
- Maintain gzip compatibility for older clients while preferring Brotli for modern browsers
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
BrotliMiddleware adds Brotli compression to ASGI applications as a drop-in replacement for GZipMiddleware, offering denser compression with configurable quality and fallback to gzip when needed.
Yes, if you're running an ASGI framework and want better compression than gzip. The package is lightweight, has no security vulnerabilities, and supports Python 3.9–3.14. Maintenance is aging but stable; the last release was 224 days ago and the repository remains active. Install it if bandwidth reduction matters for your workload and your clients support Brotli.
Install
brotli-asgi on PyPI
pip
pip install brotli-asgiuv
uv add brotli-asgipoetry
poetry add brotli-asgiInstalling brotli-asgi
Before you install
Installs cleanly with only two runtime dependencies (starlette and brotli). Maintenance is aging—last release was 224 days ago—but the repository remains active and unarchived with a recent commit on 2026-01-02.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
Quickstart
pip install brotli-asgi
from brotli_asgi import BrotliMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware
app = Starlette(middleware=[Middleware(BrotliMiddleware)])
Verify before relying
- Performance gains over gzip in production workloads with typical response sizes and quality settings
- Browser compatibility breakdown for older clients not supporting Brotli
- CPU overhead during compression relative to gzip at different quality levels
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — starlette, brotli |
| Maintenance | aging — 224 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 678,044/month — #5,378 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: brotli_asgi-1.6.0-py3-none-any.whl
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
starlette-compressMiddleware for Starlette and FastAPI that…
permissive · top 5,000 on PyPI
starlette-cramjamMiddleware for Starlette that compresses HTTP…
permissive · top 15,000 on PyPI
Flask-CompressFlask-Compress automatically compresses Flask…
permissive · top 5,000 on PyPI
brotlipybrotlipy provides Python bindings to the Brotli…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-asgiProvides ASGI middleware for OpenTelemetry that…
permissive · top 1,000 on PyPI
brotlicffiProvides Python CFFI bindings to the Brotli…
permissive · top 5,000 on PyPI
a2wsgiConverts between WSGI and ASGI applications…
permissive · top 5,000 on PyPI
asgi-correlation-idASGI middleware that reads or generates…
permissive · top 5,000 on PyPI
servestaticServeStatic serves static files efficiently…
permissive · top 15,000 on PyPI
opentelemetry-util-httpProvides ASGI and WSGI middleware and HTTP…
permissive · top 1,000 on PyPI