Async Techniques and Examples in Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Async Flask

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Another third party library we looked at was Quart. Purpose of Quart is take the non-async web framework, Flask
0:08 and make it an async and await-enabled framework. It does this by completely reimplementing Flask
0:14 atop asyncio, but doing it in a entirely compatible way so even Flask extensions just plug into Quart and'll work just fine. So how did that go?
0:23 Well, we added an async method definition here so instead of def sun, we have async def sun. We do all of our work against as much async operations
0:34 as many async operations as we can, so we make sure we await those, and in these places our web server can entirely go
0:42 and start processing other requests completely. Cause what are we doing? We're waiting for that web service, that location service
0:48 or sun service to get back to us. So while that's happening, let's do the rest of the work. And then, we just return our data, in this case it's an API
0:57 so we're going to return JSON data via quart.jsonify. Remember the complex algorithm of conversion here. You take the word Flask and you replace
1:05 it with the word Quart. If it's lowercase flask it's lowercase quart uppercase Flask, uppercase Quart. And then you make as much of your libraries
1:12 and your internals async enabled and then you just await them and use them, like this. It's beautiful.


Talk Python's Mastodon Michael Kennedy's Mastodon