Introduction to FastAPI

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.8+ based on standard Python type hints. It was created by Sebastián Ramírez and has become one of the most popular Python frameworks for building REST APIs.

What is FastAPI?

FastAPI is built on top of two libraries:

It runs on ASGI (Asynchronous Server Gateway Interface) servers such as Uvicorn or Hypercorn, which is what allows it to handle many concurrent requests efficiently.

Key Features

FastAPI vs Flask vs Django

Quick Questions and Answers

Q: Is FastAPI only for asynchronous code?

A: No. You can write endpoints with normal def and FastAPI runs them in a thread pool, or with async def and it runs them on the event loop. You can mix both in the same application.

Q: What does "ASGI" mean and why does it matter?

A: ASGI is the async successor of WSGI. While WSGI (used by Flask/Django traditionally) handles one request per worker at a time, ASGI supports asynchronous, long-lived connections (WebSockets, SSE) and thousands of concurrent connections on a single process.

Q: What is OpenAPI's role in FastAPI?

A: FastAPI automatically generates an OpenAPI schema describing every path, parameter, request body and response. That schema powers the interactive docs and can be used to generate client code in other languages.

Conclusion

FastAPI combines speed, type safety, automatic validation and automatic documentation in one framework. Understanding its pillars (Starlette for the web layer, Pydantic for data, Uvicorn as the ASGI server) is the foundation for everything else in this course.