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
pip
pip install tortoise-ormMethods
No methods match this filter.
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.
Model.create→ signature from https://tortoise.github.io/query.html; official text: “-create(**kwargs)- creates an object with given kwargs”Model.filter→ signature from https://tortoise.github.io/query.html; official text: “-filter(*args, **kwargs)- create QuerySet with given filters”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.