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