sqlmodel
SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
What it is and what it does
SQLModel is a thin layer bridging SQLAlchemy and Pydantic, letting you write a single Python class that simultaneously acts as a SQL table definition, an ORM model, and a data validator. Instead of maintaining separate SQLAlchemy models and Pydantic schemas, you annotate class attributes with types and Field() declarations, and SQLModel handles both database persistence and request/response validation. It's built for FastAPI applications but works in any Python codebase that needs SQL databases.
The library handles the boilerplate of mapping Python objects to database rows and back, with full editor autocompletion and type checking throughout. You create instances of your model class to represent rows, pass them to a Session for database operations, and query using SQLAlchemy's select() syntax. Because the same class serves dual duty, you avoid duplicating field definitions and validation logic.
Use it for:
- Build FastAPI applications where request/response models and database models are the same class, cutting model definition code in half.
- Migrate existing SQLAlchemy projects to gain Pydantic validation without rewriting your ORM layer.
- Define type-safe database schemas with Python type hints, getting IDE autocompletion for both model creation and query results.
- Reduce boilerplate in data-heavy applications by using one model definition for validation, serialization, and persistence.
- Prototype database-backed services quickly with minimal schema duplication between API contracts and storage.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
SQLModel combines SQLAlchemy and Pydantic to let you define SQL database tables and rows as Python classes with type annotations, eliminating code duplication between ORM models and data validators.
Yes. SQLModel is actively maintained, has no known vulnerabilities, installs with low friction, and solves a real pain point—eliminating duplicate model definitions. It's well-suited for FastAPI projects and SQLAlchemy migrations. The 0.0.39 version number signals beta status, so production use should account for potential API changes, but the library is widely used and stable in practice.
Install
sqlmodel on PyPI
pip
pip install sqlmodeluv
uv add sqlmodelpoetry
poetry add sqlmodelInstalling sqlmodel
Before you install
Low friction install with only three runtime dependencies (SQLAlchemy, pydantic, typing-extensions). Active maintenance with a recent release and 18266 repository stars; supports current Python versions from 3.10 onward.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal restrictions.
Quickstart
pip install sqlmodel
from sqlmodel import Field, Session, SQLModel, create_engine
class Hero(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
age: int | None = None
engine = create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
hero = Hero(name="Example")
session.add(hero)
session.commit()
Requires Python 3.10 or later.
Verify before relying
- Whether async/await support is available for database operations beyond the AsyncIO framework classifier.
- Performance characteristics compared to raw SQLAlchemy or other hybrid ORM solutions.
- Maturity level and backward-compatibility guarantees given the 0.0.39 version number.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — SQLAlchemy, pydantic, typing-extensions |
| Maintenance | actively maintained — 50 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 21,035,871/month — #1,017 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sqlmodel-0.0.39-py3-none-any.whl
Tags
More Internet packages
Botocore provides low-level, data-driven access…
permissive · top 100 on PyPI
aiobotocoreProvides an async client for AWS services using…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
googleapis-common-protosProvides common Protocol Buffer message…
permissive · top 100 on PyPI
ormarAn async ORM for Python that unifies database…
permissive · top 15,000 on PyPI
py-automapperAutomatically maps object fields from one class…
permissive · top 15,000 on PyPI
redis-omRedis OM provides declarative object mapping…
permissive · top 15,000 on PyPI
sqladminGenerates a web-based admin interface for…
permissive · top 5,000 on PyPI
SQLAlchemySQLAlchemy is a Python SQL toolkit and Object…
permissive · top 100 on PyPI
databricks-sqlalchemyProvides a SQLAlchemy 2.0 dialect that bridges…
permissive · top 1,000 on PyPI
prismaPrisma Client Python is a type-safe ORM that…
permissive · top 5,000 on PyPI
sqlacodegenReads an existing database schema and generates…
permissive · top 5,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
PyPikaPyPika is a Python API for building SQL queries…
permissive · top 5,000 on PyPI