# sqlmodel

> SQL databases in Python, designed for simplicity, compatibility, and robustness

- Type: agent or tool
- Field: Data & Databases
- Repository: https://github.com/fastapi/sqlmodel
- GitHub stars: 18668
- Licence: MIT
- Language: Python
- Last push: 2026-11-16
- Page: https://imutechz.in/agents/sqlmodel

## What it is
SQLModel is a Python library for interacting with SQL databases using Python objects. It is built on Python type annotations and powered by Pydantic and SQLAlchemy, acting as a thin layer over both. It is designed to simplify database code in FastAPI applications and reduce duplication between SQLAlchemy and Pydantic models.

## Features
- Models defined with Python type annotations and a single class
- A single type annotation can serve as both SQLAlchemy and Pydantic model
- Editor autocompletion and inline error support
- Compatible with FastAPI, Pydantic, and SQLAlchemy
- Extensible through the underlying SQLAlchemy and Pydantic power
- Minimizes code duplication across models

## Best for
- Defining SQL tables as Python classes
- Building database-backed FastAPI applications
- Reducing duplicate SQLAlchemy and Pydantic models
- Writing typed, autocompleted database code

## Pros
- Intuitive to write with strong editor support and completion
- Sensible defaults that simplify the code you write
- Designed for compatibility with FastAPI, Pydantic, and SQLAlchemy
- Thin layer that keeps full SQLAlchemy and Pydantic power available

## Cons
- Requires a recent and currently supported version of Python
- Depends on Pydantic and SQLAlchemy, which are installed automatically

## Install
```
uv add sqlmodel
```

## Usage
```
class Hero(SQLModel, table=True):
```

Tags: python, sql, orm, sqlalchemy, pydantic, fastapi, database, type-annotations
