Flask-SQLAlchemy
Add SQLAlchemy support to your Flask application.
Decision gist · record as of 2026-08-14
Yes. Flask-SQLAlchemy is a mature, actively maintained extension (last commit 2026-05-18, 4311 stars) with no known vulnerabilities, low install friction, and a permissive license. It is the standard way to use SQLAlchemy in Flask applications and is worth installing if you are building a Flask web application that needs database persistence.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction with a pure Python wheel distribution.
- Actively maintained as of 2026-05-18 with 4311 repository stars, indicating stable, well-established tooling.
License · maintenance · safety
permissive license (permissive) — Permissive BSD license allows use in commercial and proprietary projects without copyleft obligations.
last release 2023-09-11 (1068 days) · last repo commit 2026-05-18 · 4,311 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 31,412,966 downloads/mo, #787 on PyPI
Alternatives
Verify before relying
pip install Flask-SQLAlchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"
class Base(DeclarativeBase):
pass
db = SQLAlchemy(app, model_class=Base)
class User(db.Model):
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)
with app.app_context():
db.create_all()
db.session.add(User(username="example"))
db.session.commit()- Whether the package supports async/await patterns for database operations
- Performance characteristics when handling large result sets or many concurrent connections
- Migration tooling integration details beyond what the excerpt shows
What it is and what it does
Flask-SQLAlchemy is a Flask extension that bridges Flask applications to SQLAlchemy, the Python SQL toolkit and ORM. It provides a db object that wraps SQLAlchemy functionality with Flask-aware defaults—database URI configuration through app.config, automatic session management tied to Flask's request context, and helper methods for common operations like create_all() and session.execute(). The package aims to reduce boilerplate when using SQLAlchemy in Flask by handling context binding and providing a familiar, Flask-style API.
You define database models as classes inheriting from db.Model, using SQLAlchemy's modern declarative syntax (Mapped types, mapped_column). The extension manages the session lifecycle automatically within Flask's application context, so you can focus on defining schemas and writing queries rather than managing connection pools and session cleanup. It supports current Python versions and works with any SQLAlchemy-compatible database backend.
Use it for
- Building REST APIs with Flask where you need ORM-based data models and automatic session handling per request
- Defining and managing database schemas declaratively in Flask applications without manual session boilerplate
- Prototyping web applications that require SQLite or PostgreSQL backends with minimal database configuration overhead
- Integrating SQLAlchemy queries into Flask route handlers while maintaining clean separation of concerns
- Creating Flask admin interfaces or CRUD applications where ORM models map directly to database tables
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Flask-SQLAlchemy is a mature, actively maintained extension (last commit 2026-05-18, 4311 stars) with no known vulnerabilities, low install friction, and a permissive license. It is the standard way to use SQLAlchemy in Flask applications and is worth installing if you are building a Flask web application that needs database persistence.
Install
flask-sqlalchemy on PyPI
Before you install
Low install friction with a pure Python wheel distribution. Actively maintained as of 2026-05-18 with 4311 repository stars, indicating stable, well-established tooling.
License in practice
Permissive BSD license allows use in commercial and proprietary projects without copyleft obligations.
Quickstart
pip install Flask-SQLAlchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///example.sqlite"
class Base(DeclarativeBase):
pass
db = SQLAlchemy(app, model_class=Base)
class User(db.Model):
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)
with app.app_context():
db.create_all()
db.session.add(User(username="example"))
db.session.commit()
Verify before relying
- Whether the package supports async/await patterns for database operations
- Performance characteristics when handling large result sets or many concurrent connections
- Migration tooling integration details beyond what the excerpt shows
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesflasksqlalchemy |
| Maintenance | Actively maintained 1,068 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 31,412,966 / month, #787 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonTopic :: Internet :: WWW/HTTP :: Dynamic Content |
Evidence: flask_sqlalchemy-3.1.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “flask orm database”
- Flask-SQLAlchemyFlask-SQLAlchemy integrates SQLAlchemy database operations into Flask…
- sqlbagsqlbag provides a collection of SQLAlchemy utilities and helpers for…
- Flask-PyMongoFlask-PyMongo integrates MongoDB database access into Flask…
Give your agent the search over MCP, or paste the wish link into any chat.
More Dynamic Content packages
MarkupSafe provides a text object that escapes special characters so untrusted strings can be safely embedded in HTML and XML without injection attacks.
Jinja2 is a templating engine that renders dynamic content by combining templates with Python-like syntax and data, supporting template inheritance, macros, autoescaping, and sandboxed execution.
Soupsieve is a CSS selector library designed to work with Beautiful Soup 4 to select, match, and filter HTML and XML elements using modern CSS selectors from CSS level 1 through CSS level 4 specifications.
Install it if you use Beautiful Soup for HTML or XML parsing and want modern CSS selector support.
Werkzeug is a WSGI utility library providing request/response objects, URL routing, an interactive debugger, HTTP utilities, and a development server for building web applications.
Flask is a lightweight WSGI web application framework for building web applications in Python, from simple single-page sites to complex multi-route applications.
Mako compiles Python-embedded templates into Python modules for fast rendering, supporting layout inheritance, custom functions, and direct Python expressions within template syntax.
See also Flask-Alembic · sqlalchemy-mixins · sqlbag · pylint-flask-sqlalchemy · Flask-Session · Flask-Migrate · Flask-Admin · SQLAlchemy · Flask-Mail