Async Techniques and Examples in Python Transcripts
Chapter: asyncio-based web frameworks
Lecture: Demo: An async weather endpoint
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Although I trust you can take the sun example and adapt it to the weather example let's go ahead and do that together.
0:06
So over here we're going to say we have an async method. And again, this right now is a synchronous function.
0:13
Let me just go over here and grab some aiohttp client. And we're going to re-implement this again, not request.
0:23
And not response like that but like this. And this. Good? One more thing, async. Okay, so now this is an async method using async with and async await.
0:42
And here, we should be able to go to this function and we don't get the data back, we have a coroutine. If we await it though, we get the data back.
0:49
Alright, I think that's done it. Let's just test the weather as well. So there's the sun but if I change that to weather
0:58
yep, also works. So it looks like we've converted from an entirely synchronous Flask based API over to Quart and what does that take?
1:06
Maybe, maybe 15 minutes, probably less with me talking and explaining, poking around. If I just put my head down
1:13
that could've been a 10 minute job, easy. Granted, pretty toy application but not entirely a toy app, right? It is calling other services
1:21
it does have some reasonable structure with the blueprints and the config files and all that kind of stuff. So it's non-trivial
1:28
even if it's somewhat on the small side. Hopefully you see this as pretty straight forward and pretty easy to do.