0

Does FastAPI do async/await with the decorator functions? I’m confused about why they don’t use async/await in their official docs when they’re doing db operations.

Seems like a long db operation as illustrated in the docs would block the whole API, or are they doing some magic?

Chris
  • 18,724
  • 6
  • 46
  • 80
Glenn
  • 4,195
  • 9
  • 33
  • 41
  • 2
    In brief, when you declare a path operation function with normal `def` instead of `async def`, it is run in an external threadpool that is then awaited; hence, in any case, [FastAPI will still work asynchronously](https://fastapi.tiangolo.com/async/). – Chris Sep 09 '22 at 11:38
  • @Chris I think if what you say is true, they could say it much more plainly somewhere in their docs. I’ve read that page before and don’t see anything that definitively states what you stated. I’m not saying I don’t believe you I would just like a doc that explains this more clearly. – Glenn Sep 09 '22 at 19:57
  • Also, if you want to run your database queries asynchronously, there is [documentation on how to do that](https://fastapi.tiangolo.com/advanced/async-sql-databases/) as well. – M.O. Sep 10 '22 at 11:59

0 Answers0