SQLModel is a Python library for interacting with SQL databases using Python objects. It is built on Python type annotations and powered by Pydantic and SQLAlchemy, acting as a thin layer over both. It is designed to simplify database code in FastAPI applications and reduce duplication between SQLAlchemy and Pydantic models.
Install & use
Install
uv add sqlmodel
Usage
class Hero(SQLModel, table=True):
fastapi/sqlmodel is a third-party open-source project, listed here from public GitHub data. ImuTechz did not write it and has not reviewed or security-audited its code. Read the source and its permissions before you install or run it.
Features
Models defined with Python type annotations and a single class
A single type annotation can serve as both SQLAlchemy and Pydantic model
Editor autocompletion and inline error support
Compatible with FastAPI, Pydantic, and SQLAlchemy
Extensible through the underlying SQLAlchemy and Pydantic power
Minimizes code duplication across models
Best for
Defining SQL tables as Python classes
Building database-backed FastAPI applications
Reducing duplicate SQLAlchemy and Pydantic models
Writing typed, autocompleted database code
Pros
Intuitive to write with strong editor support and completion
Sensible defaults that simplify the code you write
Designed for compatibility with FastAPI, Pydantic, and SQLAlchemy
Thin layer that keeps full SQLAlchemy and Pydantic power available
Cons
Requires a recent and currently supported version of Python
Depends on Pydantic and SQLAlchemy, which are installed automatically
A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python…