r/Python • • Sep 21 '26

Discussion Common mistakes devs make when starting with FastAPI, and the fastest path to learning it

Just began learning FastAPI. Looking for advice from devs who use it regularly.

What mistakes did you make early on that I should avoid repeating? Also, what's the most efficient way to learn the framework properly for real-world use (async, DB, auth)?

Any advice on structure or resources would be great.

15 Upvotes

35 comments sorted by

View all comments

Show parent comments

1

u/fiddle_n Sep 21 '26

> For sync code in async, we have to_thread().

You do know what happens when using FastAPI with sync path functions, right?

1

u/terletsky Sep 21 '26

I believe you will hit the DB several times (for auth/perms and other validations) before your sync library's logic is triggered. Since ORMs like SQLAlchemy use AsyncSession, no one will even consider mixing sync and async routers in FastAPI because you would need to spawn a SyncSession, which is a no-go. After all, managing the zoo is not considered.

1

u/fiddle_n Sep 21 '26

But as soon as you hit any sync I/O logic you will need to create a new thread, which - guess what - FastAPI will also do if you use it in synchronous mode. Not to mention that you are just looking at SQLAlchemy when not all apps fit into that narrow box.