Flask Type Stubs
types-flask is a PEP 561 type stub package providing static type information for the Flask web framework. It allows type-checking tools like MyPy, PyCharm, and Pyright to analyze code that uses Flask, catching potential type-related errors before runtime. The current version is 1.1.6. It is part of the `typeshed` project, which generally releases updates as needed to align with changes in the runtime libraries it provides stubs for, although its primary function for Flask versions 2.0 and newer has been superseded by Flask's native type annotations.
Warnings
- breaking For Flask versions 2.0 and above, the `flask` package itself includes type annotations. Installing `types-flask` alongside Flask 2.0+ can lead to conflicts or redundant type information.
- gotcha `types-flask` is a stub package and does not add any new runtime functionality or modules. All imports should still target the original `flask` library.
- gotcha The versioning of `types-flask` is tied to the `typeshed` project and may not directly correspond to specific `flask` package versions. Ensure compatibility by checking `typeshed`'s `Flask` stub history if encountering type-checking issues with specific `flask` versions prior to 2.0.
Install
-
pip install types-flask
Imports
- Flask
from flask import Flask
Quickstart
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world() -> str:
return 'Hello, World!'
# To run (if Flask < 2.0 and types-flask is needed):
# FLASK_APP=app.py FLASK_ENV=development mypy app.py
# FLASK_APP=app.py flask run