Skip to content

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 FastAPI
from dispatch.fastapi import Dispatch
app = FastAPI()
dispatch = Dispatch(app, endpoint="https://my-app.com")
@dispatch.function
async def background_job():
print("I'm executed asynchronously in background")
@app.get("/")
async def index():
await background_job.dispatch()
return "OK"