Skip to content
Dispatch Dispatch Dispatch

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
def background_job():
print("I'm executed asynchronously in background")
@app.get("/")
def index():
background_job.dispatch()
return "OK"