r/FastAPI • • Jan 08 '25

Question What's the benefit of sqlmodel in fastapi?

I think using sqlalchamy is enough so why using sqlmodel especially when it adds another extra layer; what's the benefti?

16 Upvotes

24 comments sorted by

View all comments

Show parent comment

3

u/scorpiokozu Jan 08 '25

sorry -- users table was a bad example haha. i use it for some basic tables like "events" (for a calendar). here, fetching all columns is fine. but yes to your point, i have dozens of pydantic models and sqlalchemy tables, but i only very rarely get to use what sqlmodel provides. does this benefit make using a new library worth it? can't say for sure, that's up to you.

though i'm 100% certain that not much would've changed if i had just used sqlalchemy + pydantic, but i decided to stick with sqlmodel since it's what i started with. if i had to recommend, if you're already familiar with sqlalchemy and pydantic, just use them separately. otherwise, using sqlmodel might not be that bad. no strong convictions for me, really just did it cuz "might as well" haha.

2

u/bluewalt Jan 08 '25

Thanks for making it clear. I pretty much agree with you. I guess on a small project, one or the other solution will work anyway. Things could be more interesting when one need to scale.