sqlmodel

Define SQLModel table and data models with migrations and session management.

11|2|Updated Feb 18, 2026
One-click install
npx skills add https://github.com/the-perfect-developer/the-perfect-opencode --skill sqlmodel-the-perfect-developer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlmodel
Source: https://github.com/the-perfect-developer/the-perfect-opencode/tree/main/.opencode/skills/sqlmodel
Command: npx skills add https://github.com/the-perfect-developer/the-perfect-opencode --skill sqlmodel-the-perfect-developer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

SQLModel unifies the definition of database schemas and API data models in Python, enabling you to represent tables and data structures using a single class hierarchy and leverage SQLAlchemy, Pydantic, and FastAPI together.

Core Features & Use Cases

  • Unified models: define both table models (with table=True) and data models in a single, coherent hierarchy.
  • Relationships and queries: implement one-to-many and many-to-many relationships with minimal boilerplate and perform common queries via SQLModel.
  • FastAPI integration: create typed API schemas and route handlers with minimal wiring for rapid API development.
  • Session management: manage per-request sessions and engine lifecycle to ensure safe and scalable data access.

Quick Start

Define a simple data model using SQLModel and expose CRUD endpoints in FastAPI to see models in action.

Frequently Asked Questions about sqlmodel

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

FAQPage Schema
How do I unify FastAPI request schemas and SQLAlchemy database models?

To unify FastAPI request schemas and SQLAlchemy database models, define SQLModel table and data models within a single class hierarchy using table=True, eliminating duplicate code by leveraging Pydantic and SQLAlchemy together.

How do I manage per-request database sessions in FastAPI with SQLModel?

Manage per-request sessions in FastAPI with SQLModel by handling the engine lifecycle and yielding a session per route request, ensuring safe and scalable data access while preventing session leaks.

How do I define one-to-many and many-to-many relationships in SQLModel?

Define one-to-many and many-to-many relationships in SQLModel using minimal boilerplate linkage classes, allowing you to perform common queries and join tables directly within your typed Python data models.

Does SQLModel replace SQLAlchemy and Pydantic for Python API development?

SQLModel does not replace SQLAlchemy and Pydantic but combines them, enabling you to create typed API schemas and relational database structures using one coherent class hierarchy for rapid FastAPI development.

What is the best way to initialize a database and handle migrations with SQLModel?

Initialize databases and handle migrations with SQLModel by defining your table models and generating initialization scripts, satisfying requirements for relational model definitions and proper database setup in Python apps.

When should I use unified data models instead of separate schemas and tables in FastAPI?

Use unified data models instead of separate schemas and tables in FastAPI when you need to rapidly develop typed APIs with minimal wiring, reducing boilerplate by representing both API structures and relational tables in one hierarchy.