Modern APIs with FastAPI and Python Transcripts
Chapter: Welcome to the course
Lecture: Why FastAPI?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Why is there so much excitement around FastAPI? Well, let's go through just some of the things that make it special. FastAPI
0:07 is one of the fastest Python web frameworks available. In fact, it's on par with the performance of things like Node.js and Go,
0:14 and that's largely because it actually runs on top of something called Starlette,
0:19 a lower level web framework, and uses Pydantic for data exchange and data validation. So, when you think FastAPI,
0:26 you can think fast to execute, fast to run. But that's not the only fast that matters,
0:31 is it? One of the most important ways to be fast is to create applications fast and not spend a lot of time building them.
0:37 So it's also fast to code because FastAPI does many of the mundane type of things that you would do in a web
0:44 application, automatically for us, and some estimates have put it the speed of using FastAPI over things like Flask and Django at 2 to 3 times faster.
0:55 That's because we can do things like just a API method and say it takes some kind of class, one of these Pydantic models,
1:01 and it will automatically look and make sure all the stuff that that class says it
1:05 must have is there, the types the class says it must take are either there or
1:10 automatically convertible to there, so you have a class that's a location, it has a city and a state, well, it better have a city and a state,
1:18 and those are gonna be strings that can be converted over and so on. So a lot of the work around like validation, data exchange, documentation,
1:26 all of that is largely automatic, so you're not gonna have to spend time writing that code. Also,
1:32 when you don't write code and stuff happens automatically for you, that means you might not be writing bugs.
1:37 So there's also about 40% less chance of an error because you don't have to write as much validation and data exchange.
1:44 Also, because of the type hints, it deeply embraces this idea of teaching the editors what type of data is being exchanged.
1:51 You're passing rich objects to the API methods, all the various parts of the API itself, the framework itself, have
1:58 type hints, so editors know what to do and give you automatic completion everywhere, less time in the documentation, less time debugging.
2:06 It's also designed to be easy to use and learn. If you know Flask, you will be pretty close to knowing FastAPI
2:11 actually, and there's not a whole lot of code you have to write. So not too much to write, as well as not too much to learn, less time reading docs,
2:20 also, because of the great editor support. When we create our API's, we'll put parameters in there saying "it takes this kind of data, returns that
2:26 kind of data, and it has this type". Because of all the automatic stuff that's happening
2:30 for us, you'll see the framework is actually doing multiple things, like ensuring the variable is there, doing automatic type conversion, and so on.
2:37 So again, less code duplication, fewer bugs. And, it comes with a production ready web server built on Async and await, so
2:45 you get the highest performance production grade servers, you can just drop right into production.
2:51 One of the challenges with building HTTP based API's is there's zero documentation. What's supposed to be exchanged? Who knows?
2:58 Just go out there and read the docs and play with it. But with FastAPI, it automatically uses what was known as "swagger",
3:04 OpenAPI, to generate documentation for all the API methods, what data is exchanged through JSON schema, and things like that.
3:13 So it's really, really nice that we get automatic documentation by simply writing our program.
3:17 Nothing else. So, these are just some of the reasons to be excited about FastAPI, and we're gonna explore all of them throughout this course.

Talk Python's Mastodon Michael Kennedy's Mastodon