#100DaysOfWeb in Python Transcripts
Chapter: Days 21-24: Async Flask APIs with Quart
Lecture: Concept: Quart

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So you now know async and await we spend a little bit of time on the first day in the first set of lectures talking about that.
0:08 How we can take regular code and make it async. Here we have a function and we're converting it to an asynchronous function by adding the async keyword
0:17 in front of def. Any time that we're in a waiting state, any time we're waiting for a response on calling a database or web search
0:26 or even getting something from a queue, cause maybe the queue is empty or we're waiting until something
0:30 goes into in, who know how long that's going to take? We need to await that so we're going to await any other
0:36 other calls to other asynchronous methods like this asyncio queue.get. It's async so we basically have to do this.
0:46 If you don't know whether it's async just go to the definition of get, it says async def get, well you should await it.
0:52 If it doesn't then you can't await it, I noticed also that we're using data structures like the asyncio queue to make this possible.
1:01 Right, so you know async and await now that we talked about it in the first bit you already knew Flask, what do we do to make Flask work?
1:09 Well, we add a route, we write our controller logic and once we've come up with the data, we can either return
1:16 it as a JSON response or we can return it as a template using that data, but we're going to return some response
1:23 back to the server by passing it as a model data. You've already learned Flask, so you know asyncio as of
1:29 a day ago, you know Flask so putting that together to make Quart, that's crazy easy right. Now we convert our view method or our controller method into
1:40 async contoller method by adding async. We implement our controller logic, but now awaiting any chance that we can get the more asynchronous we can
1:50 make this, the better chance we have for scalability here. And then we return our response, and notice anywhere we have the word Flask we put Quart.
2:00 So this is really simple path forward, to go from a Flask API to a asnycio friendly API, very cool.


Talk Python's Mastodon Michael Kennedy's Mastodon