FastAPI
Dispatch requires an HTTP endpoint to communicate with your app via webhooks. If you’re using FastAPI, great news, because Dispatch has a built-in integration for it, which sets up this HTTP endpoint for you.
Initialize a Dispatch
class with a reference to a FastAPI
instance and it’s done.
from fastapi import FastAPIfrom dispatch.fastapi import Dispatch
app = FastAPI()dispatch = Dispatch(app, endpoint="https://my-app.com")
@dispatch.functiondef background_job(): print("I'm executed asynchronously in background")
@app.get("/")def index(): background_job.dispatch() return "OK"