A robust FastAPI application demonstrating advanced Python patterns, including background task processing with Celery, scheduled jobs, and a reverse proxy setup with Nginx.
- FastAPI Backend: Complete REST API for managing To-Do items.
- Asynchronous Tasks: Background processing for emails and CSV exports using Celery.
- Scheduled Jobs: Automated daily summaries using Celery Beat.
- Monitoring: Real-time task monitoring with Flower.
- Infrastructure: Proxying via Nginx and containerization with Docker Compose.
- Persistence: SQLite database for tasks and Redis as a message broker.
- Linter/Formatter: Flake8, Autopep8
- Backend: FastAPI, Pydantic, SQLAlchemy
- Task Queue: Celery, Redis
- Reverse Proxy: Nginx
- Monitoring: Flower
- Docker and Docker Compose installed.
-
Clone the repository:
git clone <repository-url> cd python-advanced
-
Start the containers:
docker compose up -d --build
-
Populate initial data:
./populate_data.sh
- API: http://localhost:8080
- Interactive Docs (Swagger UI): http://localhost:8080/docs
- Flower (Celery Monitor): http://localhost:5555
To trigger the daily summary generation immediately without waiting for the schedule:
docker compose exec api celery -A celery_app.celery call generate_daily_summaryThe result will be saved in the ./shared/daily_summary.json file.
Run the provided test script to trigger an export, poll for completion, and download the resulting CSV:
./test_export.shTo verify code formatting:
./.venv/bin/flake8 .The application uses sqlalchemy-celery-beat for a database-backed scheduler. This allows you to manage periodic tasks via the API without restarting services.
curl -X GET http://localhost:8080/scheduler/tasksTo change the interval of the daily summary or add a new task:
curl -X POST http://localhost:8080/scheduler/tasks \
-H "Content-Type: application/json" \
-d '{
"name": "Generar resumen diario (cada minuto)",
"task": "generate_daily_summary",
"interval_seconds": 30,
"enabled": true
}'curl -X DELETE "http://localhost:8080/scheduler/tasks/Generar%20resumen%20diario%20(cada%20minuto)"Note: Changes are picked up automatically by the Celery Beat container within seconds.
api/: FastAPI application code, models, and Celery task definitions.nginx/: Nginx configuration files.shared/: Local directory for files generated by background tasks (JSON summaries, CSV exports).docker-compose.yml: Full stack orchestration..flake8: Linting configuration.