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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Are you ready to convert our Flask app to a Quart app? Well, that actual transformation is super easy. Well see, most of the time we have to spend on
0:10 actually rewriting our web API calls or work consuming services with requests but lets just convert this to Quart real quick. So, we go over here
0:20 and we going to comment that out and put Quart. Let's just rerun this pip install -r requirements.txt. Download the Quart stuff. Okay, that went great.
0:31 And let's while were here go ahead and uncomment these bits. aiohttp has a client like requests which lets you make calls to web services
0:41 but it does it in an async friendly version. Our dependencies are switched, of course we're still using Flask up here.
0:50 Let me just give you the quick overview what we're going to do. Where you see Flask, we put the word Quart.
0:56 If you see a lower case flask, you put lower case quart. If you see upper case Flask, you put upper case Quart.
1:01 Let's try this. I know, we can all do it, it's no big deal. That was good. And we got to go to our other views
1:10 these should be the only other two places where Flask appears. So we go Flask is now Quart we're going to do a response we do it like this
1:20 we have one more place with Flask with this blue print and then we're also using abort and jsonify. That's it.
1:30 We've converted from one web framework to the other. We converted from Flask to Quart. Let's run it and see what we get.
1:38 Oh, yeah. Over here we have the way this is running it set this up as a Flask server. Let's just run it directly.
1:47 There we go. Now, we're running on here again let's see if it still works. Still does. Let's see if our API still works.
1:55 Oh, 'cause it's 5,000, let's put 5,001. There we go. 'Cause I changed that. Okay, so our API still works. Everything is good.
2:05 Are we getting all the benefits the magic of asyncs that I've already shown you? No. Let's go look.
2:12 The only part that really much matters is over here. This method, is that method an async method? Right there. Sun, is sun an async method?
2:24 Well, no. 'Cause it doesn't say async. So in order to actually take advantage of Quart we can run on it but this stuff still behaves basically
2:34 identically to Flask. But what we have now is Quart would be able to process this if we wrote an async method.
2:43 Whereas Flask couldn't do anything with this. It wouldn't work. That is all you could do. But in Quart we can now start writing this.
2:52 So if we just put an async here and make those async and we await them, magic. Let's do that next.


Talk Python's Mastodon Michael Kennedy's Mastodon