SQL databases in Python, designed for simplicity, compatibility, and robustness
open sourceMITfree
SQLModel is a Python library for working with SQL databases through Python objects, defined with type annotations. A single model class is both a SQLAlchemy table and a Pydantic model, so the same class validates data, serializes it and reads and writes rows without duplicating models, with editor completion throughout. It's a thin layer over both libraries, keeping all of their power underneath, and was made by FastAPI's author to simplify SQL databases in FastAPI apps. It installs with uv or pip, and ships an official agent skill for AI coding agents.
Problems it solves
- stop writing the same model twice for my database tables and my FastAPI request schemas
- a typed Python ORM with editor autocompletion
- read and write SQL rows as validated Python objects
Features
- one class is both a SQLAlchemy table and a Pydantic model
- Python type annotations with editor completion
- data validation and serialization through Pydantic
- full SQLAlchemy underneath
- designed for FastAPI
- official agent skill for AI coding agents
Alternatives
The same job
These do what SQLModel does.
- SQLAlchemy The Python SQL toolkit and Object Relational Mapper
- sqlc Compile SQL to type-safe code
