Flask-Squeeze is a Flask extension that automatically:
- Minifies responses with JavaScript, CSS, and HTML content
- Compresses all responses with brotli (preferred), gzip, or deflate compression based on browser support
- Protects against the BREACH exploit by adding random padding to compressed responses
- Caches static files so they don't need to be re-compressed, with both in-memory and persistent disk caching options
- Optimizes performance with intelligent compression levels for static vs. dynamic content
- Works out-of-the-box - no changes needed to your existing Flask routes or templates
Files are considered static if the substring "/static/" is in their request path.
Table of Contents
Compatibility
- Works with Python 3.10 to 3.14
Installation
pip install Flask-Squeeze
Quick Start
from flask import Flask
from flask_squeeze import Squeeze
squeeze = Squeeze()
def create_app():
app = Flask(__name__)
# Init Flask-Squeeze
squeeze.init_app(app)
# Init all other extensions
# AFTER Flask-Squeeze
return app
Thats it! The responses of your Flask app will now get minified and compressed, if the browser supports it. To control how Flask-Squeeze behaves, the following options exist:
Basic Options
| Option | Default | Description |
|---|---|---|
SQUEEZE_COMPRESS |
True |
Enable/disable compression |
SQUEEZE_MIN_SIZE |
500 |
Minimum file size (bytes) to compress |
SQUEEZE_CACHE_DIR |
None |
Directory for persistent cache (None = in-memory only) |
Minification Options
| Option | Default | Description |
|---|---|---|
SQUEEZE_MINIFY_CSS |
True |
Enable CSS minification |
SQUEEZE_MINIFY_JS |
True |
Enable JavaScript minification |
SQUEEZE_MINIFY_HTML |
True |
Enable HTML minification |
Compression Levels
| Option | Default | Range | Description |
|---|---|---|---|
SQUEEZE_LEVEL_BROTLI_STATIC |
11 |
0-11 | Brotli level for static files |
SQUEEZE_LEVEL_BROTLI_DYNAMIC |
1 |
0-11 | Brotli level for dynamic content |
SQUEEZE_LEVEL_GZIP_STATIC |
9 |
0-9 | Gzip level for static files |
SQUEEZE_LEVEL_GZIP_DYNAMIC |
1 |
0-9 | Gzip level for dynamic content |
Example Configuration
app.config.update(
{
"SQUEEZE_CACHE_DIR": "./cache/flask_squeeze/", # Enable persistent caching
"SQUEEZE_MIN_SIZE": 1000, # Only compress files > 1KB
}
)
Logging
Flask-Squeeze logs through the standard logging module under the flask_squeeze logger.
It emits DEBUG records explaining why each response was or was not squeezed.
To see them, configure the logger in your app:
import logging
logging.getLogger("flask_squeeze").setLevel(logging.DEBUG)
The records then go to whatever handlers your application has configured,
e.g. via logging.basicConfig().
Contributing
- Report bugs by opening an issue
- Submit pull requests with improvements
- Improve documentation
Development Setup
git clone https://github.com/mkrd/Flask-Squeeze.git
cd Flask-Squeeze
uv sync
just test # Run tests
just run-test-app # Run test app
License
MIT License - see LICENSE file for details.
Metadata
Release files for flask-squeeze 4.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask_squeeze-4.0.1.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_squeeze-4.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / flask_squeeze-4.0.1.tar.gz
| Download URL | flask_squeeze-4.0.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8e08fcbae7bb15ba1928486d7f654a79746719397dfc0bfd0c2a0069a246bf1
|
|
BLAKE2b-256 checksum How to use checksums |
97d70ce8a2bfc3d2bcbf3167e7b4347ee01546df40fcccefa6a41bf825a75425
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / flask_squeeze-4.0.1-py3-none-any.whl
| Download URL | flask_squeeze-4.0.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88f3c5ae077b40412011cb66f1a4a21315537ff535ec3685abfb75d5521f345b
|
|
BLAKE2b-256 checksum How to use checksums |
52f0cf31abc2e2e4e77512c5c34a5711d80d00133f9386e63a51bd7a41739f75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|