A lightweight library that provides simple SQLAlchemy integration and session management for FastAPI applications.
FastAPI-SQLAlchemy is a Python library that simplifies integrating SQLAlchemy ORM with FastAPI web applications. It provides session management middleware, context managers for database access, and utility base classes to reduce boilerplate code when working with databases in FastAPI projects.
FastAPI developers who need a clean, simple way to integrate SQLAlchemy for database operations without writing repetitive session management code.
It offers a Flask-SQLAlchemy-like experience for FastAPI, with automatic session handling, support for multiple databases, and utilities that work both inside and outside request contexts, saving development time.
Adds simple SQLAlchemy support to FastAPI
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The DBSessionMiddleware automatically handles database session creation and cleanup within FastAPI request contexts, as shown in route examples, eliminating repetitive session boilerplate.
Provides a context manager (with db():) for database access outside requests, enabling easy integration with scheduled jobs, demonstrated in the APScheduler example for tasks like user counting.
Includes an extensible ModelBase with built-in methods like save, update, and query helpers, streamlining common CRUD operations without extra code, as shown in the custom BaseModel example.
Allows configuration of multiple database connections simultaneously, facilitating complex applications with separate data sources, referenced in the multi-db example directory.
The library abstracts direct SQLAlchemy session handling, which can obscure advanced features and make custom transaction management or complex queries more cumbersome to implement.
Configuring multiple databases requires careful setup and management, as indicated in the examples, adding overhead for simpler projects that only need a single connection.
While FastAPI is async, the integration primarily uses synchronous SQLAlchemy operations, potentially not leveraging full async performance benefits without additional async driver adjustments.