Skip to content

fastapi ¤

Integration of Dispatch functions with FastAPI for handlers using asyncio.

Example:

import fastapi
from dispatch.asyncio.fastapi import Dispatch

app = fastapi.FastAPI()
dispatch = Dispatch(app)

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

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

Dispatch ¤

Dispatch(
    app: FastAPI,
    registry: Optional[Registry] = None,
    verification_key: Optional[
        Union[Ed25519PublicKey, str, bytes]
    ] = None,
)

Bases: AsyncFunctionService

A Dispatch instance, 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
registry Optional[Registry]

A registry of functions to expose. If omitted, the default registry is used.

None
verification_key Optional[Union[Ed25519PublicKey, str, bytes]]

Key to use when verifying signed requests. Uses the value of the DISPATCH_VERIFICATION_KEY environment variable if omitted. 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

Raises:

Type Description
ValueError

If any of the required arguments are missing.

batch ¤

batch() -> Batch

Create a new batch.