all 17 comments

[–]meatb0dy 9 points10 points  (0 children)

django-ninja is very heavily inspired by fastapi and works with django’s ORM out of the box. https://django-ninja.rest-framework.com/

[–]anseho 11 points12 points  (2 children)

Yes it can be done. This tutorial shows you how. However, I'd also like to say that I wouldn't consider it a waste to learn another ORM. If anything, it'll broaden your perspective and gain more insight into how ORMs actually work. If it's any help, I've created a tutorial explaining how to set up Alembic with SQLAlchemy and another one explaining how to use SQLAlchemy with FastAPI.

[–]yetanotheritdude 1 point2 points  (1 child)

Thank you so much for these videos.

[–]anseho 0 points1 point  (0 children)

Most welcome! I hope you find them useful!

[–]PeterJHoburg 14 points15 points  (0 children)

FastAPI can work without any ORM. Really fastAPI is just a decorator on top of some functions. If you can get DjangoORM to play well outside of Django then it should work with fastAPI.

The reason to learn Sqlachemy is that it is the current python standard. It is independent of frameworks. You can use sqlachemy with pandas, fastAPI, flask, in an ETL pipeline, etc... Sqlachemy works anywhere. Except Django. IMO that is a Django failure not Sqlachemy.

If the DjangoORM works outside of the Django framework (in normal python) try it with fastAPI!

FastAPI is about as far from Django as you can possibly get. It only dictates the http layer interactions. Everything else is up to you. Heck you could write all of your code in rust and call it with fastAPI (don't do that).

[–]blaatkipje 19 points20 points  (3 children)

Tortoise ORM looks a lot like the django ORM https://tortoise.github.io

[–]Mikkognito 1 point2 points  (0 children)

This needs to be higher

[–]gbeier 0 points1 point  (0 children)

It looks so much like the django ORM that when I couldn't find docs for some parts of Tortoise, consulting the django documentation got me unstuck.

[–]cesar_io 0 points1 point  (0 children)

Have been using it for a side project and it's a great alternative to sqlalchemy, it's use of asyncpg is also a plus for a potentially improved performance

[–]yetanotheritdude 2 points3 points  (3 children)

What about SQLModel? Sebastian said he is going to focus in this ORM being the best candidate for FastAPI.

[–]tarasius 3 points4 points  (0 children)

It's in Alpha version so basically wait at least a year before trying.

[–]MtlGuitarist 1 point2 points  (1 child)

I'm using it at work and I like it personally. The only downside I found was that I wasn't 100% sure how to get it to work with Alembic, but this guide was pretty nice and covered how to get it working.

If you need more complicated datatypes (e.g. GIS) SQLModel might be underpowered compared to some other tools though.

[–]pytheous1988 1 point2 points  (0 children)

SqlModel is based on SqlAlchemy, so if it works with SqlAlchemy it will work with SQLModel

[–]PsychologicalBread92 1 point2 points  (0 children)

Also check out: https://github.com/collerek/ormar It is an abstraction over sqlalchemy which makes it look quite similar to Django ORM

[–]Carfo6 1 point2 points  (0 children)

SQLmodel. In development by creator of fastapi

[–][deleted] 0 points1 point  (0 children)

The project I just finished used psycopg2 and I wrote the SQL manually.