skillfed

brotli-asgi

A compression AGSI middleware using brotli

brotli-asgi v1.6.0 678.0K downloads/30d#5,378 on PyPI86
Permissive license MIT AGING released

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-asgi

uv

uv add brotli-asgi

poetry

poetry add brotli-asgi

Installing 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

Environment :: Web EnvironmentOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

brotli compression middleware asgiresponse compression middlewarebrotli gzip alternativeasgi compression middlewarehttp response compressionbrotli encoding asgiweb compression middleware
compressionmiddlewareperformance

More WWW/HTTP packages