
Sqlalchemy Orm
Implement SQLAlchemy 2.0 models, queries, relationships, Alembic migrations, and async sessions in Python APIs.
Overview
SQLAlchemy ORM is an agent skill most often used in Build (also Ship, Operate) that implements SQLAlchemy 2.0 models, queries, migrations, and async sessions for Python apps.
Install
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill sqlalchemy-ormWhat is this skill?
- SQLAlchemy 2.0 syntax with Mapped types and declarative models
- select() query builder plus one-to-many and many-to-many relationships
- Alembic migrations and AsyncSession patterns
- PostgreSQL, MySQL, and SQLite-oriented guidance
- FastAPI and Flask integration patterns called out in related skills
- SQLAlchemy 2.0 modern syntax with eight listed key features in skill metadata
- Related skills span FastAPI, Flask, pytest, PostgreSQL, and MySQL paths
- when_to_use lists five explicit trigger scenarios
Adoption & trust: 882 installs on skills.sh; 53 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are building a Python API with a relational database but lack consistent SQLAlchemy 2.0 models, migrations, and async session patterns.
Who is it for?
Indie backend devs on Python 3.10+ who want SQLAlchemy 2.0, Alembic, and async DB access in one guided skill.
Skip if: Greenfield projects that only need document/NoSQL stores, or teams that want ORM-free raw SQL only with no migration discipline.
When should I use this skill?
Building Python apps with relational databases; need type-safe ORM, Alembic migrations, AsyncSession, or FastAPI/Flask integration.
What do I get? / Deliverables
Your agent can scaffold declarative models, relationship mappings, Alembic-ready schema changes, and FastAPI/Flask-friendly session usage.
- Declarative SQLAlchemy 2.0 model modules
- Migration-ready schema changes and query examples using select()
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Canonical shelf is Build → backend because ORM modeling and queries are the first heavy touchpoint when wiring a relational data layer. Backend subphase covers declarative models, select() API, pooling, and framework hooks—not ship-time perf tuning alone.
Where it fits
Define user and subscription tables with relationships before exposing FastAPI routes.
Add an Alembic revision for a new nullable column before release.
Tune connection pooling and async session lifecycle under load.
How it compares
ORM-and-migration skill for Python—not a Prisma/TypeScript stack guide or a DBA runbook for production incident response.
Common Questions / FAQ
Who is sqlalchemy-orm for?
Solo Python builders using FastAPI, Flask, or similar stacks who need SQLAlchemy 2.0 ORM, relationships, and Alembic migrations.
When should I use sqlalchemy-orm?
During Build when designing models and queries; again in Ship when adding migrations; in Operate when adjusting schemas or async session behavior.
Is sqlalchemy-orm safe to install?
Review the Security Audits panel on this Prism page; the skill is documentation-style toolchain guidance without mandatory cloud credentials.
SKILL.md
READMESKILL.md - Sqlalchemy Orm
{ "name": "sqlalchemy", "version": "1.0.0", "category": "toolchain", "toolchain": "python", "framework": "sqlalchemy", "tags": [ "orm", "database", "sqlalchemy", "alembic", "migrations", "sql", "postgresql", "mysql", "sqlite", "async", "fastapi", "flask" ], "entry_point_tokens": 80, "full_tokens": 5876, "related_skills": [ "../../frameworks/fastapi", "../../frameworks/flask", "../../testing/pytest", "../../../database/postgresql", "../../../database/mysql" ], "author": "Claude MPM", "license": "MIT", "subcategory": "data", "description": "SQLAlchemy 2.0 ORM with declarative models, relationships, migrations, and async support", "when_to_use": [ "Building Python applications with relational databases", "Need type-safe ORM with powerful query builder", "Working with FastAPI, Flask, or Django", "Managing database schemas with migrations (Alembic)", "Async database operations with AsyncSession" ], "key_features": [ "SQLAlchemy 2.0 modern syntax with Mapped types", "Declarative models with type hints", "Powerful query builder with select() API", "Relationship mapping (one-to-many, many-to-many)", "Alembic migration support", "Async SQLAlchemy with AsyncSession", "Connection pooling and performance optimization", "FastAPI and Flask integration patterns" ], "prerequisites": [ "Python 3.10+", "Basic SQL knowledge", "Understanding of relational databases" ], "installation": "pip install sqlalchemy alembic", "created_at": "2025-11-30", "progressive_loading": { "entry_tokens": 80, "full_tokens": 5000, "has_progressive_structure": true } } --- name: sqlalchemy-orm description: "SQLAlchemy Python SQL toolkit and ORM with powerful query builder, relationship mapping, and database migrations via Alembic" user-invocable: false disable-model-invocation: true progressive_disclosure: entry_point: summary: "SQLAlchemy Python SQL toolkit and ORM with powerful query builder, relationship mapping, and database migrations via Alembic" when_to_use: "When working with sqlalchemy-orm or related functionality." quick_start: "1. Review the core concepts below. 2. Apply patterns to your use case. 3. Follow best practices for implementation." --- # SQLAlchemy ORM Skill --- progressive_disclosure: entry_point: summary: "Python SQL toolkit and ORM with powerful query builder and relationship mapping" when_to_use: - "When building Python applications with databases" - "When needing complex SQL queries with type safety" - "When working with FastAPI/Flask/Django" - "When needing database migrations (Alembic)" quick_start: - "pip install sqlalchemy" - "Define models with declarative base" - "Create engine and session" - "Query with select() and commit()" token_estimate: entry: 70-85 full: 4500-5500 --- ## Core Concepts ### SQLAlchemy 2.0 Modern API SQLAlchemy 2.0 introduced modern patterns with better type hints, improved query syntax, and async support. **Key Changes from 1.x:** - `select()` instead of `Query` - `Mapped[T]` and `mapped_column()` for type hints - Explicit `Session.execute()` for queries - Better async support with `AsyncSession` ### Installation ```bash # Core SQLAlchemy pip install sqlalchemy # With async support pip install sqlalchemy[asyncio] aiosqlite # SQLite pip install sqlalchemy[asyncio] asyncpg # PostgreSQL # With Alembic for migrations pip install alembic # FastAPI integration pip install fastapi sqlalchemy ``` ## Declarative Models (SQLAlchemy 2.0) ### Basic Model Definition ```python from datetime import datetime from typing import Optional from sqlalchemy import String, DateTime, ForeignKey, func from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship # Base class for all models class Base(DeclarativeBase): pass #