python-database-guidelines

Implements SQLAlchemy 2.0 ORM models and Alembic migrations for Python projects.

Updated Dec 13, 2025
One-click install
npx skills add https://github.com/imehr/vet --skill python-database-guidelines
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-database-guidelines
Source: https://github.com/imehr/vet/tree/main/.claude/skills/python-database-guidelines
Command: npx skills add https://github.com/imehr/vet --skill python-database-guidelines

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides structured patterns and best practices for building Python data access layers using SQLAlchemy ORM, async sessions, and Alembic migrations. It helps teams implement clean architecture in Python projects and reduces boilerplate by offering reusable templates and examples.

Core Features & Use Cases

  • Model Definition: Declarative ORM models with base classes and timestamp mixins to ensure consistency and auditability.
  • Async Session Setup & Transactions: Async engines, session factories, and safe commit/rollback patterns for high-concurrency apps.
  • Repository Pattern: Centralized CRUD operations and query helpers to decouple business logic from data access.
  • Complex Queries & Migrations: Examples of joins, eager loading, aggregations, and migration workflows with Alembic.
  • Use Case: Rapidly scaffold a Python service with a maintainable data layer aligned to Clean Architecture.

Quick Start

    1. Install dependencies: pip install SQLAlchemy alembic
    1. Define a Base model and a sample User model with a timestamp mixin
    1. Initialize Alembic and create migrations: alembic init alembic; alembic revision --autogenerate -m "init"; alembic upgrade head

Frequently Asked Questions about python-database-guidelines

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

FAQPage Schema
How do I set up async SQLAlchemy sessions and transactions in Python?

The repository pattern decouples business logic from data access by centralizing CRUD operations and query helpers, ensuring your Python backend service maintains a clean architecture with a scalable data layer.

How do I run Alembic migrations for SQLAlchemy 2.0 models?

Running Alembic migrations requires initializing the environment, generating revision scripts with autogenerate, and applying upgrades to align your SQLAlchemy 2.0 database schema with declarative ORM model definitions.

What is the best way to structure complex queries with SQLAlchemy ORM?

The best way to structure complex SQLAlchemy ORM queries is by using joins, eager loading, and aggregations within a repository pattern, which centralizes data access and reduces boilerplate in data-intensive applications.

Does this repository pattern approach work with high-concurrency Python backend services?

Yes, the repository pattern works with high-concurrency Python backend services by leveraging async session management and safe transaction patterns to prevent bottlenecks in data-intensive applications requiring scalable data layers.