Typing Stubs for Flask-Cors
Typing stubs for the Flask-Cors library, enabling static type checking for Flask applications that implement Cross-Origin Resource Sharing. This package is part of the typeshed project, a central repository for type annotations, and provides accurate annotations for `Flask-Cors==6.0.*`. Typeshed packages are automatically released to PyPI as needed, often daily.
Warnings
- gotcha This is a stub-only package (`.pyi` files) for static type checking. It does not contain any runtime code and should not be imported from directly. Its sole purpose is to provide type hints for the `Flask-Cors` library to tools like MyPy or Pyright.
- gotcha Stub packages from `typeshed`, like `types-flask-cors`, aim to be compatible with a specific major/minor version range of the runtime library. For example, `types-flask-cors==6.0.0.X` is designed for `Flask-Cors==6.0.*`. Mismatched versions can lead to incorrect or incomplete type checking results.
- breaking While `typeshed` strives for stability, updates to stub packages can introduce changes that cause your code to fail type checking, even if the underlying `Flask-Cors` runtime library has not changed. This is inherent to the nature of refining type definitions and improving type accuracy.
- deprecated If the `Flask-Cors` library itself begins shipping with inline type annotations or its own `py.typed` file in a future version, this `types-flask-cors` stub package will become redundant and may eventually be deprecated or removed from `typeshed`. Installing both could lead to conflicts or degraded type-checking performance.
Install
-
pip install types-flask-cors
Imports
- CORS
from flask_cors import CORS
- cross_origin
from flask_cors import cross_origin
Quickstart
from flask import Flask, jsonify
from flask_cors import CORS
app = Flask(__name__)
# Enable CORS for all routes and origins
CORS(app)
@app.route("/")
def hello_world():
return jsonify({"message": "Hello, cross-origin world!"})
@app.route("/api/data")
def get_data():
return jsonify({"data": "This is cross-origin data."})
if __name__ == "__main__":
# Run the app, access at http://127.0.0.1:5000/
app.run(debug=True, port=5000)