Overview

Flask 2.1, released on March 29, 2022, speeds up JSON serialization and improves type annotations across the framework.

Main Features

Faster JSON

Flask 2.1 uses the standard JSON module more efficiently and supports alternative serializers like orjson for better performance.

python
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/api/data')
def get_data():
    return jsonify({
        'users': [
            {'name': 'Alice', 'age': 30},
            {'name': 'Bob', 'age': 25},
        ]
    })

Improved type annotations

View return types and decorators are better annotated, making integration with mypy and modern IDEs easier.

python
from flask import Flask, Response

app = Flask(__name__)

@app.route('/')
def index() -> str:
    return '<h1>Home</h1>'

@app.route('/json')
def api() -> dict:
    return {'status': 'ok'}  # automatically jsonified

@app.route('/custom')
def custom() -> Response:
    return Response('Data', content_type='text/plain')

Sources