--- id: sqlmodel version: "0.0.39" license: MIT license_treatment: permissive maintenance: active --- # sqlmodel — SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness. License: permissive · Maintenance: active · Downloads: 21.0M/mo ## 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 above — 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 pip install sqlmodel uv add sqlmodel 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_current - Install friction: low - Maintenance: active - Downloads: 21.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags SQL ORM with pydantic validation, SQLAlchemy pydantic integration, typed SQL models python, database models with type hints, fastapi database orm, reduce orm model duplication, python sql table classes, orm, fastapi-integration, type-safe-sql [View on SkillFed](https://skillfed.io/packages/sqlmodel) · [View on PyPI](https://pypi.org/project/sqlmodel/)