DEV.co
Open-Source Databases · fastapi

sqlmodel

SQLModel is a Python library that combines SQLAlchemy and Pydantic to simplify database interactions in FastAPI applications. It lets you define database tables and API models using a single Python class with type annotations, reducing code duplication and improving developer experience.

Source: GitHub — github.com/fastapi/sqlmodel
18.2k
GitHub stars
871
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryfastapi/sqlmodel
Ownerfastapi
Primary languagePython
LicenseMIT — OSI-approved
Stars18.2k
Forks871
Open issues63
Latest release0.0.39 (2026-06-25)
Last updated2026-07-08
Sourcehttps://github.com/fastapi/sqlmodel

What sqlmodel is

SQLModel is a thin wrapper around SQLAlchemy and Pydantic that enables dual-mode class definitions: instances serve as both ORM models for database operations and Pydantic validators for API serialization. It leverages Python type hints to minimize boilerplate while maintaining full compatibility with both underlying libraries.

Quickstart

Get the sqlmodel source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/fastapi/sqlmodel.gitcd sqlmodel# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

FastAPI applications with SQL databases

SQLModel was designed specifically for FastAPI, allowing you to use the same model class for database mapping, request/response validation, and API schema generation. This eliminates the need to maintain separate Pydantic and SQLAlchemy models.

Projects prioritizing minimal code duplication

When you want a single source of truth for your data structures across the ORM, API layer, and validation logic. SQLModel's unified model approach significantly reduces duplicated field definitions.

Rapid prototyping and CRUD APIs

For building straightforward database-backed REST APIs quickly, especially those that closely mirror table structure. SQLModel's sensible defaults and tight FastAPI integration accelerate development cycles.

Implementation considerations

  • Requires Python 3.7+; verify your Python version and that Pydantic and SQLAlchemy dependencies are automatically installed and compatible.
  • SQLModel models inherit from both SQLModel and Pydantic, requiring care with inheritance chains; multiple inheritance can introduce subtle validation or ORM behavior.
  • Version 0.0.39 is relatively early-stage (released June 2026); API stability cannot be assumed—review breaking changes between minor versions before upgrading in production.
  • Editor support (autocompletion, type hints) depends on IDE/LSP setup; misconfigured environments may not surface the promised developer experience benefits.
  • Dual-role classes (ORM + validation) can mask logic; ensure clear testing of both database and API serialization paths.

When to avoid it — and what to weigh

  • Complex multi-table relationships with custom mapping — If your schema requires elaborate join strategies, polymorphic inheritance, or sophisticated SQLAlchemy patterns, SQLModel's abstraction may constrain you. You may need to drop down to raw SQLAlchemy frequently.
  • Project not using FastAPI or Pydantic — SQLModel's design assumes Pydantic and FastAPI ecosystems. In non-FastAPI Python projects or those using different validation frameworks, SQLModel provides less benefit over plain SQLAlchemy.
  • API models that diverge significantly from database schema — If your API contract requires extensive computed fields, nested transformations, or representations that differ from table structure, maintaining a unified SQLModel becomes problematic; you may need separate presentation models anyway.
  • Mature legacy SQLAlchemy codebases — Migrating established SQLAlchemy applications to SQLModel requires careful refactoring. Unless compatibility and simplification gains are clear, gradual adoption may be safer than wholesale replacement.

License & commercial use

SQLModel is licensed under the MIT License, a permissive OSI-approved license. MIT permits commercial use, modification, and distribution with minimal restrictions (attribution and license inclusion required).

MIT license clearly permits commercial use without requiring source disclosure or special agreements. Ensure you include the original MIT license text in distributions. No commercial licensing or proprietary restrictions detected. Recommended to review license text independently for your jurisdiction.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

SQLModel inherits SQLAlchemy's parameterized query protection against SQL injection. Pydantic validation applies to API input, reducing type-confusion attacks. Standard database credential management (environment variables, secrets manager) applies. Audit ORM-generated queries in security-sensitive contexts. No claims of SQLModel-specific security hardening found; rely on underlying library security postures.

Alternatives to consider

SQLAlchemy ORM alone

More mature, decoupled from Pydantic, and supports complex schema patterns. Choose if you don't need unified API/ORM models or prioritize SQLAlchemy's full feature set over simplicity.

Tortoise ORM

Designed for async/await workflows and is often more feature-complete for complex relationships. Consider if you need first-class async support or are not deeply integrated with FastAPI.

Django ORM

Mature, comprehensive, with rich admin and migration tooling. Choose if you're building monolithic applications or prefer Django's conventions over FastAPI's lighter approach.

Software development agency

Build on sqlmodel with DEV.co software developers

SQLModel bridges ORM and API validation in one unified model. Ideal for FastAPI projects that need rapid CRUD development without duplicating model definitions. Assess if your schema and use case align with SQLModel's strengths.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

sqlmodel FAQ

Can I use SQLModel without FastAPI?
Yes, but SQLModel loses much of its advantage. It is still a valid ORM/validation hybrid, but SQLAlchemy alone may be simpler if you don't need Pydantic integration.
Is SQLModel production-ready?
Version 0.0.39 indicates pre-1.0 status. It is used in production (GOVCERT.LU sponsors it), but expect potential breaking changes. Review release notes before upgrading.
How does SQLModel handle async database operations?
SQLModel relies on SQLAlchemy's async features; use `create_async_engine()` and async sessions. Not explicitly showcased in the README, so refer to SQLAlchemy async documentation for details.
Do I need separate models for API requests and database storage?
SQLModel's goal is a unified model, but complex schemas (computed fields, different serialization rules) may still require separate presentation models to avoid tightly coupling API contract to database schema.

Custom software development services

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If sqlmodel is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.

Ready to simplify your database layer?

SQLModel bridges ORM and API validation in one unified model. Ideal for FastAPI projects that need rapid CRUD development without duplicating model definitions. Assess if your schema and use case align with SQLModel's strengths.