Skip to main content

Logo

Downloads Tests Coverage

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)
SQUEEZE_VERBOSE_LOGGING False Enable debug output

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
		"SQUEEZE_VERBOSE_LOGGING": True,  # Debug mode
	}
)

Contributing

  1. Report bugs by opening an issue
  2. Submit pull requests with improvements
  3. 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 3.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-squeeze 3.6.0
File Size Uploaded
flask_squeeze-3.6.0.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-squeeze 3.6.0
File Interpreter ABI Platform
flask_squeeze-3.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / flask_squeeze-3.6.0.tar.gz

Download URL flask_squeeze-3.6.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bd4744498a55170202f3bb1fd48e67ef68c81288b429e5b681ace6e0448221a1
BLAKE2b-256 checksum
How to use checksums
ceb70b5555cd65ac4989d849012c59f212cab279a9c7d01873c5d8f9d40248d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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-3.6.0-py3-none-any.whl

Download URL flask_squeeze-3.6.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccb762b64fbbb6e85d800f45ae5d85ccbc46309dc5f1c9d3de926a41c6177563
BLAKE2b-256 checksum
How to use checksums
3432c7e9cc1a0e9704eb74a61615f72705bd3ac02e9147767be9a48e63c270da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","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 history Release notifications | RSS feed

5.0.2

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.0.1

2 release files

3.7.0

2 release files

3.6.1

2 release files

This release

3.6.0 This release

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.4

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.13.0

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

1.9

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page