Introducing FastAPI

15 Views
English
#FastAPI#Python#Python Web

Outline

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def index():
    return {"Hello": "World"}

# Runs via ASGI server (e.g. Uvicorn)
# uvicorn main:app

FastAPI is a modern, fast (high-performance) web framework for building APIs based on standard Python 3.7+ type hints. As its name suggests, it prioritizes fast development (Fast to Code) and fast request processing (Fast to Run).

Flask vs Django in 2025: A Comprehensive Comparison of Python Web Frameworks | LearnDjango.com

FastAPI uses the ASGI framework Starlette as the foundation for its web framework functionality, and leverages the Pydantic library for data validation, serialization, and automatic documentation generation. This allows developers to easily implement powerful features using standard Python type hints without complex setup. It is a fully open-source project distributed under the MIT license.

 

Specificity

FastAPI provides a variety of features required for modern API development in a concise and efficient manner.

  • High Performance: Based on Starlette and Pydantic, it delivers exceptionally high processing performance, comparable to Node.js and Go.
  • Intuitive and Easy Learning Curve: Well-structured and designed for ease of use, FastAPI offers detailed documentation and numerous examples, making it easy to learn.
  • Clean Code: Designed to minimize code duplication. For example, simply declaring type hints on function parameters allows you to define the request body, path parameters, query parameters, cookies, and more, all while simultaneously performing data validation.
  • Standards-Based: It fully supports and operates on the OpenAPI standard for API specification writing and the JSON Schema standard for data structure definition.
  • Active Utilization of Type Hints: In conjunction with Pydantic, FastAPI handles data validation, serialization/deserialization, and configuration management using standard Python type hints.
  • Asynchronous Support: Full support for Python's async and await syntax allows for easy implementation of asynchronous APIs requiring high concurrency on top of ASGI. Synchronous functions are also supported in a standard manner.

FastAPI's code is largely written in Python, with core web functionality and data processing performance relying heavily on Starlette and Pydantic, respectively.

 

By the way

  • Compared to Flask, it offers more built-in features, such as data validation, asynchronous processing, and automatic documentation generation. It's lighter and more specialized for REST API development than the full-stack framework Django.
  • While FastAPI has gained significant popularity and generated a significant number of issues and Pull Requests (PRs), the project's core review and decision-making authority remains centralized in the hands of its founder, Sebastián Ramirez (tiangolo). This has led to a bottleneck in the review and merge of contributions (PRs), leading to criticism and concerns that the pace of new feature additions and improvements is relatively slow compared to the project's size and community expectations.[3]

 

 

Related Posts