For a type-safe ORM for Python, the strongest matches are tortoise/tortoise-orm (Tortoise ORM is an async ORM for Python with), fastapi/sqlmodel (SQLModel is a type-safe Python ORM and query builder) and sqlalchemy/sqlalchemy (SQLAlchemy is the leading Python ORM and query builder). piccolo-orm/piccolo and ormar-orm/ormar round out the shortlist. Each is ranked by relevance to your query, popularity and recent activity.
Discover Python libraries that provide robust type checking and autocompletion for database interactions and queries.
Tortoise ORM is an asynchronous object-relational mapper for Python that mirrors Django's model and queryset API while running on asyncio. It defines database tables as Python classes with typed fields and supports foreign key, many-to-many, and one-to-one relations, providing a chainable query API for filtering, annotating, grouping, and prefetching related objects without blocking the event loop. The ORM includes a built-in migration engine that detects model changes, generates migration files, and applies or reverts schema changes through a command-line tool. It connects to PostgreSQL, MyS
Tortoise ORM is an async ORM for Python with a chainable queryset API (query builder), typed model fields, migration support, and multiple database backends, directly matching the request for a type-safe ORM with query builder; it covers most features but does not explicitly provide raw SQL with type validation.
SQLModel is a type-safe object-relational mapping library for Python that integrates database schema definitions with data validation logic. By combining these two roles into a single class, it allows developers to manage relational data structures and enforce data integrity for web APIs simultaneously. The framework is built to support asynchronous database operations, enabling high-performance applications to execute queries and transactions without blocking the main execution thread. The library distinguishes itself by leveraging Python type hints to provide IDE autocompletion and compile-
SQLModel is a type-safe Python ORM and query builder that uses Pydantic for validation and type hints, supporting async operations, migrations, and multiple databases with full query-building capabilities, making it an excellent fit for this search.
SQLAlchemy is a comprehensive Python SQL toolkit and object-relational mapper that provides a full suite of tools for interacting with relational databases. It serves as a foundational layer for database connectivity, offering both a high-level object-oriented interface for data persistence and a programmatic SQL expression language for constructing complex, dialect-agnostic queries. The project distinguishes itself through its sophisticated unit of work persistence, which coordinates atomic transactions and tracks object state changes to minimize redundant database operations. It provides a
SQLAlchemy is the leading Python ORM and query builder, now with first-class type-hinted schema definitions (Mapped, mapped_column) in version 2.0, async support, comprehensive relationship handling, and broad database coverage — squarely meeting your search for a type-safe ORM and query builder.
Piccolo is an async Python ORM with a built-in type-safe query builder that uses type hints, directly fitting the search's core requirement; it supports async, migrations, relationships, and PostgreSQL/SQLite, though it may not cover MySQL or raw SQL type validation as fully.
Ormar is an asynchronous object-relational mapper for Python that integrates database persistence with data validation. It functions as a bridge between relational database management and application-level data structures, allowing developers to define database schemas that serve simultaneously as validation models. The project distinguishes itself by using validation classes to enforce schema integrity, ensuring that all persisted records conform to defined types and structures. It supports complex relational associations, including one-to-many and many-to-many relationships, and provides ev
ormar is an async Python ORM built on Pydantic for automatic type validation and alignment with FastAPI, covering the core type-safe ORM and query-building needs with migration support via Alembic and async database access.
Kysely is a TypeScript SQL query builder that provides a type-safe interface for constructing and executing database queries. It functions as a database layer that ensures schema compliance and prevents runtime errors by using a fluent interface and a programmable way to build complex SQL statements. The project features a type-safe database layer capable of inferring return types and aliases from SQL selections and joins. It also includes a SQL migration manager to track and apply schema changes across different environments to keep database versions synchronized. The toolkit covers relatio
Kysely is a type-safe SQL query builder and migration tool for TypeScript, not Python, so it does not match the visitor's requirement for a Python library combining ORM and query builder with type hints.
Prisma is a database toolkit that provides a unified access layer for interacting with relational and document databases. It centers on a declarative schema modeling approach, where developers define their data structures in a human-readable language. This schema serves as the single source of truth, from which the toolkit automatically generates type-safe database clients that provide compile-time validation and editor autocomplete for all data operations. The project distinguishes itself through a high-performance, Rust-based query engine that handles query planning and connection pooling o
Prisma is a type-safe ORM and query builder, but it targets TypeScript and JavaScript rather than Python, so it is not the Python library you are looking for despite matching the concept.
Prisma is a type-safe database object-relational mapper that uses a declarative schema to map data models to relational and document databases. It provides a unified toolkit for data access, combining a database driver with tools for schema management and record manipulation. The project features a multi-database driver that standardizes interactions across PostgreSQL, MySQL, and MongoDB. It includes a system for tracking and applying structural schema migrations across different environments and a graphical user interface for browsing and editing database records. The system ensures data in
Prisma is a type-safe ORM and query builder with schema migrations and multi-database support, but it is written in Scala and targets the Node.js/TypeScript ecosystem, not the Python library this search requires.
Gel is an object-relational database system that models data as a graph of interconnected objects. By utilizing a strongly typed schema, it enables complex relational queries and polymorphic data structures without the need for traditional join tables. The system integrates native vector storage and similarity search operators, allowing it to function as both a relational and a vector database for semantic data retrieval. The platform distinguishes itself through a comprehensive suite of developer-centric automation tools. It features a declarative migration system that tracks and versions sc
Gel is a full object-relational database system with its own type-safe query language, not a Python library that provides an ORM and query builder for use with other databases.
SQLite.swift is a type-safe Swift wrapper and object-relational mapping layer that provides a bridge for interacting with SQLite databases. It functions as a database driver that allows for embedded database management and local data persistence within Swift applications. The project distinguishes itself through a type-safe expression builder that verifies SQL statement syntax and intent at compile time. It includes specialized support for high-performance text matching via full-text search integration and provides mechanisms for securing sensitive data through database encryption. The libra
This is a type-safe ORM and query builder for Swift, not for Python, so it does not satisfy the requirement for a Python library even though its design aligns with the type-safe approach.
Pydantic is a data validation and serialization library that enforces schema constraints and performs type conversion on complex data structures. It utilizes standard Python type annotations to define data models, allowing developers to establish structured schemas that automatically enforce business rules and constraints without the need for custom domain-specific languages. The library distinguishes itself by transforming high-level model definitions into optimized code during initialization to minimize runtime overhead. It supports recursive validation for nested data structures and employ
Pydantic provides robust type-hint-based data validation, but it is not an ORM or query builder—it lacks database interaction, query construction, async DB support, and migrations that this search for a combined type-safe ORM and query builder demands.
This project is a full-stack web application scaffolder designed to initialize production-ready projects with pre-configured database, authentication, and deployment settings. It provides a standardized starting point for development by generating a complete application structure that includes integrated backend, frontend, and database components. The template distinguishes itself through a type-safe integration layer that automatically synchronizes backend API definitions with frontend client code, ensuring consistent data exchange. It also features a containerized development environment th
This is a full-stack project scaffold that uses SQLModel under the hood, but it's a TypeScript-based template for bootstrapping applications, not the standalone Python ORM+query-builder library the visitor is looking for.
| Repository | Stars | Language | License | Last push |
|---|---|---|---|---|
| tortoise/tortoise-orm | 5.6K | Python | Apache-2.0 | |
| fastapi/sqlmodel | 18.1K | Python | MIT | |
| sqlalchemy/sqlalchemy | 11.6K | Python | mit | |
| piccolo-orm/piccolo | 1.9K | Python | MIT | |
| ormar-orm/ormar | 1.8K | Python | MIT | |
| kysely-org/kysely | 14K | TypeScript | MIT | |
| prisma/prisma | 46.4K | TypeScript | Apache-2.0 | |
| prismagraphql/prisma | 16.4K | Scala | Apache-2.0 | |
| geldata/gel | 14.1K | Python | apache-2.0 | |
| stephencelis/sqlite.swift | 10.2K | Swift | MIT |