--- id: starlette-cramjam version: "0.7.0" 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) license_treatment: permissive maintenance: active --- # starlette-cramjam — Cramjam integration for Starlette ASGI framework. License: permissive · Maintenance: active · Downloads: 212.8K/mo ## 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 above — 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 pip install starlette-cramjam uv add starlette-cramjam 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_current - Install friction: low - Maintenance: active - Downloads: 212.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags starlette compression middleware, brotli gzip deflate zstd compression, asgi response compression, http content encoding middleware, starlette middleware compression, asgi-middleware, compression [View on SkillFed](https://skillfed.io/packages/starlette-cramjam) · [View on PyPI](https://pypi.org/project/starlette-cramjam/)