skillfed

starlette-cramjam

Cramjam integration for Starlette ASGI framework.

starlette-cramjam v0.7.0 212.8K downloads/30d#9,449 on PyPI20
Permissive 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) Active released

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

uv

uv add starlette-cramjam

poetry

poetry add starlette-cramjam

Installing 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

Intended Audience :: Information TechnologyIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

starlette compression middlewarebrotli gzip deflate zstd compressionasgi response compressionhttp content encoding middlewarestarlette middleware compression
asgi-middlewarecompression

More WWW/HTTP packages