Registry / web-framework / flask-minify

flask-minify

JSON →
library0.50pypypi✓ verified 86d ago

Flask extension that automatically minifies HTML, CSS, JS and Less responses using various minifiers. Current version 0.50, released April 2025. Active development, roughly quarterly releases.

pip install flask-minify
INSTALL
IMPORT
SIG · FLASK-MINIFY
F
flask-minify
web-frameworkpythonv0.50
Install
3.5s avg
Import
501ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.50 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 0.518s · 26MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 3.5s · import 0.484s · 27MB
24MB installed
● package 24MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Minify
from flask_minify import Minify
Main class to initialize the extension.
decorators
from flask_minify import minify_response
from flask_minify.decorators import minify_response
In versions >=0.50, the decorator is imported directly from flask_minify. The old path may still work but is not guaranteed.

Initialize Minify with the Flask app. By default, only HTML is minified if no arguments are passed. Explicitly enable CSS/JS.

from flask import Flask from flask_minify import Minify app = Flask(__name__) Minify(app=app, html=True, css=True, js=True) @app.route('/') def index(): return '<html><body><h1>Hello</h1></body></html>' if __name__ == '__main__': app.run()
Debug
Known issues
breakingIn version 0.49, support for Python 3.7 was dropped and the dash option (--dash) was removed. Upgrade Python to 3.8+.
fix
Use Python >=3.8; remove any usage of the 'dash' parameter.
affects: >=0.49
deprecatedThe `htmlmin` backend is unmaintained; the library switched to a fork in 0.43. Using htmlmin may cause compatibility issues in the future.
fix
Use the default backend or install tdewolff-minify (pip install flask-minify[tdewolff]) for better support.
affects: >=0.43
gotchaIf you install only the base package, minification of CSS/JS may silently fail because cssmin/jsmin are optional dependencies. The extension will still serve the original content without error.
fix
Install with extras: pip install flask-minify[htmlmin] or pip install flask-minify[tdewolff] to ensure minifiers are available.
affects: all
gotchaThe `minify_response` decorator does not work on class-based views (MethodView). It only works on view functions.
fix
Use the global Minify(app=app) initialization for class-based views, or apply the decorator manually inside the method's return.
affects: all
gotchaLess compilation is only triggered if the response has a .less extension. If you serve Less files with a wrong Content-Type, it won't compile.
fix
Ensure your route returns files with .less extension, or override the Content-Type header to text/less.
affects: all
Errors
Common errors & fixes
AttributeError: module 'flask_minify' has no attribute 'Minify'
Old version (pre-0.39) used a different import pattern; or a stale cached .pyc.
fix
Upgrade to latest: pip install --upgrade flask-minify. Also clear __pycache__ if needed.
ImportError: cannot import name 'minify_response' from 'flask_minify'
The decorator was moved to the main module in 0.50. Old imports from flask_minify.decorators break.
fix
Use 'from flask_minify import minify_response' for version >=0.50.
TypeError: Minify() got an unexpected keyword argument 'dash'
The 'dash' parameter was removed in version 0.49.
fix
Remove the 'dash' argument from Minify() call. It is no longer supported.
pip install flask-minify fails with error: legacy-install-failure (or similar)
Missing build dependencies or incompatible Python version (e.g., Python 3.7 before 0.49).
fix
Upgrade Python to >=3.8; install wheel: pip install wheel; then retry.
Upgrade
Version history
0.50latest on PyPI · released Mar 29, 2025
Audit
Dependencies
FlaskrequiredCore dependency, Flask application must be present
cssminoptionalMinify CSS when using default minifiers
jsminoptionalMinify JavaScript when using default minifiers
htmlminoptionalMinify HTML when using htmlmin backend (slower but more thorough)
tdewolff-minifyoptionalAlternative fast minifier backend for HTML, CSS, JS
lesscpyoptionalCompile Less files to CSS
Agent activity
6 hits · last 30 days
node
6
Resources
flask-minify — pip install flask-minify · libregistry