Flask-Compress
Compress responses in your Flask app with gzip, deflate, brotli or zstandard.
What it is and what it does
Flask-Compress is a Flask extension that automatically compresses HTTP responses using the client's preferred algorithm (gzip, deflate, brotli, or zstd). It inspects the Accept-Encoding request header, respects quality factors, and attaches the appropriate Content-Encoding headers while compressing response data. The extension works transparently—once initialized with a Flask app, it compresses eligible MIME types (HTML, CSS, JavaScript, JSON, SVG, fonts, and others) on every request without requiring changes to route handlers.
The package supports both global compression and per-view compression via decorators, works with streaming responses, handles ETags for conditional requests, and can integrate with caching layers to serve pre-compressed responses. It's designed as a fallback when a reverse proxy like Nginx cannot handle compression for you, though the documentation notes that server-side compression is the preferred approach.
Use it for:
- Compress all HTML, CSS, and JavaScript responses in a Flask app to reduce bandwidth without a reverse proxy.
- Selectively compress specific views using the @compress.compressed() decorator while leaving others uncompressed.
- Serve pre-compressed responses from a cache to reduce CPU load on repeated requests.
- Support modern compression algorithms (brotli, zstd) alongside gzip for clients that request them.
- Reduce payload size for static files served by Flask when Nginx or similar is not available.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Flask-Compress automatically compresses Flask application responses using gzip, deflate, brotli, or zstd based on client capabilities, reducing bandwidth and improving load times.
Yes, if you need HTTP compression in Flask and cannot use a reverse proxy. The package is actively maintained, has low install friction, carries no security vulnerabilities, and uses a permissive MIT license. It supports current Python versions (3.9–3.14) and is straightforward to integrate. Install it when bandwidth reduction or response time matters and you lack infrastructure-level compression.
Install
flask-compress on PyPI
pip
pip install flask-compressuv
uv add flask-compresspoetry
poetry add flask-compressInstalling Flask-Compress
Before you install
Low friction install with a pure-Python wheel. Maintenance is active—last commit 2026-08-04, repository not archived. Supports Python 3.9 through 3.14 and PyPy.
License in practice
MIT license (permissive). No restrictions on commercial or private use; attribution required but no copyleft obligations.
Quickstart
from flask import Flask
from flask_compress import Compress
app = Flask(__name__)
Compress(app)
# Or with deferred initialization:
compress = Compress()
compress.init_app(app)
Requires Python 3.9 or newer. brotli and brotlicffi are optional runtime dependencies for Brotli compression; backports.zstd is optional for ZStandard compression.
Verify before relying
- Performance impact of compression on CPU vs. bandwidth savings for typical workloads.
- Compatibility with async Flask applications or ASGI servers.
- Whether brotli and zstd are optional or required for the package to function.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — flask, brotli, brotlicffi, backports.zstd |
| Maintenance | actively maintained — 136 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,937,241/month — #2,443 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: flask_compress-1.24-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
cartCaRT is a file format and Python library for…
permissive · top 15,000 on PyPI
gzip-streamWraps streams to compress data on-the-fly using…
permissive · top 15,000 on PyPI
starlette-cramjamMiddleware for Starlette that compresses HTTP…
permissive · top 15,000 on PyPI
starlette-compressMiddleware for Starlette and FastAPI that…
permissive · top 5,000 on PyPI
brotli-asgiBrotliMiddleware adds Brotli compression to…
permissive · top 15,000 on PyPI
whitenoiseWhiteNoise serves static files directly from a…
permissive · top 5,000 on PyPI
pgzippgzip is a multi-threaded gzip implementation…
permissive · top 15,000 on PyPI
brotlipybrotlipy provides Python bindings to the Brotli…
permissive · top 5,000 on PyPI
inflate64Provides Deflater and Inflater classes to…
copyleft · top 5,000 on PyPI
lzstringCompresses and decompresses text using the…
permissive · top 15,000 on PyPI