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.
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
muslpy 3.10–3.975 runs
installs and imports cleanly · install 0.0s · import 0.482s · 22.9MB
glibcpy 3.10–3.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
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.
fixUse '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.
fixDowngrade 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.
fixImport '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.
fixEnsure 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.
fixUse Python's built-in 'json' module instead: 'import json'.
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].