r/FastAPI • u/pehibah • Feb 09 '26
pip package Tortoise ORM 1.0 release with migrations support
I know many people using fast-api use tortoise as orm, to minimise boilerplate code and to have more django-like experience.
For many years people using tortoise had one big limitation - migrations support in tortoise was lacking, which pushed users to use Alembic together with SQLAlchemy for full-fledged migrations support.
Tortoise did have migrations support via the Aerich library, but it came with a number of limitations: you had to connect to the database to generate migrations, migrations were written in raw SQL, and the overall coupling between the two libraries was somewhat fragile - which didn’t feel like a robust, reliable system.
The new release includes a lot of additions and fixes, but I’d highlight two that are most important to me personally:
Built-in migrations, with automatic change detection in offline mode, and support for data migrations via RunPython and RunSQL.
Convenient support for custom SQL queries using PyPika (the query builder that underpins Tortoise) and execute_pypika, including returning typed objects as results.
Thanks to this combination of new features, Tortoise ORM can be useful even if you don’t want to use it as an ORM: it offers an integrated migrations system (in my view, much more convenient and intuitive than Alembic) and a query builder, with minimal additional dependencies and requirements for your architecture.
You can see example project for fast-api with tortoise and migrations at
{github}/tortoise/tortoise-orm/tree/develop/examples/fastapi (sorry for not linking directly, afraid of reddit auto-ban)
Try it out yourself, create issues, contribute through PRs
1
u/scoutlance Feb 10 '26
Congrats on the 1.0. Django migrations are so good, definitely a great target. Alembic is clearly an awesome tool but it always feels clunky to me. Too many decisions. I love seeing the elegance of the Django ORM query syntax with some async sauce, too. We'll have to get some instrumentation out there for it at Scout!
1
7
u/_s0uthpaw_ Feb 09 '26
I actually know the developer and have been following the project since the very beginning. I think Tortoise did a great job bringing a Django-like experience to FastAPI + in an async-first way. If you’re looking for something like that, give it a try and see how it feels. (I did and I love it!)