Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

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:

Download

Sample Code (.zip)

1.1 KB
Download

Course Slides (.pdf)

290.0 KB

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.

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.

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.