探索为数据库交互和查询提供强大类型检查及自动补全功能的 Python 库。
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.