sqlmodel: Build Python Models for SQL Databases

sqlmodel: Build Python Models for SQL Databases

Summary

SQLModel combines Pydantic-style data models with SQLAlchemy database mapping in one Python library. It suits FastAPI developers and Python teams who want typed models for validation and database access without maintaining duplicate definitions.

At a glance

Language
Python
License
MIT
Stars
18.4k
Forks
889
Added to OSRepos
December 8, 2025
Last analyzed
October 4, 2026
View on GitHub

Topics

Click on any tag to explore related repositories

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Overview

SQLModel is a Python library for defining SQL database tables and working with database records through typed Python models. It builds on Pydantic and SQLAlchemy, aiming to reduce duplicated model definitions while retaining compatibility with both libraries.

It is especially relevant to FastAPI applications, where the same model can support database persistence and data validation. The project is a thin layer over established libraries, so it can also fit Python applications that use SQLAlchemy without FastAPI.

Key Features

  • Define table models and columns with Python type annotations.
  • Use models that work with both SQLAlchemy and Pydantic.
  • Create database tables and manage records through SQLModel sessions.
  • Build queries with SQLModel's select interface.
  • Retain access to SQLAlchemy and Pydantic capabilities underneath.
  • Use models with FastAPI and benefit from editor completion and inline type feedback.

Use Cases

  • FastAPI developers can use shared models for request data and database tables, reducing duplicated definitions.
  • Python developers starting a small SQL-backed application can define typed models and interact with a database through familiar Python code.
  • Teams with SQLAlchemy applications can consider SQLModel when they want a more concise model layer while keeping SQLAlchemy compatibility.
  • Developers who rely on editor completion and type annotations can use SQLModel to make database model fields clearer in their code.

Project Facts

  • Language: Python
  • License: MIT
  • Stars: 18.4k
  • Forks: 889
  • Topics: fastapi, json, json-schema, pydantic, python, sql, sqlalchemy
  • Archived: No

Getting Started

Install with uv add sqlmodel. See the README and official documentation for setup and usage details.

Considerations

  • Requires a recent, currently supported Python version.
  • Pydantic and SQLAlchemy are required dependencies and are installed with SQLModel.
  • SQLModel builds on Pydantic and SQLAlchemy, so its design and behavior are closely tied to those libraries. Consult their documentation when you need capabilities beyond SQLModel's simplified interface.

Found this useful?

Share it with someone who would like sqlmodel.

Comparisons

Source repository

Open the original repository on GitHub.

15 counted GitHub visits

View on GitHub

Related repositories

Similar repositories that may be relevant next.

OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️