fastapi

sqlmodel: Build Python Models for SQL Databases

SQLModel is a Python library built on Pydantic and SQLAlchemy for working with SQL databases through typed Python models. It reduces duplicated schemas and is designed to work with FastAPI while retaining access to both underlying libraries.

ActivePythonMITLibraryDatabaseFastAPI
Stars
18.4k
Forks
892
Stars, last 30 days
+187
Last commit
today
Contributors
100+

Our take

Activeregular commits and releases

Health score

76/100

How it is scored
Activity
70
Community
89
Issues
74
Pull requests
72

+187 stars in the last 30 days

  • Closes issues faster than 81% of the projects we track
  • More contributors than 78% of the projects we track
  • Releases more often than 75% of the projects we track

SQLModel is an actively maintained, MIT-licensed bridge between Pydantic and SQLAlchemy, with recent commits and releases and a broad contributor base that is not concentrated in one person.

Good fit if

  • You use Python and want typed models that work across SQL persistence and Pydantic data validation.
  • Your application uses FastAPI, or you already work with SQLAlchemy and want a more concise model layer.
  • You can target Python 3.10 or newer and value the SQLAlchemy and Pydantic foundations.

Look elsewhere if

  • You need a database abstraction that does not rely on SQLAlchemy and Pydantic.
  • Your project must support Python versions older than 3.10.
  • You need a solution outside Python for defining and querying relational data.
All health signals
Last commit2026-10-15 (today)
Commits, last 90 days85
Releases, last 12 months21 (latest 0.0.48, 2026-10-06)
Contributors100+ (top contributor: 28% of commits)
Issues closed, last 90 days3 (typically closed in 0 days)
Pull requests merged, last 90 days47 (typically merged in 0 days)
Project age5 years

Checked on 2026-10-16 with the GitHub API.

Project history

Daily GitHub snapshots since Oct 7, 2026. History covers stars and forks; health signals are not tracked historically.

Selected snapshot

Stars

18,659

Forks

900

Change since Nov 23, 2026: +6 stars·-1 forks

Overview

SQLModel is a Python library built on Pydantic and SQLAlchemy, created by the FastAPI author to make working with SQL databases from Python code simpler. It lets a typed model serve as both a SQLAlchemy table model and a Pydantic data model, reducing duplicated definitions and fitting naturally into FastAPI applications.

The project targets developers who want Python classes and type annotations to represent database tables and rows, without giving up the capabilities of SQLAlchemy or Pydantic. Its examples use SQLite, and the README describes compatibility with SQL databases generally.

Key Features

  • Define database table models with Python type annotations and SQLModel classes.
  • Use a model as both a SQLAlchemy model and a Pydantic model.
  • Create, save, and query database records through SQLModel's session and query APIs.
  • Reuse model inheritance to reduce duplication between data and database models.
  • Get editor completion and inline type feedback for models and query results.
  • Use SQLAlchemy underneath for extensibility and compatibility with existing SQLAlchemy models.
  • Integrate with FastAPI applications and Pydantic-based data handling.

Use Cases

  • FastAPI developers building an application that needs typed SQL-backed data models.
  • Python teams replacing separate Pydantic and SQLAlchemy definitions with a shared model where their needs align.
  • Developers prototyping database-backed applications with SQLite and a concise model-and-session workflow.
  • Existing SQLAlchemy projects that want to introduce SQLModel models while continuing to use SQLAlchemy capabilities.

What you need

Detected in the repository

  • Python >=3.10 (from pyproject.toml)
  • A Compose file to run it with its related services
  • A test suite and automated checks on GitHub Actions

License in plain words

MITpermissive

  • Commercial use: yes
  • Modify and redistribute: yes
  • You must keep: the copyright and license notice
  • Share your changes: no

A summary, not legal advice: the LICENSE file is what applies.

Getting Started

Install with uv add sqlmodel. For pip installation and the tutorial, see the SQLModel documentation.

Alternatives

  • dataset: dataset offers a simpler, JSON-like interface for SQL data access, while SQLModel defines typed models using Pydantic and SQLAlchemy.
ProjectLanguageLicenseStarsStatus
sqlmodelPythonMIT18.4kActive
datasetPythonMIT4.9kQuiet

Considerations

SQLModel depends on Pydantic and SQLAlchemy, so adopting it also means working within their model and database ecosystems. It requires Python 3.10 or newer. Its concise shared-model approach can reduce duplication, but teams should check that using the same model for database tables and data validation suits their application's boundaries. The project is MIT licensed; review the license terms for your distribution and use.

Repository: fastapi/sqlmodel · Documentation

Found this useful?

Share it with someone who would like sqlmodel.

Comparisons