{"id":203,"library":"Flask","title":"Flask","description":"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.","status":"active","version":"3.1.3","language":"python","source_language":"en","source_url":"https://flask.palletsprojects.com/en/stable/changes/","tags":["web","wsgi","framework","http","jinja2","werkzeug"],"install":[{"cmd":"pip install Flask","lang":"bash","label":"Core"},{"cmd":"pip install \"Flask[async]\"","lang":"bash","label":"With async view support (adds asgiref)"},{"cmd":"pip install \"Flask[dotenv]\"","lang":"bash","label":"With .env file support (adds python-dotenv)"}],"dependencies":[{"reason":"WSGI utilities. Required. Version pinned by Flask.","package":"Werkzeug>=3.1","optional":false},{"reason":"Template engine. Required.","package":"Jinja2>=3.1.2","optional":false},{"reason":"Required for async views. Only installed with Flask[async].","package":"asgiref>=3.2","optional":true},{"reason":"Loads .env files for flask run. Only installed with Flask[dotenv].","package":"python-dotenv","optional":true}],"imports":[{"note":"FLASK_ENV environment variable and app.env property were removed in Flask 3.0. Use FLASK_DEBUG=1 for debug mode instead.","wrong":"from flask import Flask\napp = Flask(__name__)\napp.config['FLASK_ENV'] = 'development'  # FLASK_ENV removed in 3.0","symbol":"Flask","correct":"from flask import Flask\napp = Flask(__name__)"},{"note":"@app.before_first_request and @bp.before_app_first_request removed in 3.0. Use app context at startup or initialize in app factory.","wrong":"@app.before_first_request\ndef initialize():\n    init_db()  # decorator removed in Flask 3.0","symbol":"before_first_request","correct":"# Use app context or lifespan pattern\nwith app.app_context():\n    init_db()\n\n# Or with app factory + teardown:\n@app.before_request\ndef check_initialized():\n    ..."}],"quickstart":{"code":"from flask import Flask, jsonify, request\n\napp = Flask(__name__)\n\n@app.get('/')\ndef index():\n    return jsonify({'status': 'ok'})\n\n@app.post('/items')\ndef create_item():\n    data = request.get_json()\n    return jsonify(data), 201\n\n@app.errorhandler(404)\ndef not_found(e):\n    return jsonify({'error': 'not found'}), 404\n\n# Run: flask --app app run --debug","lang":"python","description":"Minimal Flask 3.x app with JSON responses and error handler."},"warnings":[{"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.","message":"@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.","severity":"breaking","affected_versions":">= 3.0"},{"fix":"Use FLASK_DEBUG=1 or flask run --debug for debug mode. Set app.config['TESTING'] = True for test mode.","message":"FLASK_ENV environment variable, ENV config key, and app.env property removed in Flask 3.0. Using FLASK_ENV=development no longer enables debug mode.","severity":"breaking","affected_versions":">= 3.0"},{"fix":"Use app.json.sort_keys = False, app.json.mimetype = 'application/json', app.json.ensure_ascii = False on the app.json provider instead.","message":"JSON 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.","severity":"breaking","affected_versions":">= 3.0"},{"fix":"Subclass flask.json.provider.DefaultJSONProvider and assign: app.json_provider_class = MyProvider, then app = Flask(__name__).","message":"app.json_encoder and app.json_decoder class attributes removed in Flask 3.0. Custom JSON serialization using these was a common pattern.","severity":"breaking","affected_versions":">= 3.0"},{"fix":"Update send_file calls: send_file(path, download_name='file.csv', max_age=3600, etag=True).","message":"send_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.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"from markupsafe import Markup","message":"flask.Markup imported from flask is deprecated. Markup was moved to MarkupSafe.","severity":"deprecated","affected_versions":">= 2.0"},{"fix":"flask --app mymodule:app run  or  export FLASK_APP=mymodule:app","message":"flask 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.","severity":"gotcha","affected_versions":"all"},{"fix":"pip install 'Flask[async]' to enable async view support.","message":"Async views require Flask[async] (installs asgiref). Defining async def routes without this raises RuntimeError or silently runs synchronously depending on version.","severity":"gotcha","affected_versions":">= 2.0"}],"env_vars":null,"search_vec":"'2':27 '2023':15 '2026':11 '3.0':13 '3.1.3':9 'api':21 'config':35 'current':6 'custom':38 'deprec':25 'encoder/decoder':40 'env':33 'feb':10 'first':30 'flask':1,12,32 'framework':5,49 'generat':43 'http':50 'jinja2':51 'json':34,39 'key':36 'larg':18 'lightweight':2 'llms':41 'pattern':46 'remov':16,45 'request':31 'sep':14 'set':19 'sinc':26 'still':42 'version':7 'web':4,47 'werkzeug':52 'wsgi':3,48 'x':28","created_at":"2026-03-25T18:30:43.016511+00:00","updated_at":"2026-04-15T19:00:47.244021+00:00","problems":[{"fix":"Use 'from flask_wtf import FlaskForm' instead of 'from flask import FlaskForm'.","cause":"The 'FlaskForm' class is part of the 'flask_wtf' extension, not the core 'flask' module.","error":"ImportError: cannot import name 'FlaskForm' from 'flask'"},{"fix":"Downgrade Werkzeug to a version before 3.0.0 by adding 'Werkzeug==2.3.7' to your 'requirements.txt' file and reinstalling dependencies.","cause":"The 'url_quote' function was removed in Werkzeug 3.0.0.","error":"ImportError: cannot import name 'url_quote' from 'werkzeug.urls'"},{"fix":"Import 'escape' from 'markupsafe' instead: 'from markupsafe import escape'.","cause":"The 'escape' function was removed from Jinja2 in version 3.1.0.","error":"ImportError: cannot import name 'escape' from 'jinja2'"},{"fix":"Ensure that your project structure does not have circular imports and that 'flask' is installed correctly.","cause":"This error often occurs due to a circular import or incorrect project structure.","error":"ImportError: cannot import name 'Flask' from 'flask'"},{"fix":"Use Python's built-in 'json' module instead: 'import json'.","cause":"The 'json' module was removed from Flask in version 3.0.0.","error":"ImportError: cannot import name 'json' from 'flask'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.1.3","cli_name":"flask","cli_version":"Python 3.11.15","type":"library","homepage":"https://flask.palletsprojects.com","github":"https://github.com/pallets/flask","docs":"https://flask.palletsprojects.com/","changelog":"https://flask.palletsprojects.com/page/changes/","pypi":"https://pypi.org/project/Flask/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":"verified"}}