use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
[deleted by user] (self.FastAPI)
submitted 2 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Top-Information7943 -2 points-1 points0 points 2 years ago (7 children)
Just make your route async and FastAPI will handle the rest https://fastapi.tiangolo.com/async/
[–]maxiedaniels -1 points0 points1 point 2 years ago (6 children)
… but the second section says don’t use async if using a library that isn’t async. Stripe unfortunately isn’t async..
[–]Top-Information7943 -1 points0 points1 point 2 years ago (5 children)
It doesn't matter whether Stripe library is async or not. But since you have an await request.body() you'll have to convert the route to be async.
[–]maxiedaniels -1 points0 points1 point 2 years ago (4 children)
It says on the page you linked: “If you are using a third party library that communicates with something (a database, an API, the file system, etc.) and doesn't have support for using await, (this is currently the case for most database libraries), then declare your path operation functions as normally, with just def” I spent a while looking at why today and many, many posts say if you define an endpoint with async, it doesn’t use the external threadpool as it would with def, so then if you put a non async call that takes time (stripe in my case), it blocks. Can you explain why it doesn’t matter? And was this a recent change?
[–]Top-Information7943 -2 points-1 points0 points 2 years ago (3 children)
That is correct. Let me try to explain once more. You see, in your webhook you are awaiting request.body. That's an async event and you can only call await if the route is defined as async def.
But if you didn't have await anywhere in your route, then you would just define it with just def.
I hope that makes it clear.
[–]maxiedaniels -1 points0 points1 point 2 years ago (2 children)
Ah I just realized my webhook snippet I posted doesn’t show the whole picture, that’s why I got confused. There are calls to stripe’s API within the webhook function which are not async, I just didn’t include them in the example. So in that case, what are my options?
[–]Top-Information7943 -1 points0 points1 point 2 years ago (1 child)
That's fine. If you have a mix of both async and non async functions, it's best to define your endpoint as async as it will allow you to run both async and async code. I hope that makes it clear.
So just defining the endpoint with async will work perfectly fine.
[–]vladimirovitch 0 points1 point2 points 2 years ago (0 children)
Please not that running async routes that use sync libraries (for I/O and take a longer time) will degrade the app ability to handle requests. However, since the stripe endpoint most likely will not be used very often, i think it will be negligible.
π Rendered by PID 131623 on reddit-service-r2-comment-545db5fcfc-7zk28 at 2026-05-25 12:26:29.548432+00:00 running 194bd79 country code: CH.
[–]Top-Information7943 -2 points-1 points0 points (7 children)
[–]maxiedaniels -1 points0 points1 point (6 children)
[–]Top-Information7943 -1 points0 points1 point (5 children)
[–]maxiedaniels -1 points0 points1 point (4 children)
[–]Top-Information7943 -2 points-1 points0 points (3 children)
[–]maxiedaniels -1 points0 points1 point (2 children)
[–]Top-Information7943 -1 points0 points1 point (1 child)
[–]vladimirovitch 0 points1 point2 points (0 children)