Introduction to FastAPI
Our goal is to build an AI agent and offer it as a service people can use over the internet. When a user sends a question, the agent needs to process it and return a result.
This requires a web server that accepts requests, passes them to the agent, and responds with the results. Let's learn how to build one with FastAPI, a Python web framework.
What Is a Web Framework?
Building a web server involves recurring tasks: reading data from HTTP requests, creating responses, storing and retrieving database records, and authenticating users. Services may offer different features, but they often need the same underlying operations.
A web framework provides the basic structure and common features needed to build a web service. Think of a LEGO set: ready-made pieces let you build your own model. Similarly, you can combine a framework's features and add your own to create a web server.
Two Meanings of Fast
The Fast in FastAPI has two meanings.
Fast to Run
FastAPI is an asynchronous web framework built around modern Python features. Its support for asynchronous processing helps it handle concurrent requests efficiently. For workloads that benefit from concurrency, it can outperform traditional synchronous frameworks.
Fast to Code
FastAPI makes extensive use of Python type hints. Instead of writing every step of data processing yourself, you declare the expected data types and constraints. FastAPI also uses these declarations to generate API documentation. Less boilerplate means faster development.
Comparing Web Frameworks
Python also has web frameworks such as Django and Flask. All three can build web services, but their built-in features and development styles differ.
| Framework | Approach | Common Uses |
|---|---|---|
| An integrated set of features for web services | Large services with extensive administration needs | |
| A minimal core extended with the tools you need | Small services and prototypes | |
![]() |
Concise, productive web API development | API servers and AI model or agent services |
Each framework has trade-offs. Choose one that fits the service you want to build.
Django is convenient when you need features such as user management and an administration interface. Flask and FastAPI work well when you prefer a smaller starting point, want to assemble your own tools, or are building an API-focused service.
Flask and FastAPI both let you expand a service by connecting the tools you choose. FastAPI also provides asynchronous request handling, data validation, and automatic API documentation.
In the 2026 Stack Overflow Developer Survey, 18.5% of respondents reported using FastAPI, ahead of Flask and Django.
According to the FastAPI documentation, companies including Microsoft, Uber, Netflix, and Cisco use FastAPI. OpenAI also uses it for API development, according to this account of its technology stack.
Check Your Understanding
Decide whether each statement is true or false.
- A web framework provides structure and features commonly needed in web service development.
- FastAPI's name refers to both request handling performance and development productivity.
- Using FastAPI automatically speeds up the computations inside an AI model.
- FastAPI uses type declarations to generate API documentation automatically.
- Django and Flask cannot be used to build web APIs.
Answers and Explanations
- True — Frameworks help with recurring tasks such as routing requests and creating responses.
- True — FastAPI emphasizes both runtime performance and the speed of developing features.
- False — FastAPI handles web requests. Model computation speed depends on the model and its execution environment.
- True — Data types and constraints also inform the generated documentation, reducing manual documentation work.
- False — All three frameworks can build APIs; they differ in their built-in features and development styles.
