sqlalchemy-patterns

Implement SQLAlchemy 2.0 ORM models, async sessions, and Alembic migrations.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/romankovsv/claude-code-python-devops-mlops --skill sqlalchemy-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlalchemy-patterns
Source: https://github.com/romankovsv/claude-code-python-devops-mlops/tree/main/skills/sqlalchemy-patterns
Command: npx skills add https://github.com/romankovsv/claude-code-python-devops-mlops --skill sqlalchemy-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SQLAlchemy 2.0 patterns provide a cohesive set of best practices for building robust data-access layers, from ORM models to migrations, reducing boilerplate and cognitive load.

Core Features & Use Cases

  • Base models & mixins for common fields and auditing
  • Async and sync sessions with safe session handling and proper commit/rollback
  • Relationships, lazy loading strategies, and query patterns to avoid N+1
  • Alembic migrations workflow integration and repository pattern examples
  • Performance tips and scalable architectural patterns for large applications

Quick Start

Install and apply the SQLAlchemy 2.0 patterns in your project to standardize data access and improve maintainability.

Frequently Asked Questions about sqlalchemy-patterns

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

FAQPage Schema
How do I structure SQLAlchemy 2.0 async sessions for a scalable backend?

Structure SQLAlchemy 2.0 async sessions by using explicit repository patterns that enforce safe session handling, proper commit/rollback boundaries, and cohesive data access across sync and async contexts for scalable backend applications.

What is the best way to avoid N+1 query problems in SQLAlchemy ORM?

Avoid N+1 query problems in SQLAlchemy ORM by applying explicit relationship mappings, configuring lazy loading strategies, and using efficient query patterns to optimize data fetching and improve application performance.

How do I manage Alembic migrations when using SQLAlchemy 2.0 patterns?

Manage Alembic migrations with SQLAlchemy 2.0 by integrating migration workflows directly into your data-access layer, ensuring database schemas stay synchronized with Base models and relationship mappings as your application scales.

Can I use the repository pattern with both sync and async SQLAlchemy sessions?

Yes, the repository pattern supports both sync and async SQLAlchemy sessions by providing clean architecture boundaries that standardize data access, reduce boilerplate, and maintain cohesive query execution across different operational contexts.

When do I need base models and mixins in SQLAlchemy for clean architecture?

Use base models and mixins in SQLAlchemy when building scalable apps that require consistent auditing, shared common fields across ORM models, and reduced boilerplate to maintain a clean data-access architecture.