API Reference

Tortoise ORM

An asyncio ORM for Python inspired by Django, with typed models and a query API.

Official Documentation ↗
CompatibilityThis documentation covers version v1.1.9. Check the official docs for the latest API surface.

Installation

pippip install tortoise-orm

Methods

Tortoise ORM maps models to tables and provides async CRUD and relations.

Key Features

  • Awaitable CRUD operations
  • Relations and prefetching
  • Built-in migrations via Aerich

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security

Official security statements captured from the package documentation:

  • 参数化查询有助于防止 SQL 注入 — “- Helps prevent SQL injection by using parameterized queries.” (source: https://tortoise.github.io/index.html, fetched 2026-11-08T09:53:13.312Z)

API reference evidence

Fetched from official sources on 2026-11-08T09:53:13.312Z via WebFetch https://tortoise.github.io/query.html.

FAQ

What happens if I forget to close connections?
Connections stay open and can exhaust the pool. Call await Tortoise.close_connections() on shutdown.
How are relations loaded?
Use prefetch_related or select_related in the query to avoid extra round trips; lazy access triggers additional queries.
How do I manage schema changes?
Use Aerich, the companion migration tool, to generate and apply migrations from model changes.