sqlalchemy-orm

Configure SQLAlchemy 2.0 ORM models, queries, and Alembic migrations for Python applications.

3|1|Updated Dec 8, 2025
One-click install
npx skills add https://github.com/bobmatnyc/termpilot --skill sqlalchemy-orm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlalchemy-orm
Source: https://github.com/bobmatnyc/termpilot/tree/main/.claude/skills/toolchains-python-data-sqlalchemy
Command: npx skills add https://github.com/bobmatnyc/termpilot --skill sqlalchemy-orm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a complete guide to using SQLAlchemy 2.0 for building Python applications with relational databases, including an ORM, declarative models, and migrations. It helps automate complex data access patterns, reducing boilerplate and ensuring type-safe SQL queries.

Core Features & Use Cases

  • Declarative Models: Define models with Python type hints and clear relationships.
  • Powerful Querying: Use modern SQLAlchemy 2.0 APIs for robust queries.
  • Migrations with Alembic: Manage schema changes safely over time.
  • Use Case: Build a FastAPI/Flask/Django app with complex relationships and migrations.

Quick Start

Install SQLAlchemy, define your models, create an engine and session, and perform queries with modern patterns.

Frequently Asked Questions about sqlalchemy-orm

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

FAQPage Schema
How do I build a Python application with a type-safe ORM and complex database relationships?

SQLAlchemy ORM provides declarative models with Python type hints, relationship mappings for one-to-many and many-to-many associations, and modern 2.0 APIs for robust queries. Define models using Mapped and mapped_column, create sessions, and query with select() for type-safe database interactions across FastAPI, Flask, or Django applications.

What's the best way to manage database schema changes in Python applications?

Alembic-based migrations integrated with SQLAlchemy automate schema changes safely over time. Define your models declaratively, generate migration scripts that track schema evolution, and apply versioned changes to production databases without manual SQL, ensuring consistency across environments.

Can I use SQLAlchemy with async Python frameworks like FastAPI?

Yes, SQLAlchemy 2.0 supports AsyncSession for non-blocking database operations in async Python applications. Use async engines, session factories, and async queries to integrate SQLAlchemy ORM with FastAPI, enabling scalable data models without blocking I/O.

How do I handle connection pooling and optimize database performance in Python?

SQLAlchemy's connection pooling automatically manages database connections, reducing overhead and improving performance. Configure pool size, overflow, and recycling parameters when creating your engine to match your application's concurrency and workload patterns.

Does SQLAlchemy work with complex many-to-many relationships and foreign keys?

SQLAlchemy ORM handles many-to-many relationships through association tables and relationship() mappings with foreign keys. Define bidirectional relationships, cascades, and join conditions declaratively in your models to represent complex relational structures without raw SQL.

Why should I use declarative models instead of writing raw SQL queries?

Declarative models with type hints reduce boilerplate, prevent SQL injection, enable IDE autocomplete, and make schema intent explicit in Python code. SQLAlchemy's ORM translates Python expressions into optimized SQL, ensuring consistency and maintainability across your application.