fastapi-sqlalchemy

Configure async SQLAlchemy 2.0 with FastAPI for non-blocking database access.

1|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/weorbitant/compound-engineering-feat-python-plugin --skill fastapi-sqlalchemy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-sqlalchemy
Source: https://github.com/weorbitant/compound-engineering-feat-python-plugin/tree/main/skills/fastapi-sqlalchemy
Command: npx skills add https://github.com/weorbitant/compound-engineering-feat-python-plugin --skill fastapi-sqlalchemy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Senior developers often struggle to implement robust, asynchronous data access in FastAPI with SQLAlchemy 2.0 and consistently manage migrations. This skill provides a curated set of patterns and practices to streamline session lifecycles, repository usage, and zero-downtime migrations.

Core Features & Use Cases

  • Async-first data access using create_async_engine and async_sessionmaker for non-blocking I/O.
  • Repository pattern and type-safe queries to keep business logic clean and testable.
  • Alembic-based migrations with best practices for safe, zero-downtime schema changes.
  • Use cases include building reliable FastAPI endpoints that interact with PostgreSQL/SQL databases and migrating schemas in production.

Quick Start

Create a FastAPI app that uses Async SQLAlchemy 2.0, then wire a repository into a route to perform a simple CRUD flow.

Frequently Asked Questions about fastapi-sqlalchemy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage async SQLAlchemy sessions in FastAPI?

Manage async SQLAlchemy sessions in FastAPI by using async_sessionmaker and create_async_engine to handle non-blocking database I/O. This approach enforces proper session lifecycles and type-safe queries, ensuring maintainable data access across typical CRUD workflows.

What is the repository pattern in async FastAPI SQLAlchemy applications?

The repository pattern in async FastAPI SQLAlchemy applications separates data access logic from business logic using type-safe queries and DeclarativeBase. This keeps endpoints clean, testable, and maintainable while handling non-blocking database operations.

How do I wire Alembic migrations for zero-downtime schema changes in FastAPI?

Wire Alembic migrations for zero-downtime schema changes in FastAPI by applying best practices for safe, non-blocking database updates. This ensures reliable schema migrations in production while maintaining async SQLAlchemy session compatibility.

Does SQLAlchemy 2.0 work with FastAPI for async database access?

SQLAlchemy 2.0 works with FastAPI for async database access by leveraging create_async_engine and async_sessionmaker. This integration provides non-blocking I/O, robust session lifecycle management, and scalable data access for PostgreSQL and SQL databases.

What's the best way to structure CRUD endpoints with async SQLAlchemy in FastAPI?

Structure CRUD endpoints with async SQLAlchemy in FastAPI by wiring a repository pattern into routes using async_sessionmaker. This keeps business logic clean and testable while ensuring safe, non-blocking database interactions across typical workflows.