Rock Solid Python with Python Typing Transcripts
Chapter: Frameworks Built on Typing
Lecture: Setting up Our FastAPI Example

Login or purchase this course to watch this video and the rest of the course contents.
0:00 For this last example, let's take some of these things and put them together.
0:05 Pydantic, Beanie, FastAPI into a somewhat realistic web app that I'll give you to work with and we can play with some of the things going on there.
0:16 All right, now this is a complex application that I built up in another course, the one on Async MongoDB. That would take an hour to build at least.
0:27 So we're not going to do that. We're just going to start from having the code here. I'm going to call that web example.
0:32 And in this, we need to set this as a sources route as well. And we're going to run this. But in order to run this, we have to update our dependencies.
0:42 It is based on things like FastAPI, and UVicorn and others. So let's go down to our pip tools.
0:49 Again, you don't need to do this, just need to run the requirements.txt. But I'm doing it for you. And you can use it to update things along the way.
0:59 So this app uses passlib, I'll put this up here like that. It uses passlib and the argon2 password hash for its account management.
1:10 It uses FastAPI for the web framework. It uses beanie to talk to MongoDB. More about how to work with that in a second.
1:19 It's going to use Jinja2 to show HTML and uvicorn to run. So let's go down here and I'll do pip compile, pip requirements.pip, or requirements.pip
1:30 tools upgrade. And now this has been updated and you can see there's a lot more stuff here like argon2c, ffi, beanie, and others.
1:49 So we got a pip install -r, a bunch of things. Now, if we go over here, all those errors should go away and we should be able to run this code.
2:00 Let's try it, see what happens. Yes, look at that. We're talking to our MongoDB server on localhost for a database called PyPI.
2:11 Let's just click here and see what we get. Now, this data, this example is an API that lets you get information about a subset of PyPI data.
2:22 That is the data out of the Python package index. I took some of the popular, their first top 1,000 or top 5,000 packages
2:33 and put them into MongoDB in a way that we could work with. So if we wanna go over here and get the five most recent packages, here they are.
2:42 And by the way, if you're working with this kind of data, Firefox is such a better way to do it. Why you ask? Well, look at that view.
2:53 You have the raw view, which you can pretty print or you can look at this straight away. And I just wish some of the other browsers
3:01 like Vivaldi, the one I really like, had a better view of it. But we can come over here and it lets you ask for most recently updated packages.
3:09 Here we have Beanie, Boto and Pydantic. And if we go back here, You can see I want the details for say, FastAPI,
3:17 and there's pretty much everything you would see in terms of releases and description, read me type stuff on the page. Okay, so there's also stats.
3:28 I guess here's how many packages I was able to load in that I thought were relevant, popular ones. So very, very cool.
3:36 This is all done and powered with, as I said, FastAPI, Pydantic, and Beanie.


Talk Python's Mastodon Michael Kennedy's Mastodon