Skip to content

flask ¤

Integration of Dispatch functions with Flask.

Example:

from flask import Flask
from dispatch.flask import Dispatch

app = Flask(__name__)
dispatch = Dispatch(app)

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

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

Dispatch ¤

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

Bases: BlockingFunctionService

A Dispatch instance, powered by Flask.

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

Parameters:

Name Type Description Default
app Flask

The Flask 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.