#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.
0:02 That was great, except
0:03 it did not have any async integration.
0:06 It had no way to await it
0:08 which means we couldn't unlock this powerful
0:11 shared, cooperative multi-threading
0:14 that asyncio provides and Quart is based on.
0:17 What we had to do is go find aiohttp's client.
0:22 We needed to find a replacement for requests.
0:25 I want to give you a few other examples
0:26 so you kind of know where to look.
0:29 Every place where you're waiting
0:30 think, database call, web service call
0:33 cache server call, things like that.
0:36 To get true, full advantage
0:39 of what we're talking about here
0:40 you have to use an async version of that code.
0:44 Many of the most popular libraries
0:46 don't have an async option
0:48 so they're kind of useless
0:50 or almost even harmful to you.
0:51 So let's look at a few others.
0:52 So we saw requests and aiohttp client.
0:55 If you're using Postgres, there's this thing
0:58 called asyncpg for Postgres for Python
1:01 and this is a fast Postgres database client
1:04 for Python and asyncio.
1:06 If you look down here, often you'll see, like
1:08 "Oh, it's super fast.","Awesome, awesome graphs"
1:11 but the idea is, that with this one
1:13 you can await your calls.
1:15 So, for example, we're going to run, and await
1:18 connecting to the database
1:19 and then, we're going to await running a SQL query
1:22 and await closing the connection.
1:24 Alright, standard stuff, like you might expect.
1:26 What if we're using MongoDB and not Postgres?
1:29 Then you can look at Micromongo.
1:32 Synchronous and asynchronous MongoDB. Very cool.
1:36 And this actually has the cool capability
1:38 to be based on synchronous MongoDB
1:40 on Motor asyncio, which is an asynchronous version
1:44 or even a mocking foundation.
1:46 So there's all sorts of cool stuff you can do there
1:49 and if you're doing like, Redis, well, aioredis.
1:52 Again, very, very similar. Await connecting to it.
1:56 Awaiting executes some GET operation on a key
1:59 things like that. Standard Redis caching stuff.
2:02 You have to go get one of these asyncio-based libraries
2:06 if you're going to take advantage of it in Quart.
2:09 It doesn't mean you have to have it.
2:11 You could make a synchronous Redis call
2:14 but it means that that portion of your waiting time
2:16 of the request, you're not giving up
2:19 to do other processing.
2:20 You're hurting your, sort of, scalability there.
2:24 I guess the take away is, if it's available
2:26 use an asyncio-based one and await it.
2:28 If not, you know, what are you going to do?
2:30 You still got to write your code and run it, right?
2:32 So use what you've got.