skillfed

sqlmodel

SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.

sqlmodel v0.0.39 21.0M downloads/30d#1,017 on PyPI18,266
Permissive license MIT Active released

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 sqlmodel

uv

uv add sqlmodel

poetry

poetry add sqlmodel

Installing 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

Development Status :: 4 - BetaFramework :: AsyncIOIntended Audience :: DevelopersIntended Audience :: Science/ResearchIntended Audience :: System AdministratorsProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: DatabaseTopic :: Database :: Database Engines/ServersTopic :: InternetTopic :: Internet :: WWW/HTTPTopic :: Internet :: WWW/HTTP :: HTTP ServersTyping :: Typed

Tags

SQL ORM with pydantic validationSQLAlchemy pydantic integrationtyped SQL models pythondatabase models with type hintsfastapi database ormreduce orm model duplicationpython sql table classes
ormfastapi-integrationtype-safe-sql

More Internet packages