FastAPI-SQLAlchemy
Adds simple SQLAlchemy support to FastAPI
Decision gist · record as of 2026-08-14
Yes, if you are starting a new FastAPI project with SQLAlchemy and are comfortable with a dormant package. The integration is straightforward and low-friction. No, if you require active maintenance, up-to-date compatibility with the latest FastAPI and SQLAlchemy versions, or ongoing support—consider alternatives or manage sessions manually. The lack of updates since 2020 is a significant concern for long-term projects.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.7 or later; session access relies on ContextVar, which is built into Python 3.7+.
- Low friction install with just two runtime dependencies (starlette and SQLAlchemy).
- However, the package is dormant—last release was 2020-09-25 and last commit 2024-04-09—so expect no active maintenance or support for newer FastAPI or SQLAlchemy versions.
License · maintenance · safety
MIT (permissive) — MIT license (permissive) means you can use, modify, and distribute this package freely in both open-source and commercial projects with minimal restrictions.
last release 2020-09-25 (2149 days) · last repo commit 2024-04-09 · 756 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 109,417 downloads/mo, #12,516 on PyPI
Alternatives
Verify before relying
pip install fastapi-sqlalchemy
from fastapi import FastAPI
from fastapi_sqlalchemy import DBSessionMiddleware, db
app = FastAPI()
app.add_middleware(DBSessionMiddleware, db_url="sqlite://")
@app.get("/users")
def get_users():
users = db.session.query(User).all()
return users- Compatibility with FastAPI versions released after 2020-09-25 is unclear given the dormant maintenance status.
- Whether the package works with current SQLAlchemy 2.x API changes is not documented in the fact sheet.
What it is and what it does
FastAPI-SQLAlchemy is a thin integration layer that attaches SQLAlchemy session management to FastAPI applications via middleware. It provides a global `db` object that gives routes automatic access to a request-scoped database session, and also supports out-of-request database access (e.g., in background tasks) by using the same `db` object as a context manager. The package relies on Python 3.7+ ContextVar to isolate sessions per request, ensuring thread-safe and async-safe behavior.
The package is designed for developers who want to use SQLAlchemy's ORM with FastAPI without manually managing session lifecycles in each route. It abstracts away the boilerplate of creating, binding, and cleaning up sessions, letting you focus on query logic. However, because the package entered dormancy after 2020, it may not reflect current best practices or compatibility with recent FastAPI and SQLAlchemy releases.
Use it for
- Add SQLAlchemy ORM support to a new FastAPI REST API without writing custom session management code.
- Query a database from FastAPI route handlers using the global `db.session` object.
- Access the database in background tasks or scheduled jobs using `db()` as a context manager.
- Migrate a Flask-SQLAlchemy application to FastAPI while keeping similar session patterns.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you are starting a new FastAPI project with SQLAlchemy and are comfortable with a dormant package.
The integration is straightforward and low-friction. No, if you require active maintenance, up-to-date compatibility with the latest FastAPI and SQLAlchemy versions, or ongoing support—consider alternatives or manage sessions manually. The lack of updates since 2020 is a significant concern for long-term projects.
Install
fastapi-sqlalchemy on PyPI
Before you install
Low friction install with just two runtime dependencies (starlette and SQLAlchemy). However, the package is dormant—last release was 2020-09-25 and last commit 2024-04-09—so expect no active maintenance or support for newer FastAPI or SQLAlchemy versions.
Requires Python 3.7 or later; session access relies on ContextVar, which is built into Python 3.7+.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in both open-source and commercial projects with minimal restrictions.
Quickstart
pip install fastapi-sqlalchemy
from fastapi import FastAPI
from fastapi_sqlalchemy import DBSessionMiddleware, db
app = FastAPI()
app.add_middleware(DBSessionMiddleware, db_url="sqlite://")
@app.get("/users")
def get_users():
users = db.session.query(User).all()
return users
Verify before relying
- Compatibility with FastAPI versions released after 2020-09-25 is unclear given the dormant maintenance status.
- Whether the package works with current SQLAlchemy 2.x API changes is not documented in the fact sheet.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.7 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesstarletteSQLAlchemy |
| Maintenance | Dormant 2,149 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 109,417 / month, #12,516 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: AsyncIOIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: Implementation :: CPythonTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Internet :: WWW/HTTP :: HTTP ServersTopic :: Software Development :: Libraries :: Python Modules |
Evidence: FastAPI_SQLAlchemy-0.2.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 › “fastapi sqlalchemy integration”
- FastAPI-SQLAlchemyProvides middleware and helpers to integrate SQLAlchemy database…
- fastapi-users-db-sqlalchemyProvides a SQLAlchemy ORM adapter for FastAPI Users, enabling user…
- fastcrudFastCRUD provides async CRUD operations and automatic endpoint…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also fastapi-pagination · fastapi-users-db-sqlalchemy · fastcrud · Flask-SQLAlchemy · fastapi-injectable · fastapi-utilities · fastapi-utils · ormar · databases · fastapi-restful