Add async database access to a FastAPI or Sanic web app using Django-style model definitions.
Define relationships between tables and query them using Python code instead of raw SQL.
Use the built-in migration CLI to update your database schema automatically as your models change.
Migrate a project to an async-compatible ORM without learning a completely new query syntax.
Requires an async Python framework and a running database, each database type needs its own pip install extra for the async driver.
Tortoise ORM is a Python library for working with databases using an async-native API that will feel familiar to anyone who has used Django. An ORM (Object-Relational Mapper) lets you define your database tables as Python classes and write queries using Python code instead of raw SQL, handling the translation between the two behind the scenes. It also helps prevent SQL injection automatically through the way queries are constructed. The key distinction for Tortoise ORM is that it is built on top of asyncio, Python's framework for writing asynchronous code. This makes it a good fit for async web frameworks and applications where multiple database operations can be happening at the same time without one blocking the other. The API is modeled after Django's ORM, so defining models, querying them, and managing relationships follows a similar pattern to what Django developers already know. Supported databases include SQLite, PostgreSQL, MySQL, Microsoft SQL Server, and Oracle. Each database has its own installation option via pip, pulling in the appropriate async driver for that database. The library includes a migration system with a command-line tool. You run commands to detect changes in your model definitions, generate migration files, and apply them to your database schema. This handles the typical workflow of updating your database as your application evolves over time. To get started, you define model classes, initialize Tortoise with a database URL and a reference to your models, and then write async functions that create, query, update, and relate records. Full documentation lives on a separate site. The project is licensed under the Apache License.
← tortoise on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.