Python REST APIs with FastAPI (Summary)
In this video course, you learned about FastAPI and how to use it to create production-ready APIs that have best practices by default while providing the best developer experience possible.
You learned how to:
- Use path parameters to get a unique URL path per item
- Receive JSON data in your requests using pydantic
- Use API best practices like validation, serialization, and documentation
- Continue learning about FastAPI and pydantic for different use cases
You’re now ready to start creating your own highly performant APIs for your projects. If you want to dive deeper into the world of FastAPI, then you can follow the official User Guide in the FastAPI documentation.
For more information on concepts in this course, you can check out:
- Async IO in Python: A Complete Walkthrough
- Python Type Checking (Guide)
- Python and REST APIs: Interacting With Web Services
- Python’s Requests Library (Guide)
- Real Python Podcast Episode 72: Starting With FastAPI and Examining Python’s Import System
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00 In this course, you learned how to create a complete REST API that uses a database to implement CRUD operations with FastAPI in less than fifty lines of Python code.
00:11 That’s pretty impressive. You saw how to use the HTTP methods POST, GET, PUT, and DELETE to implement the Create, Read, Update, and Delete functions of a database, respectively.
00:23
You saw how the API receives input via path parameters and how you can enforce the types of those parameters using Python type hints and pydantic. Also, using pydantic, you defined a subclass of the BaseModel
class that represented the payload of a request body.
00:41 And you saw how FastAPI automatically serializes and deserializes between JSON objects and pydantic base models.
00:50
And you learned how to use the HTTPException
class to return responses with different status codes to the client. Finally, you tested the API using Swagger, a web-based UI that provides interactive documentation for the API, and the HTTPie command-line client.
01:11 While you did all of this in less than fifty lines of code, there were some things that were omitted, and you can explore FastAPI to learn how to implement authentication to control access to your API, use query parameters in addition to path parameters to provide input, and web sockets for two-way communication. FastAPI can do all of this and more.
01:33 You can also learn more about the Python language features related to FastAPI, such as async and type checking, by referring to these Real Python articles.
01:43 Thank you for choosing to watch this course, and I hope you found it useful. If you want to continue the conversation, please leave a comment below or post on the Real Python forums.
daxmahoney on April 13, 2022
That was awesome.
When I would pause the video, the video controls would obscure the bottom line of the terminal or the latest command. I wish the whole screen was moved up like one row. It was annoying, but I survived.
Douglas Starnes on April 13, 2022
@daxmahoney
I’ll look into what I can do to avoid that. It would require clearing the console a lot and might be distracting. Thanks for the suggestion.
Douglas Starnes on April 13, 2022
@briandonati Thanks for the comment! I think FastAPI is the best of all worlds.
killbit on July 12, 2022
Thank you! This was excellent and exactly what I needed to make my scripts accessible to my team!
Peter Tribout on Nov. 7, 2022
Big congrats! Excellent course. Is there a course that builds on this one about Authentication? Thanks.
chaudhriankit on April 1, 2023
great article! how do we secure your end points?
kbauch on July 26, 2023
That’s clear. And OMG FastAPI is just wonderful !
I’m from JS and discover how all python tools work, it’s brainfuck !
mikesult on Oct. 13, 2023
Thanks for a great course. “[with FastAPI] there’s a decorator for that” is a wonderful thing! Standing on the shoulders of FastAPI, pydantic, Swagger and httpie is a great place to be. thanks for presenting it so clearly!
Glaron101 on Jan. 18, 2024
I am fairly new to python. I was just tasked at work to come up with an API and document it. This series is making me feel so much better.
Become a Member to join the conversation.
briandonati on April 9, 2022
Very good presentation. I’ve created several applications using flask_restful and flask_restplus. After reviewing this course I will definitely give FastAPI a try. While I’ve always considered Flask to be mostly “cruft” free, it appears that FastAPI is even more so. Good job and thanks.