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:
- Speed: it uses Python’s static typing system to achieve exceptional performance through compilation and static validation at runtime.
- 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.
- Automatic documentation generation: it has a system for auto-generating interactive documentation (OpenAPI/Swagger) from the defined types and method annotations.
- Asynchronous support: allows handling asynchronous operations, making it suitable for high-performance web applications.
- 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:
.
├── 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:
docker compose up -d
Useful commands:
View the containers that are running:
docker compose ps
Stop and remove the application:
docker compose down
Rebuild the application after making changes to the code:
docker compose --build -d