{"id":2029,"library":"flask-compress","title":"Flask-Compress","description":"Flask-Compress is a Flask extension that allows you to easily compress your Flask application's responses using various algorithms like gzip, deflate, brotli, or zstandard. It helps reduce bandwidth usage and improve page load times. The library is actively maintained, with the current version being 1.24, and it typically sees releases for bug fixes, performance improvements, and feature enhancements.","status":"active","version":"1.24","language":"en","source_language":"en","source_url":"https://github.com/colour-science/flask-compress","tags":["flask","compression","web performance","gzip","brotli","zstandard","deflate"],"install":[{"cmd":"pip install flask-compress","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Core web framework for which this is an extension.","package":"Flask"},{"reason":"Required for Brotli compression.","package":"brotli","optional":true},{"reason":"Required for Zstandard compression.","package":"python-zstandard","optional":true}],"imports":[{"symbol":"Compress","correct":"from flask_compress import Compress"}],"quickstart":{"code":"from flask import Flask, request, jsonify\nfrom flask_compress import Compress\nimport os\n\napp = Flask(__name__)\nCompress(app)\n\n@app.route('/')\ndef hello_world():\n    return 'Hello, Compressed World!'\n\n@app.route('/large-data')\ndef large_data():\n    # Simulate a large JSON response\n    data = {'items': [{'id': i, 'name': f'Item {i}', 'description': 'This is a long description for item'} for i in range(1000)]}\n    return jsonify(data)\n\nif __name__ == '__main__':\n    app.run(debug=True)","lang":"python","description":"This quickstart demonstrates how to initialize Flask-Compress with your Flask application. Once initialized, Flask-Compress automatically compresses responses for specified MIME types, such as HTML or JSON, without further configuration. The `/large-data` endpoint serves a large JSON payload which will be compressed."},"warnings":[{"fix":"For static files, consider configuring your front-end web server (e.g., Nginx, Apache) to pre-compress or dynamically compress them, rather than relying on Flask-Compress.","message":"Enabling streaming compression for static content served directly by Flask might not be ideal. Flask-Compress will compress static content chunk-by-chunk, which can be less efficient than having a web server (like Nginx) handle static file compression.","severity":"gotcha","affected_versions":">=1.21"},{"fix":"To enable ETag for streaming, set `COMPRESS_EVALUATE_CONDITIONAL_REQUEST` to `True` and optionally `COMPRESS_STREAMING_ENDPOINT_CONDITIONAL` for specific endpoints. Evaluate memory usage carefully.","message":"ETag support is disabled by default for streaming responses because it typically requires buffering the entire response in memory to compute the ETag, which can negate the benefits of streaming. If you enable ETag support for streaming endpoints, be aware of the potential memory impact.","severity":"gotcha","affected_versions":">=1.20"},{"fix":"Monitor server CPU usage after enabling compression. Adjust `COMPRESS_LEVEL` (for gzip/deflate) or `COMPRESS_BROTLI_QUALITY` to find an optimal balance between compression ratio and CPU load. If CPU becomes a bottleneck, offload compression to a reverse proxy or CDN.","message":"While compression improves network efficiency, it increases CPU usage on the server. For applications with very high traffic or limited CPU resources, this trade-off should be carefully considered and monitored.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}