Registry / web-framework / Flask

Flask

JSON →
library3.1.3pypypi✓ verified 51d ago

Lightweight WSGI web framework. Current version is 3.1.3 (Feb 2026). Flask 3.0 (Sep 2023) removed a large set of APIs that had been deprecated since 2.x — before_first_request, FLASK_ENV, JSON config keys, and custom json_encoder/decoder. LLMs still generate these removed patterns.

web-frameworkserialization
pip install Flask
Install & Compatibility
Where this runs
tested against v3.1.3 · 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.975 runs
installs and imports cleanly · install 0.0s · import 0.482s · 22.9MB
glibc
py 3.103.975 runs
installs and imports cleanly · install 2.2s · import 0.439s · 23MB
21MB installed
● package 21MB
Code
Verified usage

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

Flask
from flask import Flask app = Flask(__name__)
from flask import Flask app = Flask(__name__) app.config['FLASK_ENV'] = 'development' # FLASK_ENV removed in 3.0
FLASK_ENV environment variable and app.env property were removed in Flask 3.0. Use FLASK_DEBUG=1 for debug mode instead.
before_first_request
# Use app context or lifespan pattern with app.app_context(): init_db() # Or with app factory + teardown: @app.before_request def check_initialized(): ...
@app.before_first_request def initialize(): init_db() # decorator removed in Flask 3.0
@app.before_first_request and @bp.before_app_first_request removed in 3.0. Use app context at startup or initialize in app factory.

Minimal Flask 3.x app with JSON responses and error handler.

from flask import Flask, jsonify, request app = Flask(__name__) @app.get('/') def index(): return jsonify({'status': 'ok'}) @app.post('/items') def create_item(): data = request.get_json() return jsonify(data), 201 @app.errorhandler(404) def not_found(e): return jsonify({'error': 'not found'}), 404 # Run: flask --app app run --debug
flask --version
Debug
Known issues
breaking@app.before_first_request and @bp.before_app_first_request decorators removed in Flask 3.0. Extremely common in older tutorials and LLM-generated code.
fix
Run initialization code in the app factory, in a CLI command, or using with app.app_context(): at startup. For teardown-based patterns use @app.teardown_appcontext.
affects: >= 3.0
breakingFLASK_ENV environment variable, ENV config key, and app.env property removed in Flask 3.0. Using FLASK_ENV=development no longer enables debug mode.
fix
Use FLASK_DEBUG=1 or flask run --debug for debug mode. Set app.config['TESTING'] = True for test mode.
affects: >= 3.0
breakingJSON config keys removed in Flask 3.0: JSON_AS_ASCII, JSON_SORT_KEYS, JSONIFY_MIMETYPE, JSONIFY_PRETTYPRINT_REGULAR. LLMs still generate these in config blocks.
fix
Use app.json.sort_keys = False, app.json.mimetype = 'application/json', app.json.ensure_ascii = False on the app.json provider instead.
affects: >= 3.0
breakingapp.json_encoder and app.json_decoder class attributes removed in Flask 3.0. Custom JSON serialization using these was a common pattern.
fix
Subclass flask.json.provider.DefaultJSONProvider and assign: app.json_provider_class = MyProvider, then app = Flask(__name__).
affects: >= 3.0
breakingsend_file() parameter names changed in Flask 2.0 and finalised in 3.0: attachment_filename → download_name, cache_timeout → max_age, add_etags → etag. Old names raise TypeError.
fix
Update send_file calls: send_file(path, download_name='file.csv', max_age=3600, etag=True).
affects: >= 2.0
deprecatedflask.Markup imported from flask is deprecated. Markup was moved to MarkupSafe.
fix
from markupsafe import Markup
affects: >= 2.0
gotchaflask run requires the app to be discoverable. By default looks for app.py or wsgi.py with an app variable. Use FLASK_APP env var or --app flag for other module names.
fix
flask --app mymodule:app run  or  export FLASK_APP=mymodule:app
affects: all
gotchaAsync views require Flask[async] (installs asgiref). Defining async def routes without this raises RuntimeError or silently runs synchronously depending on version.
fix
pip install 'Flask[async]' to enable async view support.
affects: >= 2.0
Errors
Common errors & fixes
ImportError: cannot import name 'FlaskForm' from 'flask'
The 'FlaskForm' class is part of the 'flask_wtf' extension, not the core 'flask' module.
fix
Use 'from flask_wtf import FlaskForm' instead of 'from flask import FlaskForm'.
ImportError: cannot import name 'url_quote' from 'werkzeug.urls'
The 'url_quote' function was removed in Werkzeug 3.0.0.
fix
Downgrade Werkzeug to a version before 3.0.0 by adding 'Werkzeug==2.3.7' to your 'requirements.txt' file and reinstalling dependencies.
ImportError: cannot import name 'escape' from 'jinja2'
The 'escape' function was removed from Jinja2 in version 3.1.0.
fix
Import 'escape' from 'markupsafe' instead: 'from markupsafe import escape'.
ImportError: cannot import name 'Flask' from 'flask'
This error often occurs due to a circular import or incorrect project structure.
fix
Ensure that your project structure does not have circular imports and that 'flask' is installed correctly.
ImportError: cannot import name 'json' from 'flask'
The 'json' module was removed from Flask in version 3.0.0.
fix
Use Python's built-in 'json' module instead: 'import json'.
Upgrade
Version history
3.1.3latest on PyPI
Audit
Dependencies
Werkzeug>=3.1requiredWSGI utilities. Required. Version pinned by Flask.
Jinja2>=3.1.2requiredTemplate engine. Required.
asgiref>=3.2optionalRequired for async views. Only installed with Flask[async].
python-dotenvoptionalLoads .env files for flask run. Only installed with Flask[dotenv].
Agent activity
111 hits · last 30 days
node
30
bytedance
5
seranking-bot
4
petalbot
2
ahrefsbot
2
amazonbot
1
Resources