Sample application utilizing FastAPI, Celery with RabbitMQ for task queue. RabbitMQ is also used as Celery backend and optional flower for monitoring the Celery tasks.
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
The key features are:
Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.
Fast to code: It allows for significant increases in development speed.
Easy: Designed to be easy to use and learn. Less time reading docs. Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs. Robust: Get production-ready code. With automatic interactive documentation. Standards-based: It’s based on the open standards for APIs, OpenAPI and JSON Schema.
Celery is a simple, flexible, and reliable distributed system to process vast amounts of messages, while providing operations with the tools required to maintain such a system. It’s a task queue with focus on real-time processing, while also supporting task scheduling. It also helps us to handle asynchronous tasks, which is vital for smooth user experiences. With this powerful combo of FastAPI and Celery, we will be able to do things like:
- Run machine learning models
- Send bulk emails
- Process images or PDFs
- Generate exports of user data
- Perform backups
RabbitMQ is the most widely deployed open source message broker.
Flower is a real-time web application monitoring and administration tool for Celery.
Make sure you have installed
- make
- docker
make build
make start
Once the Flower starts we cann see the submitted tasks at http://localhost:5555/tasks.
This will start the application on port 8000 and Celery process will listen to the Queue universities,university
FastAPI also automatically generated fully interactive API documentation that we can use to interact with our API. We can visit http://127.0.0.1:8000/docs in our browser to see the interactive API documentation provided by Swagger UI: