Skip to content

Using fast-api non-async libraries #8313

Answered by dmontagu
codingsett asked this question in Questions
Discussion options

You must be logged in to vote

FastAPI should have no issues making use of non-async libraries. As long as you define your endpoints properly, you can still get the performance benefits of the async event loop as long as the non-async libraries are only blocking on IO. So yes, a (non-async) library that sends requests to an external API should integrate nicely with a FastAPI-based backend.

From the FastAPI docs (https://fastapi.tiangolo.com/async/):

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, instead of being called directly (as it would block the server).

In other words, you'll get all the performance benefits as long as a…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
5 participants
Converted from issue

This discussion was converted from issue #260 on February 28, 2023 15:05.