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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We saw that we were using Requests. That was great, except it did not have any async integration. It had no way to await it
0:09 which means we couldn't unlock this powerful shared, cooperative multi-threading that asyncio provides and Quart is based on.
0:18 What we had to do is go find aiohttp's client. We needed to find a replacement for requests. I want to give you a few other examples
0:27 so you kind of know where to look. Every place where you're waiting think, database call, web service call cache server call, things like that.
0:37 To get true, full advantage of what we're talking about here you have to use an async version of that code. Many of the most popular libraries
0:47 don't have an async option so they're kind of useless or almost even harmful to you. So let's look at a few others.
0:53 So we saw requests and aiohttp client. If you're using Postgres, there's this thing called asyncpg for Postgres for Python
1:02 and this is a fast Postgres database client for Python and asyncio. If you look down here, often you'll see, like
1:09 "Oh, it's super fast.","Awesome, awesome graphs" but the idea is, that with this one you can await your calls.
1:16 So, for example, we're going to run, and await connecting to the database and then, we're going to await running a SQL query
1:23 and await closing the connection. Alright, standard stuff, like you might expect. What if we're using MongoDB and not Postgres?
1:30 Then you can look at Micromongo. Synchronous and asynchronous MongoDB. Very cool. And this actually has the cool capability
1:39 to be based on synchronous MongoDB on Motor asyncio, which is an asynchronous version or even a mocking foundation.
1:47 So there's all sorts of cool stuff you can do there and if you're doing like, Redis, well, aioredis. Again, very, very similar. Await connecting to it.
1:57 Awaiting executes some GET operation on a key things like that. Standard Redis caching stuff. You have to go get one of these asyncio-based libraries
2:07 if you're going to take advantage of it in Quart. It doesn't mean you have to have it. You could make a synchronous Redis call
2:15 but it means that that portion of your waiting time of the request, you're not giving up to do other processing.
2:21 You're hurting your, sort of, scalability there. I guess the take away is, if it's available use an asyncio-based one and await it.
2:29 If not, you know, what are you going to do? You still got to write your code and run it, right? So use what you've got.

Talk Python's Mastodon Michael Kennedy's Mastodon