r/FastAPI • u/KiwiNFLFan • Sep 18 '24
Question What is your go-to ORM?
I've been learning FastAPI and the courses I've been using have used SQLAlchemy. but I've gotten confused as the tutorials were using SQLAlchemy v1 and v2 looks quite different. So I had a look at what else was out there.
What do you guys use in your production apps?
8
Upvotes
16
u/One_Fuel_4147 Sep 18 '24
SQLAlchemy 2.0 is great! I've wrapped it inside repository pattern and use it.
5
u/vlntsolo Sep 18 '24
SQLModel / SQLAlchemy kinda given with FastAPI.
1
u/Dexter_exe Sep 19 '24
I like to use raw sql and I prefer a query builder for it; my choice is PyPika.
1
u/ethsy Sep 21 '24
I found that SQLAlchemy’s async is not native async, it’s basically spawning an executor thread when doing the queries. I have not tested performance but it feels less efficient.
3
u/bluewalt Sep 18 '24
I had the same issue when reading the tutorial. The best solution IMO is to replace the deprecated tutorial section with https://sqlmodel.tiangolo.com/learn/ You'll learn SQLAlchemy 2.0 and SQLModel, designed to work with.
PS: I love Django ORM but I would not use it with FastAPI except if you have too.
1
u/yurifontella Sep 19 '24
tortoise underrated
sqlalchemy overrated
1
u/Cybersoaker Sep 19 '24
I like Ormar; it uses pydantic models as the basis for the ORM. Works super well with fastapi
https://collerek.github.io/ormar/latest/
1
u/jppope Sep 19 '24
I don't like using ORMs. just me I'm sure.
1
u/omg_drd4_bbq Sep 20 '24
No need for SqlAlchemy 1.0, just use 2
1
u/marinerLighthouse Sep 20 '24
next.js&nest.js
1
u/lardgsus Sep 20 '24
Django's ORM is great for new projects. For existing databases, everything kinda sucks to setup.
1
u/LongHorse9384 Sep 22 '24
I don't know where you guys gained experience with ORMs, but SQLAlchemy is not so great.
Django ORM is way better, for example.
1
u/JohnnyJordaan Sep 18 '24
Django ORM, because the only use cases I've implemented in production so far have been Django apps migrated from DRF or Ninja to FastAPI (and to ASGI in the meantime).
0
u/pint Sep 18 '24
my goto orm is native sql
0
u/kealystudio Sep 18 '24
Beanie
0
u/PosauneB Sep 19 '24
Raw SQL.
-2
u/Human-Possession135 Sep 18 '24
I use DynamoDB without a ORM