r/FastAPI • • May 19 '21

Question Writing models on fastapi is difficult with sqlalchemy.

can anyone recommend better orm similar to django-orm with async support if possible.

0 Upvotes

12 comments sorted by

7

u/Deadly_chef May 19 '21

What exactly is difficult about writing models for you?

2

u/rj0_1_ May 20 '21

creating relationships between table example manytomany

6

u/dogs_like_me May 20 '21

Is your issue just with sqlalchemy then? This doesn't seem to be a fastapi-specific problem.

1

u/rj0_1_ May 20 '21

In fastapi docs examples are in sqlalchemy

5

u/kimaniyyyy May 19 '21

Have a look at https://peewee-async.readthedocs.io/en/latest/. I have used is before with sanic for async queries.

4

u/Nick0tin May 19 '21

I use tortoise-orm, I love using it and would recommend for use with FastAPI. It's interface is similar to django orm(which I preferred) and it is completely asynchronous.

1

u/sambame May 19 '21

How is it with JSONB and textsearch (tsvector)?

1

u/Nick0tin May 19 '21

It works fine for me, the orm has postgres(and MySQL I think) specific fields beside common field types.

1

u/sasmariozeld May 26 '21

Fullstack python has some helpful links for sqlalchemy, yeah it can be weird but sqlalchemy is so good that it is one of the main reasons to use python imo

0

u/nicolaballotta May 19 '21

Yeah I’m also curious to know what’s difficult. I’m using it with Sqlalchemy and it looks pretty easy.

And btw why you need async for the db?

0

u/[deleted] May 19 '21

[deleted]

2

u/s-to-the-am May 19 '21

SqlAlchemy has Async support now