Skip to content

fastapi ¤

Integration of Dispatch programmable endpoints for FastAPI.

Example:

import fastapi
from dispatch.fastapi import Dispatch

app = fastapi.FastAPI()
dispatch = Dispatch(app, api_key="test-key")

@dispatch.function()
def my_function():
    return "Hello World!"

@app.get("/")
def read_root():
    my_function.dispatch()

Dispatch ¤

Dispatch(
    app: FastAPI,
    endpoint: str | None = None,
    verification_key: Ed25519PublicKey | None = None,
    api_key: str | None = None,
    api_url: str | None = None,
)

Bases: Registry

A Dispatch programmable endpoint, powered by FastAPI.

It mounts a sub-app that implements the Dispatch gRPC interface.

Parameters:

Name Type Description Default
app FastAPI

The FastAPI app to configure.

required
endpoint str | None

Full URL of the application the Dispatch programmable endpoint will be running on. Uses the value of the DISPATCH_ENDPOINT_URL environment variable by default.

None
verification_key Ed25519PublicKey | None

Key to use when verifying signed requests. Uses the value of the DISPATCH_VERIFICATION_KEY environment variable by default. The environment variable is expected to carry an Ed25519 public key in base64 or PEM format. If not set, request signature verification is disabled (a warning will be logged by the constructor).

None
api_key str | None

Dispatch API key to use for authentication. Uses the value of the DISPATCH_API_KEY environment variable by default.

None
api_url str | None

The URL of the Dispatch API to use. Uses the value of the DISPATCH_API_URL environment variable if set, otherwise defaults to the public Dispatch API (DEFAULT_API_URL).

None

Raises:

Type Description
ValueError

If any of the required arguments are missing.

function ¤

function(func)

Decorator that registers functions.

primitive_function ¤

primitive_function(
    primitive_func: PrimitiveFunctionType,
) -> PrimitiveFunction

Decorator that registers primitive functions.

set_client ¤

set_client(client: Client)

Set the Client instance used to dispatch calls to local functions.