Get startedGet started for free

Why FastAPI?

1. Why FastAPI?

Welcome to the course! I'm Matt and I'll be your instructor. I have been using FastAPI in industry since soon after it was released. This course is designed for experienced Python programmers who want to build web applications that manage data using the FastAPI framework. In this first video, we will learn about how FastAPI can be used to manage data and provide high throughput data and machine learning transactions on the web.

2. What is FastAPI?

What is FastAPI? Let's start with some terminology. API stands for Application Programming Interface, meaning any software with a defined purpose. In internet jargon however, API refers to web applications using the HTTP protocol to transmit structured data. A web application is an application that serves traffic over the web. A web framework is a software framework that helps build web applications. FastAPI is a fast way to build high-performance APIs using Python.

3. FastAPI key features

Let's review some key features of FastAPI. FastAPI is Fast. It has very high performance and is one of the fastest Python frameworks available. FastAPI is "low code" and easy to learn. It leverages Python annotations and type hints to make coding APIs almost identical to coding Python functions. FastAPI is robust. It builds production-ready code with automatic interactive documentation. FastAPI is standards-based. It's based on (and fully compatible with) the open standards for APIs: OpenAPI and JSON Schema. The FastAPI website, shown on the slide, provides more information about the framework's features.

4. FastAPI vs. other Python web frameworks

What about other Python web frameworks? Flask and Django are also web frameworks, but both are designed for web-based Graphical User Interface, or GUI, apps instead of APIs. The big difference between Flask and Django is that Django has a built-in Object-Relational Mapping or ORM for short. An ORM is software that represents database models as Python objects. FastAPI and Flask do not have a built-in ORM. FastAPI's key difference is that it's designed for APIs without database operations, which can hurt API performance. This makes FastAPI a great framework for high-throughput data and machine learning transactions.

5. Building our first web application with FastAPI

FastAPI is incredibly simple to get up and running. First, we install the fastapi module from the terminal with pip. Next we create our application by defining it in a file called main.py. Don't worry about the details, we will get back to this soon! Now all we have to do is run the application with the command "fastapi dev main.py." As you can see, this command runs the FastAPI application.

6. Before we practice with FastAPI

Before practicing, let's cover a few notes about FastAPI development. First, we can't run the FastAPI server like we typically run Python scripts with the "Run this code" button. Instead we will define our server code in the Python editor as "main.py" and run it from the terminal with the command "fastapi dev main.py." Always verify that the logs in the terminal show "Application startup complete" before testing the live server. Once the live server is running, we can stop the server by pressing Control-C in the same terminal. Finally, you should install FastAPI in your own Python environment to get used to practicing there as well.

7. Let's practice!

Now, let's practice using FastAPI by running our first FastAPI application!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.