FastAPI Template with Industry Standard Observability
-
Logfire is Uncomplicated Observability for Python by Pydantic Team.
-
Create a new project in Logfire with name
api-template -
Setup logfire in your project
# Authenticate with Logfire, one time operation
logfire auth
# Initialize your local project to use Logfire
logfire projects use api-template- Set in your
.envfile:OLTP_LOG_METHOD=logfire
-
Taskiq is distributed task queue with full async support.
-
Like celery but better with async support and more broker support like Redis, RabbitMQ, Kafka, etc.
-
The official docs recommend taskiq-aio-pika as the broker and taskiq-redis as the result backend for production use.
-
Test taskiq with RabbitMQ and Redis
# Run Redis and RabbitMQ in docker
make run-taskiq-services
# Run the taskiq workers
make run-taskiq-workers
# Test the taskiq workers
make run-taskiq-main
# (Optional) Run taskiq scheduler for periodic tasks
make run-taskiq-schedulerIf you want to migrate your database, you should run following commands:
# To run all migrations until the migration with revision_id.
alembic upgrade "<revision_id>"
# To perform all pending migrations.
alembic upgrade "head"If you want to revert migrations, you should run:
# revert all migrations up to: revision_id.
alembic downgrade <revision_id>
# Revert everything.
alembic downgrade baseTo generate migrations you should run:
# For automatic change detection.
alembic revision --autogenerate
# For empty file generation.
alembic revision