starlette-cramjam
Cramjam integration for Starlette ASGI framework.
What it is and what it does
starlette-cramjam is a Starlette ASGI middleware that automatically compresses HTTP responses using one or more compression algorithms (Brotli, GZip, Deflate, ZSTD). It inspects the client's Accept-Encoding header and applies the appropriate algorithm, handling both standard and streaming responses transparently. The middleware is built on top of cramjam, which provides Rust-backed compression bindings for performance.
You configure it by specifying which compression algorithms to support, the compression level (0–11), a minimum response size threshold to avoid compressing small payloads, and optional path or media-type exclusions. It integrates directly into Starlette's middleware stack with minimal setup and requires only Python 3.11 or later.
Use it for:
- Reduce bandwidth and improve response times for text-heavy APIs by automatically compressing JSON or HTML responses.
- Support multiple compression standards (Brotli, GZip, Deflate, ZSTD) to accommodate diverse client preferences without manual negotiation.
- Exclude specific routes or media types (e.g., already-compressed images) from compression to avoid overhead.
- Tune compression level per deployment environment to balance CPU cost and bandwidth savings.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Middleware for Starlette that compresses HTTP responses using Brotli, GZip, Deflate, or ZSTD algorithms based on client Accept-Encoding headers.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and solves a common Starlette use case with a clean API. Install it if you need HTTP compression middleware for a Starlette application and want support for multiple algorithms beyond the standard library.
Install
starlette-cramjam on PyPI
pip
pip install starlette-cramjamuv
uv add starlette-cramjampoetry
poetry add starlette-cramjamInstalling starlette-cramjam
Before you install
Low friction: pure Python wheel with only two runtime dependencies (cramjam and starlette). Actively maintained with a recent release and no known vulnerabilities.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal obligations—suitable for both open-source and commercial projects.
Quickstart
pip install starlette-cramjam
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette_cramjam.middleware import CompressionMiddleware
app = Starlette(
middleware=[Middleware(CompressionMiddleware)]
)
Requires Python 3.11 or later.
Package facts
| License | MIT License Copyright (c) 2021 Development Seed Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — cramjam, starlette |
| Maintenance | actively maintained — 109 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 212,832/month — #9,449 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: starlette_cramjam-0.7.0-py3-none-any.whl
Keywords: ASGI, Compression, Cramjam, Starlette
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
brotli-asgiBrotliMiddleware adds Brotli compression to…
permissive · top 15,000 on PyPI
cramjamProvides fast Python bindings to multiple…
permissive · top 1,000 on PyPI
starletteStarlette is a lightweight ASGI framework for…
permissive · top 100 on PyPI
starlette-compressMiddleware for Starlette and FastAPI that…
permissive · top 5,000 on PyPI
Flask-CompressFlask-Compress automatically compresses Flask…
permissive · top 5,000 on PyPI
starsessionsProvides session management middleware for…
permissive · top 15,000 on PyPI
asgi-correlation-idASGI middleware that reads or generates…
permissive · top 5,000 on PyPI
starlette-contextMiddleware for Starlette that stores and…
permissive · top 5,000 on PyPI
starlette-testclientProvides a drop-in replacement for Starlette's…
permissive · top 5,000 on PyPI
opentelemetry-util-httpProvides ASGI and WSGI middleware and HTTP…
permissive · top 1,000 on PyPI