Tortoise ORM

1.1.7 · active · verified Tue Mar 24

Async ORM for Python inspired by Django ORM. Built on asyncio — requires async context. Current version: 1.1.7 (Mar 2026). v1.0 released 2024 — first stable release after years of 0.x. Breaking changes from 0.x: connections.close_all() removed, ConnectionHandler uses per-instance ContextVar storage. FastAPI integration changed from register_tortoise() to RegisterTortoise context manager. Does not work on serverless/Vercel without workarounds.

Warnings

Install

Imports

Quickstart

Tortoise ORM v1.x standalone script with PostgreSQL.

# pip install 'tortoise-orm[asyncpg]'
from tortoise import Tortoise, fields
from tortoise.models import Model
import asyncio

class User(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=50)
    email = fields.CharField(max_length=120, unique=True)

    class Meta:
        table = 'users'

async def main():
    await Tortoise.init(
        db_url='postgres://user:pass@localhost/mydb',
        modules={'models': ['__main__']}
    )
    await Tortoise.generate_schemas()

    # Create
    user = await User.create(name='Alice', email='alice@example.com')

    # Query
    users = await User.filter(name='Alice').all()
    user = await User.get(id=1)
    user = await User.get_or_none(email='alice@example.com')

    await Tortoise.close_connections()

asyncio.run(main())

view raw JSON →