Skip to content

Examples

Runnable projects live in examples/ in the repository. CI runs each example's tests against the package from the same commit, so they keep working; the Docker images install the matching release from PyPI.

FastAPI

examples/fastapi: an order service.

  • POST /orders writes the order and enqueues orders.confirm in one transaction: a failed request leaves neither.
  • The worker confirms the order and enqueues orders.receipt on queue mail in the transaction that marks the job succeeded (complete_tx).
  • setup_db.py is the deploy step: migrate, then the app's own tables.
  • test_example.py drives the API with httpx and runs the jobs with drain.
  • compose.yml starts Postgres, the setup step, the API and a worker on both queues.
cd examples/fastapi
docker compose up --build
curl -X POST localhost:8000/orders -H 'content-type: application/json' -d '{"email": "ada@example.com"}'
curl localhost:8000/orders/1