--- id: starlette-compress version: "1.8.0" license: 0BSD license_treatment: permissive maintenance: active --- # starlette-compress — Compression middleware for Starlette - supporting ZStd, Brotli, and GZip License: permissive · Maintenance: active · Downloads: 1.1M/mo ## What it is and what it does starlette-compress is a middleware layer for Starlette and FastAPI applications that automatically compresses HTTP responses using one of three algorithms: ZStd, Brotli, or GZip. It sits between your application and the client, intercepting responses and reducing their size before transmission. The middleware applies sensible defaults—compressing responses 500 bytes or larger, using compression level 4 for all algorithms—while remaining configurable for different minimum sizes, compression levels, and content types. The package handles both standard request-response flows and streaming scenarios like Server-Sent Events (SSE), where it flushes the compressor after each message to maintain low latency. It works with asyncio and trio backends, supports modern Python versions (3.9 through 3.14), and requires four runtime dependencies: starlette itself, plus brotli, brotlicffi, and zstandard for the respective compression algorithms. Use it for: - Reduce bandwidth on Starlette or FastAPI APIs by automatically compressing JSON, HTML, and text responses - Add ZStd or Brotli compression to applications that only have GZip available in Starlette's built-in middleware - Compress Server-Sent Events (SSE) streams with per-message flushing to maintain real-time delivery - Tune compression levels per algorithm to balance file size reduction against CPU cost for specific workloads - Manage compression for custom content types or opt out of compression for specific response types ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Middleware for Starlette and FastAPI that compresses HTTP responses using ZStd, Brotli, or GZip, with sensible defaults and more algorithm options than Starlette's built-in GZipMiddleware. Yes. The package is actively maintained, has no known vulnerabilities, uses a permissive license, and offers a straightforward drop-in middleware for Starlette/FastAPI with more compression options and better defaults than the built-in alternative. Low install friction and broad Python version support make it a practical choice for any Starlette or FastAPI project needing response compression. ## Install pip install starlette-compress uv add starlette-compress poetry add starlette-compress ## Installing starlette-compress Before you install: Low install friction with four runtime dependencies (brotli, brotlicffi, starlette, zstandard). Actively maintained with a release 27 days ago and recent commits. Supports Python 3.9 through 3.14. License in practice: Licensed under 0BSD (Zero-Clause BSD), a permissive public domain dedication with no restrictions on use, modification, or distribution. Quickstart: pip install starlette-compress from starlette.applications import Starlette from starlette.middleware import Middleware from starlette_compress import CompressMiddleware middleware = [Middleware(CompressMiddleware)] app = Starlette(routes=..., middleware=middleware) Verify before relying: - Performance impact compared to Starlette's built-in GZipMiddleware under typical production loads - Whether all four runtime dependencies (brotli, brotlicffi, starlette, zstandard) are always required or conditionally installed ## Package facts - License: 0BSD (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 1.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags starlette response compression middleware, fastapi gzip brotli zstd compression, http response compression asgi, starlette middleware compression, zstandard brotli gzip middleware, asgi response encoding, web response compression, middleware, compression, asgi [View on SkillFed](https://skillfed.io/packages/starlette-compress) · [View on PyPI](https://pypi.org/project/starlette-compress/)