skillfed

Flask-Compress

Compress responses in your Flask app with gzip, deflate, brotli or zstandard.

flask-compress v1.24 3.9M downloads/30d#2,443 on PyPI129
Permissive license MIT Active released

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

uv

uv add flask-compress

poetry

poetry add flask-compress

Installing 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

Environment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python Modules

Tags

flask response compressiongzip brotli deflate for flaskhttp compression middlewarereduce flask response sizeflask static file compressionzstd compression flaskcontent encoding flask
http-compressionflask-extensionmiddleware

More Python Modules packages