In today's fast-paced world, where implementation and production times are constantly shrinking, we need tools that help us build our ideas quickly and efficiently. One of the key factors that, in my view, has boosted the popularity of this framework is its excellent documentation. It's so well-crafted that it even helps you learn about Python typing — it's detailed and easy to consult.
The Framework Sebastián Ramírez Didn't Want to Write
Its creator, Sebastián Ramírez, spent years avoiding the idea of writing a new framework. His philosophy was simple: find the best tool for the job and use it, contributing to it if necessary. He was building APIs and, despite testing different frameworks in various languages, he kept running into problems: unintuitive configurations, fragile plugin chains, lack of clear validations…
Then came type annotations (type hints) in Python 3.6, and inspired by how Pydantic used this info for serialization — and by tools like DRF with autocomplete support — he decided to start FastAPI.
His main goal was to ensure development teams could write the best code possible with FastAPI, in the simplest way, with benefits like autocomplete and inline error reporting.
What is FastAPI?
FastAPI is essentially a modern, high-performance micro web framework for building APIs with Python. Its philosophy centers around delivering the best possible developer experience, aiming to be as intuitive and efficient as possible. As a result, FastAPI has grown exponentially, ranking as the third most popular Python web framework (after Flask and Django), and without a doubt, one of the most loved today.
The core of its design lies in simplicity, achieved through standardization with open standards like OpenAPI and JSON Schema. It fully leverages Python's type hints and Pydantic. The promise is clear: "the more FastAPI code you write, the less API code you need." That means you can focus on your business logic, and let the framework handle validation, serialization, and documentation.
A Modular and Open Approach
While FastAPI doesn’t explicitly mention SOLID principles, it embodies them through its modular design, external integration philosophy, and commitment to standardization. Sebastián avoids baking unnecessary features directly into the core. Instead of creating FastAPI-specific plugins for everything, the philosophy is to document how to integrate third-party tools (like authentication libraries or databases) in a way that fits naturally with the framework.
For instance, FastAPI is database-agnostic: it doesn’t ship with a built-in ORM, allowing you to use any SQL or NoSQL solution. Although Sebastián did create SQLModel to ease SQL database integration using FastAPI and Pydantic, FastAPI does not depend on SQLModel. This keeps each component independent and focused, making maintenance and flexibility much easier. If something can be independent, it’s better to keep it that way.
Write Less, Do More!
One of FastAPI’s biggest strengths is how quickly you can build a working API. It lets you focus on your business logic, not boilerplate or infrastructure.
Let’s look at a simple example of how easy it is to get started:
from fastapi import FastAPI # 1. We import the main FastAPI class
app = FastAPI() # 2. We create a FastAPI instance, our application
@app.get("/") # 3. We define a GET route at the root of our API
def read_root(): # 4. Function that will be executed when this route is accessed
# 5. We return a Python dictionary. FastAPI automatically converts it to JSON.
return {"message": "Hello, FastAPI world!"}
@app.get("/items/{item_id}") # 6. Route with a path parameter: item_id
def read_item(item_id: int, q: str | None = None):
"""
item_id is expected as an integer, 'q' as an optional string.
FastAPI automatically validates the types and detects
whether it's a path or query parameter.
"""
return {"item_id": item_id, "q": q}
What do we achieve with so little code?
- Simplicity: a complete API with just a few lines.
- Intuitive decorators: @app.get() links the function to an HTTP GET route.
- Automatic JSON conversion: Python dictionaries are automatically serialized.
- Parameter validation and extraction: FastAPI automatically detects item_id as a path parameter and q as a query parameter thanks to type annotations. If the type doesn't match, FastAPI returns an error.
The magic of data validation
FastAPI uses Pydantic and standard Python type annotations for data validation and serialization, which is one of its most powerful features.
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
app = FastAPI()
# 1. We define a data model using Pydantic. This allows us to structure the expected JSON.
class Food(BaseModel):
name: str # The name of the food, required (no default value)
ingredients: List[str] # A list of strings representing the ingredients
price: float = 0.0 # The price, optional (default value is 0.0)
@app.post("/foods/") # 2. We use POST to receive data in the request body
def create_food(food: Food) -> Food: # 3. FastAPI expects a JSON body matching our 'Food' model
# 4. If the incoming JSON doesn’t match the 'Food' model, FastAPI will automatically reject it
return food
Benefits of this approach
- Automatic validation. If the data received by the API doesn’t match the definition of the Food model, FastAPI will automatically return a detailed error, clearly indicating where the issue lies.
- Autocomplete and editor error detection. Thanks to type annotations, your code editor (VS Code, PyCharm, etc.) knows the type of each variable and attribute, offering autocomplete and catching errors before you even run the code.
- Automatic serialization. FastAPI seamlessly converts data between Python and JSON in both directions.
- Additional validation. You can add more complex rules using pydantic.Field or fastapi.Query, fastapi.Path, fastapi.Body, among others.
Automatic and interactive documentation
One of the most praised features of FastAPI is its ability to generate interactive documentation automatically, without requiring you to write any extra code. By accessing the /docs route (Swagger UI) or /redoc, you'll get interfaces that:
- Display all your endpoints and their HTTP methods.
- Describe the expected data types for each parameter and request body.
- Let you test your APIs live directly from the browser, sending requests and seeing responses.
This is possible because FastAPI is built on top of open standards like OpenAPI and JSON Schema. This is a crucial design choice, as it eliminates the need to maintain separate documentation that can easily become outdated. Your docs are always in sync with your code.
The FastAPI community and its future
FastAPI’s community is known for being very friendly and welcoming, maintaining a strong spirit of mutual support. If you'd like to contribute, there are several ways to do so—even if you're just getting started:
- Help other users on GitHub Discussions
This is one of the most valuable contributions, as it takes up a lot of the maintainer’s time. They've even created a "FastAPI Experts" section to recognize people who help regularly.
- Translate the documentation
FastAPI’s documentation is constantly growing, and there's a desire to make it available in more languages. Helping with translations or reviewing existing ones is super helpful—and a great way to learn the framework in depth.
- Improve the documentation
Fixing grammar issues or making concepts easier to understand are valuable contributions, especially for new users.
Recently, FastAPI development was sponsored by the Sequoia OS fellowship, which led to the creation of FastAPICloud, a company focused on simplifying the deployment of FastAPI-based apps. Their goal: with just one command (fastapi deploy), the platform will take care of autoscaling, HTTPS, and infrastructure complexity, so dev teams can focus purely on business logic.
Conclusion: a framework that cares for us
FastAPI is more than a framework; it’s a tool that simplifies developers' lives by automating tedious tasks like data validation and documentation generation. It encourages better Python code through type usage and protects you from common mistakes before they hit production. Its "Developer Experience First" philosophy shines through in every detail.
If you're looking for a robust, fast, and developer-friendly solution for your Python API projects, FastAPI is a top choice. Its future looks bright, especially with strong community support and a newly founded company to drive further development of the framework.
References
- Pybites Podcast, Sebastián Ramírez
- Interview with Sebastián Ramírez, Platzi
- Open Source with FastAPI’s @tiangolo, GitHub
- Modern Python through FastAPI and friends - Sebastián Ramírez, Python Chile
- FastAPI + OpenSource talk with Sebastián Ramírez, FIUBA – Ingeniería del Software 2
Comments are moderated and will only be visible if they add to the discussion in a constructive way. If you disagree with a point, please, be polite.
Tell us what you think.