{"id":23180,"library":"types-flask-sqlalchemy","title":"Flask-SQLAlchemy type stubs","description":"Third-party type stubs for Flask-SQLAlchemy, provided by the typeshed project. Version 2.5.9.4 corresponds to stubs for Flask-SQLAlchemy 2.5.x. These stubs are installed to enable type checking (e.g., with mypy or Pyright) for Flask-SQLAlchemy usage. Release cadence follows upstream typeshed updates.","status":"active","version":"2.5.9.4","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["type-stubs","flask-sqlalchemy","mypy","typing"],"install":[{"cmd":"pip install types-flask-sqlalchemy","lang":"bash","label":"Install stubs"}],"dependencies":[{"reason":"Required runtime dependency; stubs are only useful when the actual package is installed.","package":"Flask-SQLAlchemy","optional":false},{"reason":"Flask-SQLAlchemy depends on Flask; stubs also expect Flask types (e.g., from types-Flask).","package":"Flask","optional":true}],"imports":[{"note":"","wrong":"","symbol":"SQLAlchemy","correct":"from flask_sqlalchemy import SQLAlchemy"},{"note":"Standard pattern; no alternative import path.","wrong":"","symbol":"db (SQLAlchemy instance)","correct":"from flask_sqlalchemy import SQLAlchemy\ndb = SQLAlchemy()"},{"note":"Base model class; can be subclassed.","wrong":"","symbol":"Model","correct":"from flask_sqlalchemy import Model"}],"quickstart":{"code":"from flask import Flask\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\napp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False\n\ndb = SQLAlchemy(app)\n\nclass User(db.Model):\n    id = db.Column(db.Integer, primary_key=True)\n    username = db.Column(db.String(80), unique=True)\n\nwith app.app_context():\n    db.create_all()\n    db.session.add(User(username='example'))\n    db.session.commit()\n    print(User.query.first().username)","lang":"python","description":"Minimal Flask-SQLAlchemy app with type stubs enabling type checking."},"warnings":[{"fix":"Run: pip install Flask-SQLAlchemy types-Flask","message":"Ensure both Flask-SQLAlchemy and types-Flask (or stubs for Flask) are installed. Missing stub dependencies will cause mypy to report 'library stubs not found' errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Use annotation: from typing import List; users: List['User'] = db.relationship('User')","message":"The 'db.relationship()' return type may not be fully stubbed. Use 'Mapped' or explicit type hints for complex relationships.","severity":"gotcha","affected_versions":"2.5.9.x"},{"fix":"Suppress with '# type: ignore[no-untyped-call]' or upgrade to Flask-SQLAlchemy 3.x and use SQLAlchemy 2.0 style.","message":"Mypy may raise 'Missing type hints' for methods like 'query.filter_by()' due to incomplete stubs. This is a known limitation.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"pip install Flask-SQLAlchemy","cause":"Flask-SQLAlchemy runtime package is not installed.","error":"Cannot find implementation or library stub for module 'flask_sqlalchemy'"},{"fix":"pip install types-flask-sqlalchemy","cause":"types-flask-sqlalchemy is missing or outdated.","error":"Library stubs not installed for 'flask_sqlalchemy' (or incompatible with Python 3.x)"},{"fix":"Use 'db.Column(...)' where 'db' is your SQLAlchemy instance, not 'SQLAlchemy.Column'.","cause":"Stubs do not expose SQLAlchemy's top-level attributes; they should be accessed via 'db.Column'.","error":"error: 'SQLAlchemy' has no attribute 'Column'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}