Help Center

Python - FastAPI

FastAPI is a fast, modern web development framework for Python that enables creating APIs simply, quickly, and with outstanding performance. It stands out for its speed, ease of use, and automatic generation of interactive documentation.

Some of its key features are:

  1. Speed: it uses Python’s static typing system to achieve exceptional performance through compilation and static validation at runtime.
  2. Easy to use: it relies on Python type annotations (using Pydantic) to define data types, which makes data validation and handling requests and responses easier.
  3. Automatic documentation generation: it has a system for auto-generating interactive documentation (OpenAPI/Swagger) from the defined types and method annotations.
  4. Asynchronous support: allows handling asynchronous operations, making it suitable for high-performance web applications.
  5. Support for web standards: supports authentication, authorization, WebSockets, file uploads, among other web standards.

FastAPI is built on the Starlette and Pydantic architecture, leveraging the advantages of both to offer a fast, modern, and highly efficient development framework for creating APIs in Python. Additionally, by leveraging Python’s type system capabilities, it offers strong validation that helps prevent errors before they occur at runtime.

In summary, FastAPI is a powerful tool for developing APIs with Python, standing out for its performance, ease of use, and automatic documentation generation, making it a popular choice for projects that require fast, secure, and well-documented APIs.

Project structure:

text
.
├── compose.yaml
├── app.Dockerfile
├── app
    ├── main.py
    ├── __init__.py

Deploying the application:

We change to the directory that contains the files needed to build the container:

cd /root/stack/python/fastapi

Then start the application:

text
docker compose up -d

Useful commands:

View the containers that are running:

text
docker compose ps

Stop and remove the application:

text
docker compose down

Rebuild the application after making changes to the code:

text
docker compose --build -d