Latest / Talk Python To Me / #315: Awesome FastAPI extensions and add ons
Transcript
- 0:00Have you heard that FastAPI is awesome?
- 0:02We have Michael Herman back on the show to help us make it even more awesome
- 0:06with his FastAPI Awesome list.
- 0:08He's categorized many extensions and other libraries working with FastAPI
- 0:13to help you be even more efficient with this framework.
- 0:16This is Talk Python To Me, episode 315, recorded April 22, 2015.
- 0:22Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 0:41This is your host, Michael Kennedy.
- 0:43Follow me on Twitter where I'm @mkennedy, and keep up with the show and listen to past episodes at talkpython.fm,
- 0:49and follow the show on Twitter via at Talk Python.
- 0:52Talk Python To Me is partially supported by our training courses.
- 0:55At Talk Python, we run a bunch of web apps and web APIs.
- 0:59These power the training courses as well as the mobile apps on iOS and Android.
- 1:03If I had to build these from scratch again today, there's no doubt which framework I would use.
- 1:08It's FastAPI.
- 1:09To me, FastAPI is the embodiment of modern Python and modern APIs.
- 1:14You have beautiful usage of type annotations.
- 1:16You have model binding and validation with Pydantic.
- 1:19And you have first-class async and await support.
- 1:22If you're building or rebuilding a web app, you owe it to yourself to check out one of our newest courses,
- 1:27Modern APIs with FastAPI, over at Talk Python Training.
- 1:30This is the first course in a series of FastAPI courses we're building,
- 1:34and you can get it for just $39.
- 1:36It'll take you from interested to production with FastAPI.
- 1:40To learn more and get started today, just visit talkpython.fm/FastAPI or email us at sales at talkpython.fm.
- 1:47Michael, welcome back to Talk Python To Me.
- 1:50Thank you.
- 1:51Yeah, it's really great to have you back.
- 1:53You've been on before, and there's a bunch of stuff that we're going to talk about that you've been up to and we've done.
- 1:59So you were back on episode 206 when you talked about running Django in production.
- 2:03And you've had a couple of large sites that you've been running.
- 2:07And the most recent one is probably testdriven.io where you do some articles, some tutorials, and some courses, right?
- 2:14Yeah.
- 2:15So life was obviously much different back in when I was on the podcast back in, what was that, February of 2019.
- 2:22But so now I'm still working on testdriven.io.
- 2:26So that's a, I do training courses for mid to senior level developers that are looking to learn test driven development,
- 2:32microservices, and AWS infrastructure and whatnot.
- 2:36Nice.
- 2:36It's mostly Python and JavaScript stuff.
- 2:38Is that right?
- 2:39Yeah.
- 2:39Yeah.
- 2:40Yeah.
- 2:40Cool.
- 2:40Maybe some at the same time.
- 2:42Yeah, a bit.
- 2:43I also get a lot into like container orchestration and whatnot.
- 2:45A little bit of Kubernetes, a little bit of AWS ECS as well.
- 2:49Awesome.
- 2:50And so what do you have to do now?
- 2:51So yeah, I am running testdriven.io on the side, but my full-time main gig is for Monitor.
- 2:57And we, as the banner there says, we're doing machine learning assurance.
- 3:02We're really doing probably machine learning governance is probably more like what way to redo the website.
- 3:07That's probably what we would establish machine learning governance would be there rather than assurance.
- 3:11But basically we're helping to ensure that your AI is doing what it should be doing in production.
- 3:19So that your models are basically inferences or predictions that your models are serving up are like within a certain bounds, essentially.
- 3:26Right.
- 3:27Like if the input data changes and you don't change your models, maybe they're not meant to understand that type of data.
- 3:34And there's just, you know, the thing is you're always going to get an answer, right?
- 3:36Yeah.
- 3:37It just might be the wrong or invalid data, but it looks like a valid answer.
- 3:40Like, how do you know, right?
- 3:41Yeah.
- 3:41It's kind of like an Excel, like whenever you get, you know, whatever it is besides an NA or whatever, you know, you don't know that's like good or bad or not.
- 3:49And so, yeah, we're looking for like feature drift.
- 3:51We're looking for model drift.
- 3:53We're looking for bias, you know, that sort of things.
- 3:55We're also, we take all inferences that go through a model.
- 3:58We're logging and then we're also versioning the model as well.
- 4:01So you can recreate the model, run counterfactual type tests and whatnot.
- 4:05Interesting.
- 4:05Okay.
- 4:06Is that mostly Python stuff over there?
- 4:08What's the tech?
- 4:09Yeah.
- 4:10So it's a Django monolith.
- 4:11That's like the backend API using Flask is sort of a middle layer to transform data between the API and the front end.
- 4:20The front end is in view and it's primarily AWS.
- 4:24And so I'm using Terraform as infrastructure as code to simplify the maintaining of the infrastructure.
- 4:30Oh, that's cool.
- 4:31I feel like Terraform has definitely taken off.
- 4:33I hear a lot of people saying that they're using it these days.
- 4:35Yeah, I really.
- 4:36Is that like Ansible or Chef or it's like a competitor to that, right?
- 4:41Yeah, I think those are a little bit different.
- 4:43I would say it's more of a competitor to like CloudFormation templates.
- 4:48And CloudFormation, I think there's a new sort of infrastructure as code from AWS called CDK.
- 4:53That's a little bit more declarative, sort of how Terraform is.
- 4:57And I haven't had a chance to look at that, but I think that's sort of like the new hotness these days.
- 5:01And then there's one more called like Bloomy, I believe is the name, but I haven't used that one.
- 5:06Yeah, cool.
- 5:07People want to learn more about what's going on with Monotar, they can check out episode 261, which is a little newer, April 2020 with one of your co-founders, Andrew Clark.
- 5:17Is he still working with you?
- 5:18Yeah, definitely.
- 5:19Yeah, cool.
- 5:20So we dive into all that sort of stuff over there, which is cool.
- 5:23So really the main thing that we're going to talk about is FastAPI, right?
- 5:27Like that's what we're both here.
- 5:29We're both fans of FastAPI on multiple levels.
- 5:31And yeah, so we're going to talk about the basically all the extensions in the ecosystem around FastAPI.
- 5:39But make the case for us for FastAPI itself.
- 5:43Like I feel like there was quite a thousand flowers blooming type of thing going on once async and await came out in Python, right?
- 5:51We had the Django, the Flask, old standbys.
- 5:55And then when things switched with type annotations and with async and await, those frameworks couldn't move super quick to adapt to those.
- 6:02So things like FastAPI and Sanic and Jeprento and Starlette and API Star, all these things just sort of came into existence.
- 6:09And, you know, FastAPI is certainly among that crowd, right?
- 6:12Yeah, FastAPI definitely leverages Starlet.
- 6:14And so, yeah, you get the whole async syntax, async and await syntax.
- 6:18I would say that I like FastAPI for other things.
- 6:21Like I don't really take advantage of async and await.
- 6:24And like the, I have one production app that's running in FastAPI and I could honestly care less about async and await.
- 6:30But it's more about like the developer experience that I get.
- 6:33And also I really like Pydantic.
- 6:35I would say that, yeah, if you're really into Pydantic and that's like what you use for serialization, deserialization, whatnot, then I would definitely check out FastAPI.
- 6:45Absolutely.
- 6:46Just, you probably don't realize it because it's not very obvious.
- 6:50There's like, you scoured the website, you might learn this.
- 6:52I just interviewed Samuel Colvin, the creator and maintainer of Pydantic, about Pydantic and all the cool stuff it does.
- 6:59So people who are listening to this may have just listened to that episode.
- 7:02And FastAPI is a framework that absolutely takes Pydantic and puts it on the boundary, right?
- 7:09Like it's, when data is exchanged with FastAPI, the most default way to do that is to somehow involve Pydantic models, right?
- 7:15Yeah.
- 7:15And I mean, like if you could think back to like Flask, Flask is like just a wrapper on top of Wurzwig and I'm not pronouncing that right, but Wurzwig, Click and a couple others that are escaping me right now.
- 7:26But FastAPI is really just a wrapper.
- 7:28It's dangerous.
- 7:29And like a couple other, yeah.
- 7:30Yeah.
- 7:30It's just a wrapper on top of Pydantic, OpenAPI, JSON schema, that sort of things.
- 7:36Yeah.
- 7:36A few more like sort of modern tools like that.
- 7:39And so what makes FastAPI cool is that you can, makes it easy to like hook into those two so you can like leverage that and build plugins and whatnot.
- 7:47Yeah.
- 7:48So you can say things like, here's my API endpoint that I expect somebody to send a JSON document to.
- 7:54Oh, and the argument to the document is just a Pydantic model.
- 7:59Yeah.
- 8:00Right.
- 8:00And then FastAPI will either successfully convert that model over or send something like a 400 or 422 back to say bad data.
- 8:08We can't convert it to what we're expecting.
- 8:09And on top of that, FastAPI then automatically generates the OpenAPI stuff, which you hinted at based on those models, right?
- 8:17Yeah.
- 8:17Yeah.
- 8:18So you can sort of that runtime type checking that you were talking about.
- 8:21And so you're really abstracting that out all to Pydantic.
- 8:24And so like you don't have to maintain like a test suite around that either.
- 8:27And so it handles all of like the error handling around that.
- 8:30It sends back a nice human and computer readable response.
- 8:34Yeah.
- 8:35One of the things I like is if you've got like a nested object, maybe I've got a Pydantic model and has a list of little baby Pydantic models.
- 8:42And then there's an error.
- 8:44The error would say the third thing in the list is where the problem is.
- 8:48Not just there's some invalid data, but on this field, you got a list.
- 8:52You've sent me a list of things.
- 8:54The third one, that's where that type conversion error is.
- 8:57It's like really good about giving you like allowing you to drill on where the data is wrong.
- 9:01Yeah.
- 9:01Okay, cool.
- 9:02So we've got the async and await stuff, which you said you don't use a lot, but if you need it.
- 9:06It's there.
- 9:07It's nice to have it, right?
- 9:08It's really there.
- 9:09We're going to talk about some of the places that like plug into that in a moment.
- 9:12Pydantic, I think is a big one.
- 9:14The OpenAPI stuff is a big one.
- 9:17And to me also deployment is just simple, right?
- 9:19As long as you've got uvicorn or GUnicorn plus uvicorn, you're kind of good to go, right?
- 9:24There's not a lot of other stuff you got to do on the server.
- 9:27Just GUnicorn, fire this thing up and maybe point Nginx, put Nginx in front of it.
- 9:31Yeah.
- 9:32Yeah, definitely.
- 9:32I like how it doesn't have a development server either.
- 9:35So you have to use...
- 9:36I do too.
- 9:37Yeah, uvicorn and development.
- 9:39And I think that helps beginners that are new to sort of web development conceptually understand
- 9:44that, hey, this development server is...
- 9:47There's a difference here between this development server and this production server.
- 9:51Whereas like with Flask and with Django, where they give you like a development WSGI server
- 9:56right out of the box.
- 9:57I think it's confusing because a lot of people are like, well, why do I need that?
- 9:59Why do I need...
- 10:00Why can't I use this instead of GUnicorn?
- 10:02Exactly.
- 10:03And they always come with this warning.
- 10:04This is not a production server.
- 10:05Please don't use this.
- 10:07And you're like, okay, well...
- 10:08Yeah.
- 10:08What if I want to test it like for performance?
- 10:10Is it kind of like what I would expect?
- 10:12Is it really different?
- 10:13Like there's all these things.
- 10:15Just like, just make it run what you're going to run in production anyway, right?
- 10:18Yeah.
- 10:18Yeah, definitely.
- 10:19Yeah.
- 10:19Pretty cool.
- 10:20Okay.
- 10:20Well, I think that's a pretty solid case for FastAPI.
- 10:23I do think it's probably its biggest parallel competitor type thing is probably Flask.
- 10:29You know, a lot of times people are using Django.
- 10:31They're trying to do a little bit more than maybe what they're doing with Flask.
- 10:35Flask has many, many plugins as well.
- 10:37So I don't know.
- 10:38What do you think about this?
- 10:38Do you see these working together?
- 10:40Would you use one instead of the other?
- 10:42It's interesting because I think last week, you know, Flask announced their 2.0.
- 10:46Yes, they did.
- 10:46Another 2.0 is going to have some async and await support.
- 10:49That'll be interesting because like the entire Flask, part of the power behind Flask is the ecosystem.
- 10:54Like you have just thousands of plugins.
- 10:56Some might argue that's like there's too many plugins, but regardless, there's a lot of different
- 11:00plugins there.
- 11:01And so are they all going to start migrating over and supporting async and await?
- 11:05What are they going to do?
- 11:06So I think that'll be interesting.
- 11:08But I would say there's obviously a lot of comparison type articles between Flask and Fast
- 11:12API.
- 11:13I don't know.
- 11:14Like I try not to get into the either or type thinking and try and think of and in both.
- 11:18They're both tools.
- 11:19I use all three.
- 11:20I like FastAPI for certain things.
- 11:22I use Django for other things and I use Flask for other things.
- 11:25And so it's just all about like the tool, having the right tool for the job.
- 11:29Yeah.
- 11:29Yeah.
- 11:30I would say that FastAPI is more similar to Flask than obviously is Django.
- 11:35And so it's probably going to be compared more to Flask.
- 11:37But I still think that there's like certain reasons that I would probably use Flask over
- 11:41FastAPI.
- 11:42Sure.
- 11:43That may well be because one of the plugins that you're talking about exactly nails the use
- 11:47case.
- 11:47Yeah.
- 11:47And I'm also going to have David and Phil on to talk about the Flask 2.0 release pretty
- 11:53soon.
- 11:53So that's, I think there's been this sort of like leapfrog thing is probably going to put
- 11:58Flask back, if not ahead of FastAPI and some of the cool features, it'll bring a lot of those
- 12:02features over, I would expect.
- 12:03It's also worth pointing out that like in Flask, you can still do cool stuff with say Pydantic,
- 12:08right?
- 12:09You just need one extra line of code.
- 12:10The very first line of your API method could just be model equals Pydantic thing, star,
- 12:16star, request, dot, get form or whatever the call is to get the form data that's been posted
- 12:21over or get the JSON data that's been posted over and then just run with it the same.
- 12:25Yeah.
- 12:25Yeah.
- 12:26And there's a nice like Flask Pydantic plugin as well.
- 12:28So yeah, you can definitely use Pydantic inside of Flask.
- 12:32And then there's also like Flask Res X, which will give you nice open API slash Swagger type
- 12:37support as well.
- 12:38So if you want that out of the box.
- 12:39Interesting.
- 12:40Okay.
- 12:40And a lot of this is awareness, right?
- 12:43Like knowing, oh, there's this thing that I can go get, right?
- 12:45Knowing that I could get Flask Pydantic or the open API, so on.
- 12:50And that brings us to our main topic here.
- 12:52How do you discover these things and know that they're out there, right?
- 12:56It turns out there's actually a bunch of extension type libraries for FastAPI.
- 13:02I don't know there's an official plugin model for FastAPI, but certainly things built to make
- 13:06FastAPI better and add functionality to it, right?
- 13:09And so I learned about a lot of them from your awesome FastAPI list.
- 13:13But maybe just for a minute, for people who are not aware of this whole trend of awesome
- 13:18lists, maybe just talk about awesome lists for us a little bit.
- 13:22Like what's the story?
- 13:23Where do these things come from?
- 13:24Yeah, I can't remember exactly when they started popping up.
- 13:26I feel like maybe like five years ago, something like that.
- 13:29But I mean, awesome lists is, I guess, just literally just a list of awesome things.
- 13:33In theory, it's contributed, maintained by the community.
- 13:36I mean, oftentimes what really happens is like the main author becomes like sort of a dictator
- 13:42around that, which I think is totally fine.
- 13:44But I think there's just, there's thousands of different awesome lists out there.
- 13:48And so it's just, you're like a meta, meta awesome, awesome list of awesome lists, you know,
- 13:54type thing there.
- 13:55So it gets a little crazy.
- 13:57It does get super, super meta.
- 13:59And it gets very specific as well.
- 14:01The one that probably people know best in the Python space is awesome-python.com, which is
- 14:07really general, right?
- 14:08I mean, there's Flask stuff and FastAPI stuff.
- 14:10There's zillions of other areas.
- 14:13And then there's all these offshoots like yours around FastAPI and Stump for Flask and
- 14:17so on.
- 14:18Cool.
- 14:18So when did you create your awesome FastAPI?
- 14:22It can't be more than two years ago, right?
- 14:24Yeah, I would say.
- 14:26How long FastAPIs?
- 14:27It must be like a year old, I would say.
- 14:30I can't remember when we launched the FastAPI course on Test Driven, but it was like right
- 14:35around the same time.
- 14:36I think the list probably actually came out before that because the first blog posts on
- 14:40FastAPI came out in January of 2020.
- 14:43So it was definitely after that.
- 14:44Yeah, really cool.
- 14:46Well, and I think, you know, it's FastAPI being around two years old.
- 14:49It takes a little while for these extra libraries to build up around it, right?
- 14:53And I definitely think it's gaining momentum.
- 14:56It was for the first time it showed up on, I think it was the PSF JetBrains survey for
- 15:012020.
- 15:01And I went straight to number three as the most popular web framework.
- 15:05It was really quite interesting how popular it, how quickly it became popular.
- 15:09To me, it's because it brings together these little pieces, each one that is kind of a neat,
- 15:15new modern Python idea, like type hints, like Pydantic, like async and await, all those things.
- 15:21And you just bring it all together and wanting to go, yeah, this has all the things that I
- 15:24care about.
- 15:24This is cool.
- 15:25All right.
- 15:26So your awesome list is broken down into a bunch of different categories, like third-party
- 15:30extensions, and then resources, including, say, a podcast episode like this one, and so on,
- 15:36hosting, and so on.
- 15:39So what I thought it'd be fun to do is let's just maybe go through some of those sections
- 15:42and highlight a couple of the tools or extensions or whatever that are really neat.
- 15:47Yeah, that sounds great.
- 15:49How about the FastAPI admin for the first one?
- 15:51One of the reasons why I did create this is mainly for these third-party extensions for
- 15:56listing these.
- 15:57I think it's kind of Django packages.org really aggregates them really well for, you know,
- 16:02obviously for Django.
- 16:03I don't think there is one anymore for Flask.
- 16:06The main Flask docs used to have a list, but it just got out of control.
- 16:09Yeah.
- 16:10But I think one of the powerful things is definitely the ecosystem and like these extensions.
- 16:14So I thought like someone's got to like start this, so.
- 16:17Fantastic.
- 16:18All right.
- 16:18So the first one I think is pretty interesting is this FastAPI admin.
- 16:22Tell us about this.
- 16:23Yeah.
- 16:23So, I mean, if you're familiar with Django, like one of the powerful things that you get
- 16:27from Django right out of the box is a nice CRUD admin where you can interact with your
- 16:33models, your database models in sort of like a CRUD GUI-like fashion.
- 16:37And so you can add data, all of sort of the CRUD functionality right out of the box.
- 16:41So you don't have to jump into SQL.
- 16:43So yeah, this just like mimics sort of that same sort of behavior.
- 16:46Very cool.
- 16:47Very cool.
- 16:48Yeah.
- 16:48That's one of the main features of Django that I would see people using it for.
- 16:52Yeah.
- 16:52So the idea is basically if I want to create users or mess with other tables, like here
- 16:58they have products and categories and it's just like a grid type thing to add new ones,
- 17:03edit existing ones, right?
- 17:04Yeah.
- 17:04Yeah.
- 17:05It's very straightforward, but yeah, it's not like there's not really too much to say about
- 17:08it.
- 17:08It's not some super sexy interface or anything like that, but it is like, it just saves a
- 17:12lot of time.
- 17:13Yeah.
- 17:13Like one of the main features of the newer Django 3.2 maybe was that there's now templating
- 17:18for its admin stuff to make it look all super cool.
- 17:20Yeah.
- 17:21But to be honest, I think one of the really important things is to make it easy for people
- 17:25to get started.
- 17:26And you know, for me, if I had to build a little admin backend thing like this, like, all right,
- 17:30well, there's half a day.
- 17:31Got to do that to add in.
- 17:33But if you're starting new and you're like, okay, I got this page showing, but now I need
- 17:37to edit them.
- 17:37Oh no.
- 17:38Like this is going to be such a pain, right?
- 17:40Having something like this, you can just plug in.
- 17:43It'd be really helpful to say, oh, actually maybe I will choose FastAPI over a Django
- 17:48rest framework, for example, potentially because it might have an admin, right?
- 17:51Yeah.
- 17:52I think one of the negatives about this, and this is one of the negatives with Django is
- 17:55a lot of people use it for stuff that it's not intended to be used for.
- 17:59Like they try and create, like, you know, make a consumer facing version of it.
- 18:03I think that's partly the impetus for like the templates is to be able to do more stuff
- 18:07like that, which I think that is not, then you have to make everyone sort of an admin.
- 18:11I think that's a bad practice.
- 18:12Yeah.
- 18:12It might lead to some problems.
- 18:14Yeah.
- 18:15Yeah.
- 18:16Yeah.
- 18:17Joe out there on the live stream says, does this include identity?
- 18:22Like, can I get a, I'm guessing a restricted admin backend?
- 18:26Yeah.
- 18:26I'm not sure.
- 18:27We are going to talk about other things that do include identity.
- 18:30And I suspect, I don't know, I haven't plugged in, but there's probably some point where you
- 18:34write some bit of API endpoint, maybe.
- 18:38I don't know.
- 18:39There's got to be a way where you restrict access to it.
- 18:42Yeah.
- 18:42It does have admin secret here.
- 18:44Maybe that's it.
- 18:45I mean, if it works, I haven't used this particular one.
- 18:48I don't use Tortoise in production.
- 18:50Last I looked at this, it didn't work with any other ORMs besides Tortoise.
- 18:55But I know like the, if it's built similar to the, or designed like the Django ORM, the
- 18:59Django ORM doesn't have like a concept of permissions.
- 19:01So it's just, it has like a super user.
- 19:04And so if you're super user access, you get access to it.
- 19:06So there's not really any, I think there's probably maybe some extensions you can use to
- 19:09like limit access.
- 19:10But yeah.
- 19:11Yeah.
- 19:11It looks like permission true.
- 19:13Maybe there is like a concept of permissions here.
- 19:15So I'm thinking there's two places where you can put a little bit of protection here.
- 19:19One is this, where you say the URL is slash admin.
- 19:22The URL could be slash UUID out of some insane length, right?
- 19:28So it's not very guessable.
- 19:29Yeah.
- 19:30And then this app secret, I suspect is like, what is the secret?
- 19:33You know, knock, knock, what's the magic word sort of thing.
- 19:35And there's just one login for it.
- 19:36But for the right type of app, that's probably good enough.
- 19:39Yeah.
- 19:40You would definitely want to change that URL in production.
- 19:41You don't want the forward slash admin.
- 19:43People are just always poking for stuff like that.
- 19:45Yeah.
- 19:46I don't know if you've ever, yeah, I'm sure you've done it.
- 19:49And I don't know if people out there in the audience have ever done this, but if you haven't,
- 19:52it's shocking.
- 19:54If you go and you just tail the log of your site, like the main request log, you'll just
- 19:59see like requests for all sorts of like weird, unrelated stuff.
- 20:03People just trying to guess to see if it exists.
- 20:05Like there's all sorts of requests for like WP admin.
- 20:08Yeah.
- 20:09Dot PHP on my site.
- 20:12And it's written in Python.
- 20:13It has no admin thing like that whatsoever.
- 20:15But people are just going, is there this type of, can I get and try a default password against
- 20:20a PHP admin backend or try that for a Joomla backend and just start jamming on those things.
- 20:27Right.
- 20:27And so having that URL, something that's just not default, while it's not a big piece of
- 20:32security, it dissuades the bots.
- 20:34I think.
- 20:35Yeah.
- 20:35Yeah.
- 20:36Keeps the honest people honest.
- 20:37Exactly.
- 20:38You want to hack, you got to do it for real.
- 20:39Okay.
- 20:40Let's talk about authentication.
- 20:43There's a whole section on different types of things here, right?
- 20:45Yeah.
- 20:46So the one that I like the best or the one that I've used the most, I guess I'd say is
- 20:50FastAPI users.
- 20:51Okay.
- 20:51And I think that's the most popular one.
- 20:54Yeah.
- 20:54Yeah.
- 20:55This is it.
- 20:55So it uses all, like it uses Jot based auth, but you can also sort of like, you can store
- 21:00your Jot wherever you want.
- 21:01But this also has like a session, you know, capability built into it where you can store
- 21:06the Jot in a cookie.
- 21:07Okay.
- 21:08Because a lot of times, you know, people are storing Jots and local storage, which could
- 21:11lead to XSS type attacks or like open you up to like some.
- 21:15Yeah.
- 21:16XSS or cross-site script or I always get those mixed up.
- 21:20But yeah, I thought that was cool.
- 21:22You don't see that a lot in like sort of like libraries that are like Jot based.
- 21:25Yeah.
- 21:25That's cool.
- 21:26Yeah.
- 21:26It has either a cookie auth or a Jot auth backend, which is cool.
- 21:30And it also supports different ORMs.
- 21:32So if you'd like SeekwAlchemy, you can do that.
- 21:35If you'd like MongoDB, you can do that.
- 21:37Cortis or ORMR, which I haven't actually heard of before, but we'll probably talk about it in
- 21:42a minute anyway.
- 21:42But yeah, quite neat.
- 21:44And also OAuth 2.
- 21:46Yeah.
- 21:46So this is quite neat.
- 21:48If you want to plug it in, it looks like a bunch of people have contributed to it.
- 21:51So it looks pretty lively.
- 21:53Yeah.
- 21:53It's very popular.
- 21:54Yeah.
- 21:54I mean, one thing people might want to check out is the sneak package advisor.
- 21:59Have you seen this?
- 21:59Mm-hmm.
- 22:00Over here.
- 22:01And you can put all sorts of different packages in here.
- 22:04So if you're like, ah, this one or that one, you could actually pull it up and have it tell
- 22:08you, maybe not always that quickly, the health of the community, like how popular is it?
- 22:13How healthy is its maintenance and its security and its sustainability and so on?
- 22:17So if you're like, oh, I got these two or three extensions that might be doing the same
- 22:20thing, it might be worth throwing into this sneak package advisor and get a sense for like,
- 22:24ah, this one seems a little stronger in terms of liveliness.
- 22:27Is the popularity score, is it based on similar packages or just like kind of global?
- 22:31Yeah.
- 22:32That's a good question.
- 22:33Because I can't imagine that there'd be a more popular off library for FastAPI.
- 22:38I think it's global.
- 22:40I'm pretty sure it's like a logarithmic global type thing because yeah, right.
- 22:45This is probably the most popular one.
- 22:46So what's going to beat it, right?
- 22:47But it's only 798 stars relative to like Flask users or something like that.
- 22:53Right.
- 22:53Yeah.
- 22:54Yeah.
- 22:54I'd have to look and actually see.
- 22:55It does like show you similar packages if you can find, sometimes it'll say, here's some
- 23:00other stuff that's like it.
- 23:01But anyway, I think that might be something to like bring together with just awesome lists
- 23:05in general.
- 23:05Right.
- 23:06And that's, give me a chance to check these out and see how they're doing.
- 23:08You've also got Flask, no, FastAPI login based on Flask login.
- 23:13They're both two similar and both words in the same place.
- 23:16Yeah.
- 23:17Yeah.
- 23:17Cloud Auth, which is kind of cool.
- 23:19So like using Auth0 or AWS Cognito or things like that.
- 23:25If you're doing that anyway, that might be nice.
- 23:27Yeah.
- 23:27Auth0, they just got bought by somebody.
- 23:30I feel like Google or something like that.
- 23:32Facebook.
- 23:32Yeah.
- 23:33I think they might've.
- 23:34Yeah.
- 23:34I feel like they bought something else and then, you know, little fish, big fish, whale.
- 23:39Okta.
- 23:40I think Okta just bought them.
- 23:41Yes.
- 23:42That's right.
- 23:42It was Okta.
- 23:42That's right.
- 23:43Yeah.
- 23:43Another one I wanted to throw out there while we're in this section that I don't see here
- 23:46and I don't see anything that does this.
- 23:48Possibly.
- 23:49Let's look at FastAPI security.
- 23:51Maybe this one does.
- 23:52It's not super documented over there.
- 23:55I feel like this throws some of the permissions in there that you would really want, but a place
- 24:01called.
- 24:01Like OpenAPI type stuff?
- 24:03More like the general OWASP stuff.
- 24:07If you check out secure, just how did they get this as the modern IPI package name?
- 24:14Just the word secure.
- 24:16But this one, it doesn't say that it plugs in with FastAPI, but it plugs in with Flask
- 24:22and Django and Pyramid and Court and Responder and Starlet.
- 24:26And Starlette is the foundation.
- 24:27So I think that it would actually.
- 24:29And what it does is it does things like it sets all the default header behaviors like that
- 24:35the frame, you can't embed somebody else's, your site into somebody else's site.
- 24:40And that cross-site scripting protection is set and certain types of cache policies and
- 24:46whatnot.
- 24:46And just by doing like one line of code over on against it, one or two lines, it'll automatically
- 24:52just like wrap every request with one of those.
- 24:54So that might also be interesting to think about in this regard.
- 24:58Yeah.
- 24:58Those headers can get confusing, especially if you're using like a single page application.
- 25:02You have to, if you're trying to use cookies or some sort of like session based off or whatever
- 25:08at the same time.
- 25:09Yeah.
- 25:09Like it can get pretty complex on those headers.
- 25:12So yeah, that seems like a cool package.
- 25:13Yeah.
- 25:14And if something new comes out that should be added that you don't pay attention to, but
- 25:17you happen to upgrade your package, maybe it'll bring like the new best practice along.
- 25:21Right?
- 25:22Yeah.
- 25:22Okay.
- 25:22So that's authentication.
- 25:23Databases.
- 25:24You have it broken down into ORMs, query builders, ODMs, which is for document databases, but it
- 25:30looks like a quick scan that document equal equal MongoDB for the moment here.
- 25:34Yeah.
- 25:35And then there's other, which like JSON exchange and whatnot.
- 25:39Let's talk, let's talk ORMs first.
- 25:41Big, like you pointed out, big news for SQLAlchemy, right?
- 25:44Yeah.
- 25:44SQLAlchemy 1.4.
- 25:46It was either last week or the week before.
- 25:48The change actually broke FastAPI or actually broke the FLAS course because it requires the
- 25:54database URI to have PostgresQL as the name rather than just Postgres.
- 25:58And so, you know, that broke the course.
- 26:00So a little annoying, but you know.
- 26:02Yeah.
- 26:03And it broke my courses too.
- 26:05It broke one of my FastAPI courses because we were using async.
- 26:08We were using the new one, the async one, but then they said, well, you're using a driver
- 26:12that doesn't support async.
- 26:13So we're going to throw an exception instead of just work more slowly.
- 26:17And like, ah, so.
- 26:18Yeah.
- 26:18Again, you had to put like a separate different driver in there and so on.
- 26:21So.
- 26:22Yeah.
- 26:22Yeah.
- 26:22So we find out sometimes the hard way about these releases, but.
- 26:25Yeah.
- 26:25So what's the big deal with SQLAlchemy?
- 26:27And then we got the SQLAlchemy plug in here.
- 26:30Yeah.
- 26:30Let's see.
- 26:31So, I mean, I haven't updated this like for specifically for like anything new with
- 26:35SQLAlchemy.
- 26:36So yeah, there's that FastAPI SQLAlchemy.
- 26:38That'd be interesting to take a look at that one to see if like, have there been any updates
- 26:42since SQLAlchemy new one has been released?
- 26:44It looks like no.
- 26:46Looks like it hasn't been touched yet.
- 26:47Yeah.
- 26:48So maybe if you're looking to contribute, maybe there's something to be done here because
- 26:51SQLAlchemy used to not support async.
- 26:53The big thing with the SQLAlchemy 1.4, there's stuff with changes in the API to sort of move
- 26:58to something new.
- 26:59But the big one that's probably relevant here is SQLAlchemy now as of 1.4 supports
- 27:05async and await.
- 27:05Like async, await, execute this query type of thing and give me the objects back.
- 27:11And you might not care at all about that.
- 27:13But if you're using async and await view or API endpoints in FastAPI, but you want to use
- 27:18SQLAlchemy, well, there goes your async, right?
- 27:20It's gone.
- 27:21Because one of the most important things to await upon is the database.
- 27:24And so now the new SQLAlchemy has that support.
- 27:27And I'm guessing this one, it probably doesn't support that, right?
- 27:30Because it just, it didn't exist.
- 27:31But yeah, so cool.
- 27:33Yeah.
- 27:33I'm not exactly sure.
- 27:34I'm sure it won't work because the sample right here is exactly the same code I had that
- 27:38broke.
- 27:38So it's not going to work.
- 27:40But it also is very possible to be quickly and easily updatable.
- 27:44I don't know.
- 27:44But people can check that out.
- 27:46I guess another one you've mentioned earlier is Tortoise Aurium.
- 27:49I haven't really done anything with Tortoise.
- 27:50What's the story?
- 27:51Like databases are supposed to be fast and here's the turtle going on.
- 27:54Yeah.
- 27:57I mean, naming is tough, right?
- 27:58Exactly.
- 28:00I would say like Tortoise is probably the most popular one or like just the one that I've
- 28:05like seen the most use out of in terms of seeing a lot of FastAPI projects.
- 28:09And so, yeah, I think Tortoise is one that's like leveraged a lot.
- 28:12Honestly, people use SQLAlchemy probably more than anything else.
- 28:16And they just like don't deal with async type stuff.
- 28:18But if you want async await, then yeah, I mean, Tortoise definitely has quite a bit of
- 28:22support there.
- 28:23Yeah.
- 28:23You've got Honi ORM, Tortoise ORM, PeeWee.
- 28:27I know PeeWee has an async version.
- 28:28I know the Django people are working on an async ORM story, but it's not there yet.
- 28:34SQLAlchemy just got it.
- 28:35One of the things I like about this is they put just what seems like a pretty fair graph
- 28:41comparing all the different ORMs in terms of performance.
- 28:44And Tortoise ORM comes up pretty nice on like single inserts and the whole updates.
- 28:50But there's also places where it's slower than other stuff.
- 28:53And they're just like, we're going to put it all up there and if you find it useful,
- 28:55here's what you get.
- 28:56And Tortoise is similar to the Django ORM in the sense that it uses an active record type
- 29:01approach, more similar to PeeWee.
- 29:03Whereas SQLAlchemy uses the Data Mapper approach, I believe.
- 29:07Yeah.
- 29:07The unit of work style.
- 29:08Yeah.
- 29:09Yeah.
- 29:09Yeah.
- 29:10And that's confusing for people because you've got to create the session, then you do all the
- 29:13stuff and then you call commit if you want to make changes.
- 29:15And it's not that hard to deal with, but it is one of those things.
- 29:19You're just like, why?
- 29:19Where do I get a hold of the session?
- 29:21If I got a hold of the objects and I want to update it, like I do find the active record
- 29:24stuff for simple cases, pretty handy.
- 29:26Right.
- 29:27And it comes from Django as well in that style.
- 29:29Yeah.
- 29:30So it'd be real familiar.
- 29:31Yeah.
- 29:32Yeah.
- 29:32Very cool.
- 29:33Joe also out there says, what's the most popular database to use with FastAPI?
- 29:37Postgres, ExpressJS, Mongo maybe is like another example of a pairing.
- 29:43Yeah.
- 29:43I would say Postgres.
- 29:44Yeah.
- 29:45I think generally speaking, you're talking Python, it's Postgres if you're relational,
- 29:49MongoDB if you're not.
- 29:50That seems to be like the story.
- 29:52The important thing here is that you may care about async and await.
- 29:56So then that limits the way in which you can talk to the things, but both Postgres and MongoDB
- 30:00have really good async stories.
- 30:02So I think that still holds for FastAPI.
- 30:04Does SQLite have any sort, like, I don't know if you know this offhand, if SQLite has any
- 30:09sort of async support?
- 30:10It doesn't, I don't think the real way you access it has important behaviors that are
- 30:15any different, but there's a new driver that allows it to integrate with an async event
- 30:21loop, asyncio event loop.
- 30:22So it won't block the loop, but basically it just means there's another thread waiting and
- 30:26you won't get like true scalability, but at least like you're waiting on a query here
- 30:30and an external API there, they can both happen at the same time.
- 30:33But if you have a bunch of database calls, I think it just queues up.
- 30:36Yeah.
- 30:36Cool.
- 30:37All right.
- 30:38So Portis Orem, useful because down here somewhere we probably have an await, I'm guessing.
- 30:44Oh, here's the, you asked about the SQLite.
- 30:46Here's the SQLite library.
- 30:47aiosqlite is the one that Mike Bayer was recommending.
- 30:51Yeah.
- 30:51But down here you can do, you know, await, create object, await, filter, object.first,
- 30:57exactly what you want for simple access to those APIs.
- 31:01Yeah.
- 31:02I mean, if you're just doing like a quick select or delete or whatever it is, you're probably
- 31:06not going to get any sort of performance boost.
- 31:07But if you're doing for whatever reason, if you're doing a lot of different queries in
- 31:10a route handler that are not dependent on each other, or if you're like, you're doing more
- 31:14than one query that is very expensive.
- 31:17Yeah.
- 31:17That's also not dependent on each other.
- 31:18Then you might get a performance boost like this.
- 31:20Basically the worse your database is, the better.
- 31:23Yeah, there you go.
- 31:26The more of a benefit you're going to get.
- 31:27Because async await is all about scaling, weighting, and latency.
- 31:31So the more latency your database has, because you're doing slow queries or it's like cloud
- 31:37and far away or whatever, you're going to benefit.
- 31:38But if it's a one millisecond response time, who knows?
- 31:42All right.
- 31:42You also mentioned Gino, G-I-N-O.
- 31:44This is like literally the first time I'm seeing it.
- 31:47What is this?
- 31:47Yeah.
- 31:47So Gino is from what I understand, it's more of like a full ecosystem.
- 31:52Okay.
- 31:53So Gino is not ORM, it's like asynchronous ORM.
- 31:57So, but yeah, I mean, it is an ORM, but it also like, I believe there's a generator in
- 32:02here where you can build like a scaffold out an entire like FastAPI app, sort of like based
- 32:08on your models.
- 32:09Yeah.
- 32:09Interesting.
- 32:10Similar to like how the Rails like skeleton command works.
- 32:13I don't know if you're familiar with that at all.
- 32:14You can like scaffold out like a quick CRUD app.
- 32:16Okay, cool.
- 32:17And it's one of these recursive acronyms.
- 32:19Yeah, it is.
- 32:20Yeah.
- 32:20It talks about having an async API on top of SQLAlchemy.
- 32:23I wonder how much importance that will have these days.
- 32:26But yeah, it sounds like it has other stuff.
- 32:28Like you talked about the whole community and stuff.
- 32:30So very cool.
- 32:31What else is in here that we should talk about?
- 32:34There's a couple other ORMs people can look at.
- 32:36Query builders.
- 32:37I've used databases quite a bit.
- 32:39Okay.
- 32:39One difficult thing about databases is Googling.
- 32:42It is like, if you try and Google any sort of like errors around databases, it's, you
- 32:46know, like knows what's going to come up.
- 32:48But yeah, I mean, this is like one that's...
- 32:50Was this originally done by Kenneth Wright and then handed off?
- 32:53Or is this different?
- 32:54You know, I'm not sure.
- 32:55I think it's by the same team that does Starlet.
- 32:58Yeah.
- 32:59Yeah.
- 32:59Yeah.
- 32:59Tom Christie.
- 33:00That's escaped me there.
- 33:01Yeah.
- 33:01Yeah.
- 33:02Yeah.
- 33:02Definitely.
- 33:02Cool.
- 33:03He does a lot of stuff.
- 33:04Yeah.
- 33:05That guy's busy.
- 33:05I've had him on the show before.
- 33:06He's definitely a busy guy.
- 33:08That's awesome.
- 33:08Cool.
- 33:09So it's like a wrapper around SQLAlchemy core that then will give you back proper queries
- 33:14and stuff like that.
- 33:14Yeah.
- 33:15Nice.
- 33:16Okay.
- 33:16ODMs.
- 33:17Just really quick mentions.
- 33:19Since I was recently talking about Beanie on Python Bytes.
- 33:22Beanie is kind of cool.
- 33:23It's an async way to talk to MongoDB, an ODM, object document mapper, because there's no
- 33:29relations.
- 33:30Not really.
- 33:30But what's interesting about that is it's one, it has an async option.
- 33:34And two, it's all about Pydantic.
- 33:35So you're normally you'd have like Django models or SQLAlchemy models.
- 33:39Like the models are Pydantic models that go to and from the database, which has an interesting
- 33:44possibility for integration back into the like return types and stuff that you would
- 33:48have, say for a FastAPI.
- 33:50So anyway, that's if you're into it, that's potentially worth checking out.
- 33:54It's based on Motor, which is the MongoDB official async driver for Python.
- 33:58Yeah.
- 33:58The PR for that one came out, I think last week and I heard about it maybe the week before.
- 34:03So I don't know if that's like a new library, Beanie, but.
- 34:05Yeah.
- 34:06It's quite new because I was talking to Roman Reyes.
- 34:09This is a guy who created this and when he did some stuff on it, I talked about how
- 34:13I thought it was really cool to be using Pydantic models and types, but it needs indexes.
- 34:17And so he actually went and put a whole mechanism in for doing indexes.
- 34:22I got to check them out.
- 34:23I guess that's just the example, but whole way in which you can put indexes in your models
- 34:27and stuff.
- 34:28Yeah.
- 34:28MongoDB index is perfect.
- 34:29So pretty cool that it has that stuff built in.
- 34:32And yeah, it looks like it's coming on strong.
- 34:35So maybe that's a good one.
- 34:36Mongo engine is actually what I use over at Talk Python, but I don't believe it.
- 34:38I don't believe it's async.
- 34:39I have suspicions that will never be async.
- 34:41It's super, super involved and it doesn't seem to be changing real quickly.
- 34:45So I'm guessing that that's kind of where it is.
- 34:47Have you checked out this Pydantic SQLAlchemy?
- 34:49Pydantic to SQLAlchemy?
- 34:51I haven't, no.
- 34:52Tools to convert SQLAlchemy models to Pydantic models.
- 34:55Like I just talked about the benefits of having your database models be Pydantic so they can
- 34:59be on the boundaries, right?
- 35:00Yeah.
- 35:01And maybe this is just like a way to sort of map those over.
- 35:03That's kind of cool.
- 35:04Yeah, that is cool.
- 35:05I did.
- 35:05When I looked at this earlier, one thing I wasn't psyched about, I'd be interested to hear your
- 35:09thoughts on this, Michael.
- 35:10The way that it does this is at runtime, right?
- 35:13So the way you get your SQLAlchemy model, you say, now I'm going to create a Pydantic
- 35:17user from my user by passing it to a function that does probably magic metaprogramming and
- 35:22boom, out comes this type Pydantic user, right?
- 35:25And that's cool.
- 35:25But one thing I don't like about that style is the editors can't be very smart about helping
- 35:32you, right?
- 35:32Like it doesn't know what the heck a Pydantic user can do or can be or autocomplete and
- 35:37all that sort of stuff.
- 35:38So I feel like a lot of these sort of runtime converter things, I don't know.
- 35:43They let the good editors like PyCharm and VS Code down.
- 35:46What do you think?
- 35:46Yeah.
- 35:47I mean, is there a way to look at what it'll convert that down to?
- 35:50It'd be great if you could get it to like spit out.
- 35:52Yeah.
- 35:53The actual model.
- 35:54A code file.
- 35:55You run this one time and then you're like, we're good.
- 35:57Yeah.
- 35:58We're good.
- 35:58I just want a way to go from 20 SQLAlchemy models to 20 Pydantic models and then I'm
- 36:03going to save that code and go with it or something like that would be cool.
- 36:06But I didn't know.
- 36:07It must be cached sort of at some point.
- 36:09So.
- 36:09Yeah.
- 36:10Yeah.
- 36:11That's interesting.
- 36:11Yeah.
- 36:12I do think it's really powerful though, but it's just like, yeah, it's a little tricky
- 36:15to get help with what you're supposed to do.
- 36:16Right.
- 36:16Because otherwise you have two different like model concepts.
- 36:19Like you have your model, like your database model, which is SQLAlchemy.
- 36:22And then you have like sort of like your model, which is more of like a schema.
- 36:24Yeah.
- 36:25But Pydantic calls them models.
- 36:26And so like in my FastAPI code, I call them schemas.
- 36:31So I have like a schemas.py file.
- 36:32And then I have a models.py file, which is the flask.
- 36:35Sorry.
- 36:35I keep saying flask.
- 36:36But the.
- 36:37I know.
- 36:38I was doing it too.
- 36:39It's so hard because they're the same size word and they play a very similar role.
- 36:42Yeah.
- 36:42Yeah.
- 36:43Yeah.
- 36:43Are they sponsoring this?
- 36:46Yeah.
- 36:48Just having them combined together, like would make sense.
- 36:51But yeah, I get what you're saying about like, you don't know exactly what that is.
- 36:54Like until like at runtime.
- 36:55Yeah.
- 36:56If I go to one of those and say dot, it's like, it gives me nothing.
- 36:59Right.
- 37:00Yeah.
- 37:00Yeah.
- 37:01Cool.
- 37:01Yeah.
- 37:01So Joe out there in the live stream says, what would you recommend as a DB driver instead
- 37:05of psycopg two for Postgres and FastAPI?
- 37:08You got a recommendation?
- 37:10Well, like if you're using synchronous, you want to go psycopg two, obviously.
- 37:13But if you're using the async, then it's going to be asyncpg.
- 37:15Yeah.
- 37:16So there's a separate async one.
- 37:18Very cool.
- 37:18All right.
- 37:19Let's talk about, did I just bag on code generators?
- 37:21Let's talk about code generators.
- 37:22Okay.
- 37:24Because they are valuable.
- 37:25One of the things that's super cool, like here I have a, here's a little site I built for
- 37:30a course, weather.talkpython.fm that lets you go and enter a city and it'll tell you literally
- 37:35the real weather right now.
- 37:36Like for now in Portland, it's broken clouds within like a few moments.
- 37:40Right.
- 37:40That's cool.
- 37:41And one of the things that's really nice though, with all these things is you can go to slash
- 37:44docs and you get this cool documentation thing.
- 37:47And that's just where like your Pydantic model kicks in for the JSON schema response and
- 37:52all those cool things.
- 37:53Right.
- 37:53So that's just FastAPI.
- 37:55That's amazing.
- 37:55But the next thing is the FastAPI code generator.
- 37:58Right.
- 37:59So this takes an open API file and then it'll scaffold out your FastAPI app based on that.
- 38:04And so does that do all like the Pydantic models and whatnot?
- 38:07I'm not sure if it does.
- 38:09Or does it just do the endpoints?
- 38:11It seems like it.
- 38:12It says the response model is pets.
- 38:13I think so.
- 38:14From the models import pets.
- 38:16Yeah.
- 38:16Yeah.
- 38:16So you pointed at that documentation, that slash docs that I was just talking about.
- 38:20And you say, here's some API specification.
- 38:23I want a FastAPI server implementation of that.
- 38:25Boom.
- 38:26And you get it, right?
- 38:27So you can sort of do like the document driven development.
- 38:30So then if you want to change your API, you change the open API doc.
- 38:34Exactly.
- 38:34Yeah.
- 38:35You can see right here, it is actually generating the Pydantic models and even the errors that
- 38:40it throws and so on.
- 38:40This is super cool.
- 38:41It even has support for say optional strings and default values versus non-optional strings.
- 38:46I like it.
- 38:47That's cool.
- 38:47I'm not sure I would use it because I don't find myself in a situation where I have that
- 38:51a lot.
- 38:51But if you wanted to do it, it seems like it would be really cool to have.
- 38:54All right.
- 38:55Related to that is the other side of the story.
- 38:58I want to talk to an existing FastAPI.
- 39:00Probably this would work for any open API thing, I would guess.
- 39:04But it says it's for FastAPI.
- 39:07So generate a mypy and IDE friendly API client from an open API spec.
- 39:12This looks cool.
- 39:13Let's see some examples down here.
- 39:15It both supports async and synchronous clients.
- 39:17And I'm guessing it's using the similar example model because we have a pet here as well.
- 39:23So it generates the model, the Pydantic model that you're going to exchange with the server
- 39:26and all sorts of stuff.
- 39:27This is cool.
- 39:28So what does this generate exactly?
- 39:30It's generating a client library to interact with the API?
- 39:32Yeah.
- 39:33So instead of using requests to call the API and just putting bare dictionaries, it will
- 39:39actually generate the Pydantic models and it'll give you the API endpoints as functions instead
- 39:45of just request this URL.
- 39:46Nice.
- 39:47Does that give you like Sphinx documentation and all that too?
- 39:50I have no idea.
- 39:52That would be cool.
- 39:53Yeah.
- 39:54It's super cool though.
- 39:55It shows you how to basically take all that stuff and generate those.
- 39:58And it does say that it generates IDE friendly ones.
- 40:01So it must export those and not do it at runtime, which, you know, those pet, you can see right
- 40:06here, like from client.models import pet.
- 40:08So it generates the Python files and then you consume them instead of at runtime so that you
- 40:13get like autocomplete and type check in and all that.
- 40:16That's cool.
- 40:16Yeah.
- 40:16Teddy out here on the live stream says, what use case would you use FastAPI versus say Django
- 40:23REST framework?
- 40:24It's kind of hard to compare the two.
- 40:25I mean, if you're already using Django, then yeah, obviously go with Django REST framework.
- 40:29But yeah, in terms of Django plus Django REST framework versus FastAPI, as always, it depends.
- 40:36It just depends on what you're doing.
- 40:37It depends on the size of the API.
- 40:39It depends on if you need authentication.
- 40:40It depends if you want like the CRUD admin, you know, type stuff.
- 40:44It depends on what tools you're going to be using to consume the API.
- 40:48You know, if you want something that's tried and true and battle tested, I would go with Django
- 40:52and Django REST framework.
- 40:52If you want to play around with the new hotness and take advantage of, you know, you sync and await
- 40:57and all the cool stuff that's coming out, then maybe check out FastAPI.
- 41:01Yeah, I would certainly say if you already have Django and you're already using it and
- 41:06just want to plug into the same app and just keep rolling, probably just Django REST framework,
- 41:10right?
- 41:10Unless you really want to commit to having multiple apps that you run separately and I don't
- 41:14know, put behind Nginx through URL routing or something like that.
- 41:17Also, you know, how much of the FastAPI features are you going to use, right?
- 41:21If you don't care about async and await and you don't care about the typing very much and
- 41:25you don't care about the documentation, like, well,
- 41:27then it kind of comes down.
- 41:28But if like all of those things are super important to you, maybe breaking that out matters.
- 41:32I don't know.
- 41:32That's kind of my thought as well.
- 41:33Yeah.
- 41:34Also, Galvin Haas asks, best JS front-end framework for FastAPI?
- 41:38I mean, it's kind of open, right?
- 41:39But is there anything that stands out as better?
- 41:42No.
- 41:43I mean, it works well with Vue, React, Angular.
- 41:46Vue.js because it's Vue.js.
- 41:48Cool.
- 41:51All right.
- 41:51Another one here I want to talk about that's super neat is FastAPI Profiler.
- 41:55This looks really cool.
- 41:56So it's middleware.
- 41:57I mean, Ian, you're the Django expert, certainly for the two of us here.
- 42:01Tell me how it works.
- 42:02I know in Pyramid, there's a debug toolbar you can turn on.
- 42:06And then one of the parts of that is show me the profile.
- 42:08Like when I request this page, where was my time spent?
- 42:12Show me my SQLAlchemy queries actually interlaced in there and so on, which is super cool.
- 42:16Django has something like that, right?
- 42:17Yeah.
- 42:17Django has Django debug toolbar.
- 42:19Yeah.
- 42:19You had said it does.
- 42:20Basically, that works with your service side templating to figure out with that specific template or with that specific route, how many different queries did it take to load this view?
- 42:30Right.
- 42:30Find if you got the N plus one problem because you passed this thing and then you're all over touching the lazy loaded properties over and over and over.
- 42:38Something like that, right?
- 42:39It's not going to detect N plus one issues for you, but you should be able to see them.
- 42:43Yeah.
- 42:43If you're like, why do I have a hundred queries on this page instead of two?
- 42:46Like that should jump out at you, right?
- 42:49Yeah.
- 42:49Yeah.
- 42:50So this is, I'm guessing like that.
- 42:52Yeah.
- 42:53I wonder where the output prints out at because like with FastAPI, I usually don't have the server side templating with it.
- 42:58So.
- 42:58Exactly.
- 42:59By default, you don't.
- 43:00Is this like just print out to the terminal or.
- 43:02Yeah.
- 43:02It's worth pointing out that FastAPI does support Jinja.
- 43:05Yeah.
- 43:05But you got to do a little extra work to make it do it.
- 43:08So it says, this is really like a leveraging PI instrument from Joe Rick.
- 43:12And if you scroll down over on their repo, on his repo, there's a bunch of cool output.
- 43:17I think it might even open up.
- 43:20I don't know.
- 43:21I'm not sure exactly where it goes.
- 43:22It might.
- 43:22I think it saves it to like a profile file.
- 43:24So you get this like cool little view of like the profile output here.
- 43:28Even there's like a terminal version, which is, I don't know, like a rich colored terminal version.
- 43:33But there's a bunch of cool graphs and stuff you can get.
- 43:36There's a, I think I saw in here somewhere you can open up some kind of like flame graph as well.
- 43:41Oh, that's cool.
- 43:42Yeah.
- 43:42You can dig into it.
- 43:43So basically anything you can do with PI instrument.
- 43:46I think this is just a middleware wrapper that generates PI instrument stuff for you, which is, that's pretty cool.
- 43:53Yeah.
- 43:53A lot of stuff is super powerful.
- 43:54Like you could probably take some of that stuff and tie it into your integration type test to ensure that, hey, like I built this route.
- 44:01This view takes X amount of time.
- 44:03And like, you know, now I want to throw junior developer on my code.
- 44:06I want to make sure, hey, there's not like any performance loss.
- 44:09And you can like use like some stuff like that to make sure that the number of queries don't all of a sudden triple.
- 44:15Like the load time doesn't all of a sudden triple stuff like that.
- 44:19So tying like that stuff into your test suite is like super powerful.
- 44:23I do that with, there's a library called N plus one that does that very same thing.
- 44:26Oh, interesting.
- 44:27Yeah.
- 44:27Yeah.
- 44:28Very cool.
- 44:28Nice.
- 44:29Heard of it.
- 44:29I haven't used it.
- 44:30Another one I think that stands out is pretty interesting is FastAPI mail.
- 44:34I mean, boring, but sending mail is one of those things that can take forever.
- 44:37Like I had one of these admin parts of my site.
- 44:41I had a way to like send an email to all the people in this class.
- 44:44Go 20 seconds, 30 seconds timed out.
- 44:47And it was going to like thousands of people.
- 44:50And the problem was it had sent hundreds of emails and then it timed out.
- 44:55So how do I resend that without sending a duplicate to the first half?
- 44:59Right.
- 45:00Maintaining the state there.
- 45:01Yeah.
- 45:01Yeah.
- 45:02And like, I don't really, like, it's really hard to go back to figure out everyone who got it, but not.
- 45:06Anyway, it was a huge pain.
- 45:07And I'm like, okay, sending a lot of emails kind of sucks.
- 45:09And so this one FastAPI mail is cool because email is one of those things that's like dreadfully slow.
- 45:16And this allows you to asynchronously send email messages in a super simple way.
- 45:20So you're not using like SendGrid or SES or anything to?
- 45:23At the time, I was using SES at the time.
- 45:26Yeah.
- 45:26Okay.
- 45:27Okay.
- 45:27But I was doing it instead of like doing a bulk send.
- 45:30Yeah.
- 45:30I said, this is a customized email to that person.
- 45:33This is a customized email to that person.
- 45:34And like, I mean, it's fine if I even just set the timeout limit longer or whatever.
- 45:38It would have been fine.
- 45:39What I ended up doing is just putting that in a background queue and just let it go.
- 45:43Like that's how it should have been.
- 45:44It shouldn't have been as part of the request, but I learned the hard way the first time around.
- 45:48I use Celery for that same exact thing.
- 45:50I mean, that just goes right to queue.
- 45:51Yeah.
- 45:51Perfect.
- 45:52Yeah.
- 45:52So this one has an async.
- 45:54This makes, I mean, like you said, doing bulk sending on some kind of background thing is
- 45:59exactly what you should do.
- 46:00But if you're trying to not block your processing and you want to send an email, just one, like,
- 46:05Hey, reset my password, right?
- 46:06That could be a thing you could just do right away.
- 46:08And so here's a way to await sending emails, which is kind of cool.
- 46:11Yeah.
- 46:12If you don't really care too much about what happens to the email, like if you're not too
- 46:16concerned about, Hey, if this doesn't get delivered, it's not a huge deal.
- 46:18I'd say like something like this is fine.
- 46:20If it's more like, you know, there's like any sort of like workflow based on what could
- 46:24happen there, like success, failure, that sort of thing.
- 46:27Like if then this, that type stuff.
- 46:29Yeah.
- 46:29You want to probably look more like towards salary, I would say, but I still think like,
- 46:33if you want to send like just a simple one-off email, maybe it's even to yourself or something
- 46:36like that.
- 46:37I do this like with FastAPI mails.
- 46:39I send myself notifications based on events and like, I don't necessarily need them.
- 46:44Like, you know, I'm not curing cancer here.
- 46:46So if I don't get it, I don't care.
- 46:47Yeah.
- 46:48I have the same thing.
- 46:49I'll just shoot myself messages like, Oh, here's the thing you should probably know about
- 46:52that happened.
- 46:52Very cool.
- 46:53Yeah.
- 46:53I have moved to SendGrid last month or two and really like it.
- 46:57I don't think that's so big.
- 46:58Yeah.
- 46:58Come back to normal size.
- 47:00So let's see, what else have we got here?
- 47:02That's interesting.
- 47:03Then we got the obligatory utils.
- 47:06The catch all right.
- 47:07Everything.
- 47:08Yeah.
- 47:08Well named helpers.py.
- 47:10Exactly.
- 47:12So we got socket IO stuff, plugins, pagination.
- 47:15One I do, two that I'll call quick attention to that I think is our Nate in here.
- 47:20Not, this is not an endorsement or saying I would use it, but I think I can see a real
- 47:24interesting use case.
- 47:24First, the cache one.
- 47:25Yeah.
- 47:26Maybe tell us about this cache one here.
- 47:27Yeah.
- 47:28So I haven't used this one exactly, but it looks like, yeah, it just is probably going
- 47:32to probably cache at the route handler level.
- 47:35And it looks like it's caching the response based on the request parameters inside of Redis.
- 47:41Yeah.
- 47:41You know, it's the one thing that's interesting here that it actually does that I haven't
- 47:45seen in any of these examples yet, but it's certainly a FastAPI thing is it uses dependency
- 47:49injection for the cache.
- 47:51Yeah.
- 47:51Right.
- 47:51So they've got a view method here or API endpoint, I guess, called hello.
- 47:56And then one of the parameters is cache of type Redis cache backend equals the default
- 48:01values depends on Redis cache.
- 48:03So it goes and finds the one instance of that and hands it off.
- 48:06And then it's just like standard Redis value type thing.
- 48:10Like a wait, get the thing.
- 48:12The thing's not there.
- 48:13A wait, set the thing, you know, pretty standard, but it's kind of cool.
- 48:17It was just the simple integration.
- 48:18Yeah.
- 48:18Like dependency injection, I think is a, it's a pretty difficult concept if you look at it
- 48:23from a theoretical standpoint, but it's just like this object here is just taking this other
- 48:29object at runtime, you know, essentially.
- 48:31So it's, yeah, yeah.
- 48:32It's just a way to like sort of split apart sort of your dependencies and it makes testing
- 48:36a whole lot easier.
- 48:37So you don't have to have like mocks all over the place.
- 48:39So you can just switch out like the Redis cache for like in memory cache or, you know,
- 48:43something like that.
- 48:44Yeah.
- 48:44If you could pass in anything that has a get and a set, you're good.
- 48:47Right?
- 48:48Yeah.
- 48:50I think because of dependency injection, FastAPI, like you don't necessarily have to leverage
- 48:55it, but I think that if you are, it does take a little, like you have to be a little bit
- 48:59more of a seasoned developer, I'd say than someone that's just picking up Flask.
- 49:02Yeah.
- 49:03I totally agree about that.
- 49:04Dependency injection is one of those things.
- 49:05It's like, Oh, this is really cool.
- 49:06And it makes things simpler.
- 49:07And why is it so complicated?
- 49:09What just happened?
- 49:10You know?
- 49:11And I'm thinking more of like.
- 49:12Although I don't know when you start looking at Flask global objects.
- 49:15Yeah.
- 49:15Yeah.
- 49:15Yeah.
- 49:16Yeah.
- 49:16That's complex.
- 49:18That's true.
- 49:18I'm thinking more of like the static languages like Java or C#, where you've got an
- 49:22I and I and interface one of these, and then a bunch of those registered.
- 49:26And then like, which one did it actually like, what concrete type am I even working with?
- 49:29Like, like it can get, I don't know.
- 49:31People can over pattern it, I guess.
- 49:33All right.
- 49:33Speaking of not over pattern it, let's check this out.
- 49:35So I was talking at the Python at the San Francisco Python meetup last night.
- 49:40Someone asked me, Hey, is there a way in FastAPI to just like, no, this was my office hours
- 49:46same day though.
- 49:47And also video meeting.
- 49:48Anyway, somebody said, can I just take a database and make it like an API?
- 49:52Yes.
- 49:53This FastAPI dash CRUD router.
- 49:56It sounds amazing, right?
- 49:57So basically what you do is you tell it your models and the schemas, and then it just creates
- 50:04all these API endpoints to do restful things to that table through the model.
- 50:09So I have a get slash potato, like potato was the model, get slash potato that'll list
- 50:14them all.
- 50:14Post a potato to slash potato will create one, delete a potato, we'll get rid of all of them,
- 50:21delete potato slash ID will delete that one and so on.
- 50:24So it just turns this into basically a series of FastAPI endpoints that are all the restful
- 50:31behaviors against your schemas.
- 50:33What do you think?
- 50:33You don't see it delete all very often.
- 50:35Nope.
- 50:36A little Bobby table.
- 50:36I wonder if this is how Gino might be leveraging something similar to this.
- 50:40Yeah.
- 50:40To me, this feels overexposed.
- 50:43But if it's like something simple, something internal, probably, maybe it makes sense to
- 50:48just go like, I just need to do that.
- 50:50But from JavaScript, we just turn that on.
- 50:52But like I said, I probably would not turn that on because it scares me.
- 50:55Let's see rate limiting.
- 50:57There's a couple of rate limiting things that are cool here.
- 50:59Slow API.
- 51:01And then what was the other one?
- 51:03FastAPI limiter.
- 51:04Those are cool.
- 51:04And that's pretty much it for the standard docs, right?
- 51:08Or standard extensions.
- 51:09And we've got the documentation.
- 51:10We've got some external resources, like some of the things that you have over at Test Driven.
- 51:15The podcasts that you mentioned are somehow someone linked the Python bytes thing I had
- 51:20with Sebastian, I believe.
- 51:21I'm starting to get to the point with this awesome list where it's like, I'm going to probably
- 51:25have to like curate the tutorials a little bit more because there's so many like new tutorials.
- 51:29Like when I started this, there were like three or four tutorials.
- 51:32And now, you know, there's like hundreds of them just based on the popularity of the framework.
- 51:37So getting a little bit smarter with curating the tutorials, like because you don't need 15
- 51:42different tutorials, like showing how to build a CRUD app, you know, that sort of thing.
- 51:45I did find this FastAPI for Flask users super helpful because what it does, it says, you want
- 51:51to do this in Flask.
- 51:52Here's the FastAPI version.
- 51:54You want to do this in Flask.
- 51:55Here's the FastAPI version.
- 51:56And it just does like simple stuff.
- 51:58Like I want to, let me see if I can find some examples.
- 52:00I want to create a method that does post.
- 52:03Here's what it looks like there.
- 52:04Here's what it looks like in FastAPI and just side by side sort of a cookbook type of thing.
- 52:09I like that a lot.
- 52:10So yeah, that's a good one.
- 52:11All right.
- 52:12We're just out a few moments left.
- 52:14I don't think we have time to go through all the tutorials.
- 52:16And honestly, I haven't researched them enough to talk about it.
- 52:18A couple of talks, which is cool.
- 52:20A couple of videos.
- 52:21Well, I'm sure there's probably some more out there on the internet that could overwhelm your
- 52:25list at this point.
- 52:26Courses, you and I, we've got to lock on it.
- 52:28Yeah, I recognize a few of those names, right?
- 52:31Tell us about the courses.
- 52:32Exactly, man.
- 52:34There's three courses.
- 52:35And now let's talk about yours first.
- 52:37Yeah.
- 52:37So my course focuses on building just a RESTful API.
- 52:41It also focuses on heavily, obviously, on test-driven development.
- 52:45I also focus on code formatting type tools like Black and Playgate and stuff like that.
- 52:52And so I also go into CI, you know, CD with GitHub Actions.
- 52:55And then everything is Dockerized.
- 52:57And then you also deploy it to Heroku.
- 52:58Yeah, super cool.
- 53:00And I saw that both you and I are also sponsors of the FastAPI project in GitHub, which is
- 53:05pretty cool.
- 53:05Yeah, you're gold.
- 53:06I'm silver.
- 53:06I assume you donate a few more bucks a month then.
- 53:09I guess so.
- 53:10I guess so.
- 53:11But yeah, how does that work?
- 53:12Here's the thing.
- 53:13I don't call it out to like say, oh, look how cool we are.
- 53:15I mean, I do see it on the screen here, which sort of brought it to mind.
- 53:17But there's so many companies out there who are building major parts of their businesses
- 53:22on top of FastAPI and other projects.
- 53:25Like GitHub has such a simple way to go press the sponsor button, support those things and
- 53:29make sure they have a nice, vibrant ecosystem, people backing them.
- 53:34You know, if we can do it, surely.
- 53:35Bank of America, Chase, Microsoft, Google, get in there.
- 53:40Anyway, that was more my pitch there.
- 53:43Yeah, I think more companies need to like sort of call that just the cost of doing business.
- 53:48It's like we're resting on the shoulders of all these giants.
- 53:50Like we have this other remote team over here that we know nothing about.
- 53:54And yet we're leveraging, you know, this team.
- 53:56And not all projects are like curated or maintained by Google and Facebook either.
- 54:00And so, yeah, I think it's I'm not trying to like push this in people's face.
- 54:04Like, hey, I'm better than you.
- 54:05I'm just trying to say, hey, if I can do this, then yeah, I think a lot of companies should
- 54:10be thinking more and more about doing stuff like this.
- 54:12I totally agree.
- 54:14I think they should definitely see.
- 54:16We critically depend upon these technologies.
- 54:18Let's make sure that we do a little bit to support them.
- 54:20Yeah.
- 54:21Because a little bit for a lot of these companies would dramatically change it, right?
- 54:24If if Flask got two million dollars a year, that would fundamentally change that organization.
- 54:29And yet, given how many people use it, it would be nothing to the companies.
- 54:33And like it wouldn't even show up almost.
- 54:35Right.
- 54:35So I know there's a lot of complexity about how companies justify money and where it goes on
- 54:40the balance sheet and all that.
- 54:41But still, people encourage your companies to do stuff like that.
- 54:43All right.
- 54:44So this is a really cool course.
- 54:45I love the Docker angle of it as well.
- 54:48So nice.
- 54:49Test driven.
- 54:49How's that work?
- 54:50What's the story with that part?
- 54:52Test driven development?
- 54:53Like we're like the site?
- 54:54No, I mean, just like, like, how's that plug in with like FastAPI?
- 54:57Like, are you doing like this dependency injection type stuff?
- 54:59I show I show like I show both like sort of ways how to do tests.
- 55:03Like I show like how to mock everything.
- 55:05So if you want to like speed like your tests up, but I don't actually go into like all the
- 55:08dependency injection type stuff with the ORM.
- 55:11It's a little bit too complex, I would say, especially with how Tortoise is set up.
- 55:15But yeah, I showed basically two different types of tests.
- 55:18Like you can test it sort of like integration, you know, style where it's actually hitting the
- 55:23database or like you're using monkey patch to sort of mock out sort of the actual the
- 55:27database layer.
- 55:28Yeah, that sounds super cool and useful.
- 55:30It's also like what differs like between our two courses is like minor text based and yours
- 55:35are all video based.
- 55:36Yeah, all video based.
- 55:37Yes.
- 55:38Yeah.
- 55:38I mean, there's source code on GitHub that's text, but not really.
- 55:41So yours are both then.
- 55:43Damn.
- 55:43No, no, no, no, no, no.
- 55:45Not really.
- 55:45It's all video based.
- 55:46So I didn't plan this ahead.
- 55:48I looked down like, wow, you have my two courses, which is super cool.
- 55:51So I have two courses on here, modern APIs with FastAPI.
- 55:54And the idea is just like, let's build an API that uses Pydantic, that uses async and await,
- 56:00that has real live data, stuff like that.
- 56:02And sort of the fundamentals of the FastAPI world.
- 56:06And then the other one is full web apps with FastAPI.
- 56:08So if you had already a flask app or something like that, and you're like, I'd like to add
- 56:14some additional features to it.
- 56:15You could just plug in some API type thing to it, some RESTful API extension.
- 56:20And it goes.
- 56:21But if you're starting from scratch, you might create an API with FastAPI.
- 56:25Then you're like, well, I also wanted some HTML stuff.
- 56:27Could I actually add like a server side HTML story around this as well?
- 56:33So it shows you how to like create users, submit forms, validate data, use templates, all that
- 56:39kind of stuff.
- 56:39So kind of like you need a little bit more on the server side, a little more on the website,
- 56:43not just pure API, then like that would tell you how to do that.
- 56:46So you're using server side templating for that?
- 56:48Yeah, either Jinja2 or Chameleon, pick your pick.
- 56:52Yeah.
- 56:52Basically, we recreate IPI.org and FastAPI.
- 56:55So you're not doing a single page app and with you and React and Dockerizing and both?
- 57:00No, exactly.
- 57:01Well, why not?
- 57:02I know, I know.
- 57:04You're not doing it right.
- 57:05I'm totally doing it wrong, though.
- 57:06I definitely would not be cool in the JavaScript world.
- 57:08You know, it's not that I'm super against that, but I think that there's still a lot of
- 57:12value to having some of the stuff on server side.
- 57:14And then I don't think everything has to be a spa, right?
- 57:17Single page app.
- 57:18Yeah, I was being sarcastic because that's definitely like...
- 57:20I know you are.
- 57:20I know you are.
- 57:21Yeah.
- 57:21So we were talking right before this.
- 57:25We realized we have our three classes here, our courses here, that we wanted to do some
- 57:29kind of special for people and a way also to give back to FastAPI.
- 57:33I want to tell people what we came up with.
- 57:35Like this was not pre-planned until we were like, oh, wait, why don't we, you know, we're
- 57:37looking at these three things here.
- 57:38Let's do something.
- 57:40We decided that we're going to sell these three classes as a bundle, not one off.
- 57:45But if you want to take all three of these classes, we'll give you 50% off the price and
- 57:4950% of that 50%, 50% of what you pay us will go to support FastAPI directly.
- 57:56So we're going to try to do a little fundraiser for FastAPI and do a little awareness for our
- 58:01courses.
- 58:01Yeah.
- 58:02And the courses kind of build into each other too.
- 58:03Like your core, your modern API is a FastAPI.
- 58:06I would recommend taking that first.
- 58:08And then sort of my course takes that to the next level.
- 58:10And then if you want to learn how to like, hey, I want to buy routes to have like server
- 58:15side templating so I can like serve up something to interact with the API and add the full web
- 58:19app course on top of that.
- 58:20Yeah, I think so.
- 58:21So we don't have, because it's your course and my courses, different platforms, all that,
- 58:26we don't have an official way to make this happen.
- 58:28So they just send you an email.
- 58:29Yeah.
- 58:30And say, hey, I'd like to do this bundle thing.
- 58:32And we'll just make it happen behind the scenes, right?
- 58:34Yeah.
- 58:35Just shoot me a quick email, michael.testroom.io.
- 58:38And I'll do all the hard work and link all that together and send and put down, probably
- 58:43just use Stripe for that.
- 58:44Just send out a quick Stripe invoice and then we'll make it work behind the scenes.
- 58:47And then Sebastian, the FastAPI creator, 50% of that.
- 58:50So help support FastAPI.
- 58:52Yeah.
- 58:53Fantastic.
- 58:53Super cool.
- 58:54Yeah.
- 58:55Thanks for doing that together, Michael.
- 58:56That'd be fun.
- 58:56All right.
- 58:57Now there's a couple of questions in live chat before we wrap this up.
- 59:00I guess let's go with this question from Joe real quick.
- 59:02Because I'm really happy with Flask.
- 59:04Is there any reason for me to switch to FastAPI?
- 59:05I mean, we've covered some of the reasons.
- 59:07I would point out before anyone out there listening makes that decision.
- 59:11If Flask 2.0 is coming out in a week, wait until that happens.
- 59:15And then look at what the modern Flask looks like.
- 59:17A lot of major stuff's coming like async and await support and so on.
- 59:20And then compare those.
- 59:22Yeah.
- 59:22I would say that's a hard no.
- 59:23Don't switch right away.
- 59:25Like spin up an app.
- 59:27Like see if you like it.
- 59:28See if you enjoy it before like moving your application over to SAPI.
- 59:32Yeah.
- 59:32And then Teddy has another interesting question.
- 59:34Like, are we aware of any CMS like projects building on top of FastAPI similar to say Wagtail
- 59:39with Django?
- 59:40I don't know of any.
- 59:41Yeah.
- 59:42I don't know either.
- 59:42The closest that I would say is like that thing I described with full web apps with Fast
- 59:47API, which you can get the code from the open public GitHub repo.
- 59:51You don't have to take the course to check it out.
- 59:52That does put like HTML views and stuff on top of it, but you're still there.
- 59:56It's more like what Flask does from scratch, not what Wagtail does from like, here's your
- 1:00:01CMS.
- 1:00:01So that's a very long ways from what you're asking, but it's as close as I know of.
- 1:00:04Yeah.
- 1:00:04Wagtail is like in between WordPress and sort of Django.
- 1:00:07So it adds a lot on top of Django.
- 1:00:10So yeah, if you're looking for that sort of functionality, FastAPI is not going to do
- 1:00:14that.
- 1:00:14I wouldn't even look for an extension out there for that.
- 1:00:16It's not the right tool.
- 1:00:17Yeah, probably not.
- 1:00:18Dominus, what's the best platform to deploy FastAPI?
- 1:00:22Yeah.
- 1:00:22So you can deploy it really sort of anywhere.
- 1:00:24It kind of gets into the hosting section there.
- 1:00:26So if you want to scroll down there.
- 1:00:27Yeah.
- 1:00:27Yeah.
- 1:00:28It's kind of, we were like on the cusp of it, but we don't really have time to go too
- 1:00:31deep into it.
- 1:00:31Yeah.
- 1:00:32Yeah.
- 1:00:32I mean, if you containerize it, you can obviously deploy it wherever I deploy like to Heroku.
- 1:00:37It's very simple to deploy containerize apps there.
- 1:00:40EC2, DigitalOcean as an app platform.
- 1:00:42That's where a platform is a service.
- 1:00:44It's similar to Heroku now.
- 1:00:46So yeah, I mean, really wherever you like to do your deployments, you know, FastAPI,
- 1:00:50totally fine to deploy it there.
- 1:00:51It goes pretty easily.
- 1:00:52Yeah.
- 1:00:53There's even some serverless stuff that you point out in your list there, right?
- 1:00:56Further down.
- 1:00:56Certainly on the infrastructure to service, Nginx, Gunicorn, particularly running uvicorn
- 1:01:05workers.
- 1:01:06So you get the async support, which is like a special flag you can pass to Gunicorn.
- 1:01:10And then let's encrypt for SSL and you're golden.
- 1:01:13Yeah.
- 1:01:13And I run an awesome Flask, you know, repo as well.
- 1:01:17And I literally copied and pasted this from Flask.
- 1:01:19So it's like, I mean, all of this is just agnostic.
- 1:01:21Yeah.
- 1:01:22Yeah.
- 1:01:23Very cool.
- 1:01:23And Joe actually gave a call out to that earlier saying, I just starred your live and realized
- 1:01:27you're the same guy that does the awesome Flask list.
- 1:01:29Awesome.
- 1:01:31Yeah.
- 1:01:31There we go.
- 1:01:32Fantastic.
- 1:01:32All right.
- 1:01:33Well, I think we're quite out of time here, Michael, but super fun, super fun stuff to
- 1:01:39talk about.
- 1:01:39Really helpful.
- 1:01:40I just love these awesome lists because not only do you learn about all these cool things
- 1:01:44like some of the plugins, like FastAPI, SQLAlchemy, but then also things that those are using.
- 1:01:50It's just such a cool exploration of all these different libraries and things that are out
- 1:01:54there, right?
- 1:01:54Like Beanie, for example.
- 1:01:56I didn't know about Beanie, but now I discovered it, even though I wasn't looking for that in
- 1:01:59particular.
- 1:02:00Yeah.
- 1:02:00I don't know how many times I see on Reddit, like people asking, well, hey, what should
- 1:02:04I use for auth?
- 1:02:04What should I use for this?
- 1:02:06And it's like, well, I mean, yeah, I mean, here's a list.
- 1:02:09Here's a concise list of all the different things out there.
- 1:02:11It might not cover everything because there's obviously other things out there, but it's
- 1:02:15definitely nice to like come to something like this versus like, you know, searching PyPI
- 1:02:19with FastAPI dash, basically.
- 1:02:21Exactly.
- 1:02:22Exactly.
- 1:02:23One of the big challenges we have in the Python space, which is kind of the opposite
- 1:02:27of some places like say the Microsoft world where they're like, here's your ORM, here's
- 1:02:32your web framework.
- 1:02:32You go build with that.
- 1:02:33Have a good time.
- 1:02:34Is we have the exact opposite of there's a thousand flowers blooming in each level of the
- 1:02:40stack.
- 1:02:40And it's a paradox of choice.
- 1:02:42Did you notice as a newcomer, I don't think it feels like amazing.
- 1:02:46Look at all these choices.
- 1:02:46It feels like overwhelming.
- 1:02:48I had, what do I do?
- 1:02:49Yeah.
- 1:02:49Right.
- 1:02:50I think awesome lists like the one you created are helpful to really narrow it down to a couple,
- 1:02:54go make a pick and just run with it.
- 1:02:56A lot of the Ruby and Rails folks, when they come over to the Python space, they're like,
- 1:02:59well, there's more than one.
- 1:03:00There's more than one ORM.
- 1:03:01Well, which one do I use?
- 1:03:03Well, I don't know.
- 1:03:05Ask DHH, I guess.
- 1:03:06Yeah, exactly.
- 1:03:07What are you doing?
- 1:03:07What are you doing?
- 1:03:08Yeah.
- 1:03:08Very cool.
- 1:03:09All right.
- 1:03:09Well, I guess we're down to the final two questions before I let you out of here.
- 1:03:13I'll see if this has changed since last time.
- 1:03:15So if you're going to write some code, what editor do you use?
- 1:03:19Python code, I suspect.
- 1:03:20So I approached this question a little different because you asked me favorite editor and I said
- 1:03:25idle because I don't use idle, you know, obviously, but it has a special place in my
- 1:03:29heart because that's where I learned Python was idle.
- 1:03:31And Thani is like sort of like in between like VS Code or a PyCharm and idle sort of like
- 1:03:38Interesting.
- 1:03:38You're going to learn like idle like today.
- 1:03:40Check out Thani.
- 1:03:41It like adds like some debugging like type tools and it's like a lot prettier to look at.
- 1:03:46Yeah.
- 1:03:46Super interesting.
- 1:03:47It's like sort of like a notebook, sort of like a proper like autocomplete editor.
- 1:03:53And it looks a little bit like idle.
- 1:03:55Yeah.
- 1:03:55How interesting.
- 1:03:56Yeah.
- 1:03:57Cool.
- 1:03:57Okay.
- 1:03:57Yeah.
- 1:03:57I haven't thought about that one for a while.
- 1:03:59That's cool.
- 1:03:59And then.
- 1:03:59Yeah.
- 1:04:00Don't use this on a daily basis though.
- 1:04:02So I definitely use VS Code on a daily basis.
- 1:04:06So I'm not coding in the idle.
- 1:04:08Like what does idle stand for?
- 1:04:10Integrated development and learning environment.
- 1:04:11Yeah.
- 1:04:12Don't use that on a daily basis.
- 1:04:13Exactly.
- 1:04:15I use Scratch for my architecture design diagrams.
- 1:04:17Yeah.
- 1:04:17There you go.
- 1:04:18Yeah.
- 1:04:19And then notable PyPI package.
- 1:04:20So I've been using for doc strings.
- 1:04:22I've been using Flake 8 doc strings just to lint my doc strings.
- 1:04:25And that has helped me.
- 1:04:26You know, I use like the sort of the Google flavor of doc strings.
- 1:04:30And that has helped me adhere to that a little bit better.
- 1:04:32Yeah.
- 1:04:33Also, I want to give a shout out to Hotwire Django.
- 1:04:36So Hotwire comes from sort of the Rails sort of world.
- 1:04:40But this is essentially HTML served over WebSockets.
- 1:04:44So instead of like, you know, doing, you know, all this stuff with Vue or React, what you do
- 1:04:50is you serve up basically templates and the templates are pre-rendered.
- 1:04:53Yeah.
- 1:04:53Hey.com.
- 1:04:54That's where Hotwire comes from.
- 1:04:55But instead of serving up your JSON and having two forms of state, one on the client,
- 1:05:00one on the server, you just like, you simplify it all.
- 1:05:02I mean, it does add complexity with WebSockets and you have to deal with that.
- 1:05:05But yeah, I like sort of that paradigm and it feels like a little bit more like 2005-ish
- 1:05:11than 2020-ish.
- 1:05:13But yeah, I mean, it's definitely been working for the Rails folks and Basecamp.
- 1:05:17Yeah.
- 1:05:18That place is interesting.
- 1:05:19All the frameworks that they kick out.
- 1:05:20Yeah.
- 1:05:21Cool.
- 1:05:21All right.
- 1:05:21So if you want to, if you want to be like, hey, and DHH, you can go do that.
- 1:05:24That's really cool.
- 1:05:25Yeah.
- 1:05:26I've heard good things about it.
- 1:05:26Awesome.
- 1:05:27Well, Michael, it's been really fun to talk about.
- 1:05:29Your Awesome List.
- 1:05:30And I think all the stuff we touched on is going to be super helpful.
- 1:05:33Final call to action.
- 1:05:34People want to get started with FastAPI and pick some libraries.
- 1:05:37What do they do?
- 1:05:38You know, obviously, I would definitely say start with the FastAPI documentation.
- 1:05:42It is great.
- 1:05:42Out of all of like the documentation out there in terms of Flask and Django and whatnot, that
- 1:05:48one is by far the best.
- 1:05:49Definitely start off there.
- 1:05:50After you've built like just a basic app, check out the awesome like FastAPI list to see how
- 1:05:55to extend it.
- 1:05:56And then if you're looking to like learn more in the testing and Docker type realm, check
- 1:06:01out my course and check out, you know, Michael's courses as well.
- 1:06:04Yeah.
- 1:06:04And you can do that bundle thing.
- 1:06:06I'll include the email so they can send it over and help them out.
- 1:06:10Very cool.
- 1:06:10Awesome.
- 1:06:10Yeah.
- 1:06:11Yeah.
- 1:06:11Awesome.
- 1:06:12Yeah.
- 1:06:12So thank you so much for being here.
- 1:06:13Really appreciate it.
- 1:06:14And it's been super fun to talk FastAPI and all the stuff around it.
- 1:06:18It's really growing, isn't it?
- 1:06:19Yeah.
- 1:06:19It's exciting.
- 1:06:20It's exciting to see just how much it's grown just in like past like six months.
- 1:06:24Yeah, absolutely.
- 1:06:25All right.
- 1:06:26See you later.
- 1:06:26Yeah.
- 1:06:27Well, cheers.
- 1:06:28Thanks for having me.
- 1:06:28Appreciate it.
- 1:06:29Yep.
- 1:06:29Cheers.
- 1:06:30This has been another episode of Talk Python To Me.
- 1:06:33Our guest in this episode was Michael Herman, and it's been brought to you by us over at
- 1:06:38Talk Python Training.
- 1:06:39Want to level up your Python?
- 1:06:41We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:06:45Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:06:50And best of all, there's not a subscription in sight.
- 1:06:53Check it out for yourself at training.talkpython.fm.
- 1:06:56Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:07:00We should be right at the top.
- 1:07:02You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:07:07and the direct RSS feed at /rss on talkpython.fm.
- 1:07:11We're live streaming most of our recordings these days.
- 1:07:15If you want to be part of the show and have your comments featured on the air,
- 1:07:18be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:07:22This is your host, Michael Kennedy.
- 1:07:24Thanks so much for listening.
- 1:07:25I really appreciate it.
- 1:07:27Now get out there and write some Python code.
- 1:07:44I'll see you next time.