From 6b94a32a55c2d98154e18de78f54cb62754aa4cd Mon Sep 17 00:00:00 2001 From: Stealth Rocket Date: Wed, 5 Jun 2024 17:53:35 +0000 Subject: [PATCH] Deployed 6661a09 to main with MkDocs 1.5.3 and mike 2.0.0 --- main/reference/dispatch/index.html | 23 +++++++++++++++++++++++ main/search/search_index.json | 2 +- main/sitemap.xml.gz | Bin 127 -> 127 bytes 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/main/reference/dispatch/index.html b/main/reference/dispatch/index.html index 664d64a..202648a 100644 --- a/main/reference/dispatch/index.html +++ b/main/reference/dispatch/index.html @@ -2996,6 +2996,29 @@

+ + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ +
+

The return value of the entrypoint function.

+
+
+ diff --git a/main/search/search_index.json b/main/search/search_index.json index 8221e51..c45963b 100644 --- a/main/search/search_index.json +++ b/main/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Dispatch Python SDK","text":"

This is the API reference for the Python SDK of Dispatch.

"},{"location":"reference/SUMMARY/","title":"SUMMARY","text":""},{"location":"reference/dispatch/","title":"Index","text":""},{"location":"reference/dispatch/#dispatch","title":"dispatch","text":"

The Dispatch SDK for Python.

"},{"location":"reference/dispatch/#dispatch.DispatchID","title":"DispatchID module-attribute","text":"
DispatchID: TypeAlias = str\n

Unique identifier in Dispatch.

It should be treated as an opaque value.

"},{"location":"reference/dispatch/#dispatch.Client","title":"Client","text":"
Client(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Client for the Dispatch API.

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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 the API key is missing.

"},{"location":"reference/dispatch/#dispatch.Client.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/#dispatch.Client.dispatch","title":"dispatch","text":"
dispatch(calls: Iterable[Call]) -> List[DispatchID]\n

Dispatch function calls.

Parameters:

Name Type Description Default calls Iterable[Call]

Calls to dispatch.

required

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order as the inputs.

"},{"location":"reference/dispatch/#dispatch.Registry","title":"Registry","text":"
Registry(\n    endpoint: Optional[str] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Registry of functions.

Parameters:

Name Type Description Default endpoint Optional[str]

URL of the endpoint that the function is accessible from. Uses the value of the DISPATCH_ENDPOINT_URL environment variable by default.

None api_key Optional[str]

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

None api_url Optional[str]

The URL of the Dispatch API to use when dispatching calls to functions. 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.

"},{"location":"reference/dispatch/#dispatch.Registry.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/#dispatch.Registry.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/#dispatch.Registry.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/#dispatch.Registry.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/#dispatch.Reset","title":"Reset","text":"
Reset(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n)\n

Bases: TailCall

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/#dispatch.Call","title":"Call dataclass","text":"
Call(\n    function: str,\n    input: Optional[Any] = None,\n    endpoint: Optional[str] = None,\n    correlation_id: Optional[int] = None,\n)\n

Instruction to call a function.

Though this class can be built manually, it is recommended to use the with_call method of a Function instead.

"},{"location":"reference/dispatch/#dispatch.Error","title":"Error dataclass","text":"
Error(\n    status: Status,\n    type: str,\n    message: str,\n    value: Optional[Exception] = None,\n    traceback: Optional[bytes] = None,\n)\n

Error when running a function.

This is not a Python exception, but potentially part of a CallResult or Output.

Parameters:

Name Type Description Default status Status

categorization of the error.

required type str

arbitrary string, used for humans.

required message str

arbitrary message.

required value Optional[Exception]

arbitrary exception from which the error is derived. Optional.

None

Raises:

Type Description ValueError

Neither type or message was provided or status is invalid.

"},{"location":"reference/dispatch/#dispatch.Error.from_exception","title":"from_exception classmethod","text":"
from_exception(\n    ex: Exception, status: Optional[Status] = None\n) -> Error\n

Create an Error from a Python exception, using its class qualified named as type.

The status tries to be inferred, but can be overridden. If it is not provided or cannot be inferred, it defaults to TEMPORARY_ERROR.

"},{"location":"reference/dispatch/#dispatch.Error.to_exception","title":"to_exception","text":"
to_exception() -> Exception\n

Returns an equivalent exception.

"},{"location":"reference/dispatch/#dispatch.Input","title":"Input","text":"
Input(req: RunRequest)\n

The input to a primitive function.

Functions always take a single argument of type Input. When the function is run for the first time, it receives the input. When the function is a coroutine that's resuming after a yield point, it receives the results of the yield directive. Use the is_first_call and is_resume properties to differentiate between the two cases.

This class is intended to be used as read-only.

"},{"location":"reference/dispatch/#dispatch.Input.input_arguments","title":"input_arguments","text":"
input_arguments() -> Tuple[Tuple[Any, ...], Dict[str, Any]]\n

Returns positional and keyword arguments carried by the input.

"},{"location":"reference/dispatch/#dispatch.Output","title":"Output dataclass","text":"
Output(proto: RunResponse)\n

The output of a primitive function.

This class is meant to be instantiated and returned by authors of functions to indicate the follow up action they need to take. Use the various class methods create an instance of this class. For example Output.value() or Output.poll().

"},{"location":"reference/dispatch/#dispatch.Output.value","title":"value classmethod","text":"
value(\n    value: Any, status: Optional[Status] = None\n) -> Output\n

Terminally exit the function with the provided return value.

"},{"location":"reference/dispatch/#dispatch.Output.error","title":"error classmethod","text":"
error(error: Error) -> Output\n

Terminally exit the function with the provided error.

"},{"location":"reference/dispatch/#dispatch.Output.tail_call","title":"tail_call classmethod","text":"
tail_call(\n    tail_call: Call, status: Status = Status.OK\n) -> Output\n

Terminally exit the function, and instruct the orchestrator to tail call the specified function.

"},{"location":"reference/dispatch/#dispatch.Output.exit","title":"exit classmethod","text":"
exit(\n    result: Optional[CallResult] = None,\n    tail_call: Optional[Call] = None,\n    status: Status = Status.OK,\n) -> Output\n

Terminally exit the function.

"},{"location":"reference/dispatch/#dispatch.Output.poll","title":"poll classmethod","text":"
poll(\n    coroutine_state: Optional[bytes] = None,\n    calls: Optional[List[Call]] = None,\n    min_results: int = 1,\n    max_results: int = 10,\n    max_wait_seconds: Optional[int] = None,\n) -> Output\n

Suspend the function with a set of Calls, instructing the orchestrator to resume the function with the provided state when call results are ready.

"},{"location":"reference/dispatch/#dispatch.Status","title":"Status","text":"

Bases: int, Enum

Enumeration of the possible values that can be used in the return status of functions.

"},{"location":"reference/dispatch/#dispatch.all","title":"all","text":"
all(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until all coroutines return or any coroutine raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.any","title":"any","text":"
any(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or all coroutines raises an error. If all coroutines fail with uncaught exceptions, the exception(s) will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.call","title":"call","text":"
call(call: Call) -> Any\n

Make an asynchronous function call and return its result. If the function call fails with an error, the error is raised.

"},{"location":"reference/dispatch/#dispatch.gather","title":"gather","text":"
gather(*awaitables: Awaitable[Any]) -> List[Any]\n

Alias for all.

"},{"location":"reference/dispatch/#dispatch.race","title":"race","text":"
race(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.run","title":"run","text":"
run(\n    init: Optional[Callable[P, None]] = None,\n    *args: args,\n    **kwargs: kwargs\n)\n

Run the default dispatch server. The default server uses a function registry where functions tagged by the @dispatch.function decorator are registered.

This function is intended to be used with the dispatch CLI tool, which automatically configures environment variables to connect the local server to the Dispatch bridge API.

Parameters:

Name Type Description Default init Optional[Callable[P, None]]

An initialization function called after binding the server address but before entering the event loop to handle requests.

None args args

Positional arguments to pass to the entrypoint.

() kwargs kwargs

Keyword arguments to pass to the entrypoint.

{}"},{"location":"reference/dispatch/#dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Create a new batch object.

"},{"location":"reference/dispatch/aiohttp/","title":" aiohttp","text":""},{"location":"reference/dispatch/aiohttp/#dispatch.aiohttp","title":"aiohttp","text":""},{"location":"reference/dispatch/aiohttp/#dispatch.aiohttp.Dispatch","title":"Dispatch","text":"
Dispatch(\n    registry: Registry,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n)\n

Bases: Application

A Dispatch instance servicing as a http server.

Parameters:

Name Type Description Default registry Registry

The registry of functions to be serviced.

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

The verification key to use for requests.

None"},{"location":"reference/dispatch/asyncio/","title":" asyncio","text":""},{"location":"reference/dispatch/asyncio/#dispatch.asyncio","title":"asyncio","text":""},{"location":"reference/dispatch/asyncio/#dispatch.asyncio.Runner","title":"Runner","text":"
Runner()\n

Runner is a class similar to asyncio.Runner but that we use for backward compatibility with Python 3.10 and earlier.

"},{"location":"reference/dispatch/coroutine/","title":" coroutine","text":""},{"location":"reference/dispatch/coroutine/#dispatch.coroutine","title":"coroutine","text":""},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.AnyException","title":"AnyException","text":"
AnyException(exceptions: List[Exception])\n

Bases: RuntimeError

Error indicating that all coroutines passed to any() failed with an exception.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.call","title":"call","text":"
call(call: Call) -> Any\n

Make an asynchronous function call and return its result. If the function call fails with an error, the error is raised.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.gather","title":"gather","text":"
gather(*awaitables: Awaitable[Any]) -> List[Any]\n

Alias for all.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.all","title":"all","text":"
all(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until all coroutines return or any coroutine raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.any","title":"any","text":"
any(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or all coroutines raises an error. If all coroutines fail with uncaught exceptions, the exception(s) will be re-raised here.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.race","title":"race","text":"
race(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/error/","title":" error","text":""},{"location":"reference/dispatch/error/#dispatch.error","title":"error","text":""},{"location":"reference/dispatch/error/#dispatch.error.DispatchError","title":"DispatchError","text":"

Bases: Exception

Base class for Dispatch exceptions.

"},{"location":"reference/dispatch/error/#dispatch.error.TimeoutError","title":"TimeoutError","text":"

Bases: DispatchError, TimeoutError

Operation timed out.

"},{"location":"reference/dispatch/error/#dispatch.error.ThrottleError","title":"ThrottleError","text":"

Bases: DispatchError

Operation was throttled.

"},{"location":"reference/dispatch/error/#dispatch.error.InvalidArgumentError","title":"InvalidArgumentError","text":"

Bases: DispatchError, ValueError

Invalid argument was received.

"},{"location":"reference/dispatch/error/#dispatch.error.InvalidResponseError","title":"InvalidResponseError","text":"

Bases: DispatchError, ValueError

Invalid response was received.

"},{"location":"reference/dispatch/error/#dispatch.error.TemporaryError","title":"TemporaryError","text":"

Bases: DispatchError

Generic temporary error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.PermanentError","title":"PermanentError","text":"

Bases: DispatchError

Generic permanent error. Used in cases where a more specific error class is not available, but the operation that failed should not be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.IncompatibleStateError","title":"IncompatibleStateError","text":"

Bases: DispatchError

Coroutine state is incompatible with the current interpreter and application revision.

"},{"location":"reference/dispatch/error/#dispatch.error.DNSError","title":"DNSError","text":"

Bases: DispatchError, ConnectionError

Generic DNS error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.TCPError","title":"TCPError","text":"

Bases: DispatchError, ConnectionError

Generic TCP error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.HTTPError","title":"HTTPError","text":"

Bases: DispatchError, ConnectionError

Generic HTTP error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.UnauthenticatedError","title":"UnauthenticatedError","text":"

Bases: DispatchError

The caller did not authenticate with the resource.

"},{"location":"reference/dispatch/error/#dispatch.error.PermissionDeniedError","title":"PermissionDeniedError","text":"

Bases: DispatchError, PermissionError

The caller does not have access to the resource.

"},{"location":"reference/dispatch/error/#dispatch.error.NotFoundError","title":"NotFoundError","text":"

Bases: DispatchError

Generic not found error. Used in cases where a more specific error class is not available, but the operation that failed should not be attempted again.

"},{"location":"reference/dispatch/fastapi/","title":" fastapi","text":""},{"location":"reference/dispatch/fastapi/#dispatch.fastapi","title":"fastapi","text":"

Integration of Dispatch functions with FastAPI.

Example:

import fastapi\nfrom dispatch.fastapi import Dispatch\n\napp = fastapi.FastAPI()\ndispatch = Dispatch(app, api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@app.get(\"/\")\ndef read_root():\n    my_function.dispatch()\n
"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch","title":"Dispatch","text":"
Dispatch(\n    app: FastAPI,\n    endpoint: Optional[str] = None,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

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 endpoint Optional[str]

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

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 api_key Optional[str]

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

None api_url Optional[str]

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.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/flask/","title":" flask","text":""},{"location":"reference/dispatch/flask/#dispatch.flask","title":"flask","text":"

Integration of Dispatch functions with Flask.

Example:

from flask import Flask\nfrom dispatch.flask import Dispatch\n\napp = Flask(__name__)\ndispatch = Dispatch(app, api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@app.get(\"/\")\ndef read_root():\n    my_function.dispatch()\n
"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch","title":"Dispatch","text":"
Dispatch(\n    app: Flask,\n    endpoint: Optional[str] = None,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

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 endpoint Optional[str]

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

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 api_key Optional[str]

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

None api_url Optional[str]

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.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/","title":" function","text":""},{"location":"reference/dispatch/function/#dispatch.function","title":"function","text":""},{"location":"reference/dispatch/function/#dispatch.function.PrimitiveFunctionType","title":"PrimitiveFunctionType module-attribute","text":"
PrimitiveFunctionType: TypeAlias = Callable[\n    [Input], Awaitable[Output]\n]\n

A primitive function is a function that accepts a dispatch.proto.Input and unconditionally returns a dispatch.proto.Output. It must not raise exceptions.

"},{"location":"reference/dispatch/function/#dispatch.function.Function","title":"Function","text":"
Function(\n    endpoint: str,\n    client: Client,\n    name: str,\n    primitive_func: PrimitiveFunctionType,\n)\n

Bases: PrimitiveFunction, Generic[P, T]

Callable wrapper around a function meant to be used throughout the Dispatch Python SDK.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.__call__","title":"__call__","text":"
__call__(\n    *args: args, **kwargs: kwargs\n) -> Coroutine[Any, Any, T]\n

Call the function asynchronously (through Dispatch), and return a coroutine that can be awaited to retrieve the call result.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.dispatch","title":"dispatch","text":"
dispatch(*args: args, **kwargs: kwargs) -> DispatchID\n

Dispatch an asynchronous call to the function without waiting for a result.

The Registry this function was registered with must be initialized with a Client / api_key for this call facility to be available.

Parameters:

Name Type Description Default *args args

Positional arguments for the function.

() **kwargs kwargs

Keyword arguments for the function.

{}

Returns:

Name Type Description DispatchID DispatchID

ID of the dispatched call.

Raises:

Type Description RuntimeError

if a Dispatch client has not been configured.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.build_call","title":"build_call","text":"
build_call(\n    *args: args,\n    correlation_id: Optional[int] = None,\n    **kwargs: kwargs\n) -> Call\n

Create a Call for this function with the provided input. Useful to generate calls when using the Client.

Parameters:

Name Type Description Default *args args

Positional arguments for the function.

() correlation_id Optional[int]

optional arbitrary integer the caller can use to match this call to a call result.

None **kwargs kwargs

Keyword arguments for the function.

{}

Returns:

Name Type Description Call Call

can be passed to Client.dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Reset","title":"Reset","text":"
Reset(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n)\n

Bases: TailCall

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry","title":"Registry","text":"
Registry(\n    endpoint: Optional[str] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Registry of functions.

Parameters:

Name Type Description Default endpoint Optional[str]

URL of the endpoint that the function is accessible from. Uses the value of the DISPATCH_ENDPOINT_URL environment variable by default.

None api_key Optional[str]

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

None api_url Optional[str]

The URL of the Dispatch API to use when dispatching calls to functions. 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.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Client","title":"Client","text":"
Client(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Client for the Dispatch API.

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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 the API key is missing.

"},{"location":"reference/dispatch/function/#dispatch.function.Client.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Client.dispatch","title":"dispatch","text":"
dispatch(calls: Iterable[Call]) -> List[DispatchID]\n

Dispatch function calls.

Parameters:

Name Type Description Default calls Iterable[Call]

Calls to dispatch.

required

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order as the inputs.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch","title":"Batch","text":"
Batch(client: Client)\n

A batch of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.add","title":"add","text":"
add(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n) -> Batch\n

Add a call to the specified function to the batch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.add_call","title":"add_call","text":"
add_call(call: Call) -> Batch\n

Add a Call to the batch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.dispatch","title":"dispatch","text":"
dispatch() -> List[DispatchID]\n

Dispatch dispatches the calls asynchronously.

The batch is reset when the calls are dispatched successfully.

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order they

List[DispatchID]

were added.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.reset","title":"reset","text":"
reset()\n

Reset the batch.

"},{"location":"reference/dispatch/http/","title":" http","text":""},{"location":"reference/dispatch/http/#dispatch.http","title":"http","text":"

Integration of Dispatch functions with http.

"},{"location":"reference/dispatch/http/#dispatch.http.Dispatch","title":"Dispatch","text":"
Dispatch(\n    registry: Registry,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n)\n

A Dispatch instance servicing as a http server.

Parameters:

Name Type Description Default registry Registry

The registry of functions to be serviced.

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

The verification key to use for requests.

None"},{"location":"reference/dispatch/id/","title":" id","text":""},{"location":"reference/dispatch/id/#dispatch.id","title":"id","text":""},{"location":"reference/dispatch/id/#dispatch.id.DispatchID","title":"DispatchID module-attribute","text":"
DispatchID: TypeAlias = str\n

Unique identifier in Dispatch.

It should be treated as an opaque value.

"},{"location":"reference/dispatch/proto/","title":" proto","text":""},{"location":"reference/dispatch/proto/#dispatch.proto","title":"proto","text":""},{"location":"reference/dispatch/proto/#dispatch.proto.TailCall","title":"TailCall","text":"
TailCall(\n    call: Call, status: Status = Status.TEMPORARY_ERROR\n)\n

Bases: Exception

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Input","title":"Input","text":"
Input(req: RunRequest)\n

The input to a primitive function.

Functions always take a single argument of type Input. When the function is run for the first time, it receives the input. When the function is a coroutine that's resuming after a yield point, it receives the results of the yield directive. Use the is_first_call and is_resume properties to differentiate between the two cases.

This class is intended to be used as read-only.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Input.input_arguments","title":"input_arguments","text":"
input_arguments() -> Tuple[Tuple[Any, ...], Dict[str, Any]]\n

Returns positional and keyword arguments carried by the input.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Arguments","title":"Arguments dataclass","text":"
Arguments(args: Tuple[Any, ...], kwargs: Dict[str, Any])\n

A container for positional and keyword arguments.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output","title":"Output dataclass","text":"
Output(proto: RunResponse)\n

The output of a primitive function.

This class is meant to be instantiated and returned by authors of functions to indicate the follow up action they need to take. Use the various class methods create an instance of this class. For example Output.value() or Output.poll().

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.value","title":"value classmethod","text":"
value(\n    value: Any, status: Optional[Status] = None\n) -> Output\n

Terminally exit the function with the provided return value.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.error","title":"error classmethod","text":"
error(error: Error) -> Output\n

Terminally exit the function with the provided error.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.tail_call","title":"tail_call classmethod","text":"
tail_call(\n    tail_call: Call, status: Status = Status.OK\n) -> Output\n

Terminally exit the function, and instruct the orchestrator to tail call the specified function.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.exit","title":"exit classmethod","text":"
exit(\n    result: Optional[CallResult] = None,\n    tail_call: Optional[Call] = None,\n    status: Status = Status.OK,\n) -> Output\n

Terminally exit the function.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.poll","title":"poll classmethod","text":"
poll(\n    coroutine_state: Optional[bytes] = None,\n    calls: Optional[List[Call]] = None,\n    min_results: int = 1,\n    max_results: int = 10,\n    max_wait_seconds: Optional[int] = None,\n) -> Output\n

Suspend the function with a set of Calls, instructing the orchestrator to resume the function with the provided state when call results are ready.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Call","title":"Call dataclass","text":"
Call(\n    function: str,\n    input: Optional[Any] = None,\n    endpoint: Optional[str] = None,\n    correlation_id: Optional[int] = None,\n)\n

Instruction to call a function.

Though this class can be built manually, it is recommended to use the with_call method of a Function instead.

"},{"location":"reference/dispatch/proto/#dispatch.proto.CallResult","title":"CallResult dataclass","text":"
CallResult(\n    correlation_id: Optional[int] = None,\n    output: Optional[Any] = None,\n    error: Optional[Error] = None,\n    dispatch_id: DispatchID = \"\",\n)\n

Result of a Call.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error","title":"Error dataclass","text":"
Error(\n    status: Status,\n    type: str,\n    message: str,\n    value: Optional[Exception] = None,\n    traceback: Optional[bytes] = None,\n)\n

Error when running a function.

This is not a Python exception, but potentially part of a CallResult or Output.

Parameters:

Name Type Description Default status Status

categorization of the error.

required type str

arbitrary string, used for humans.

required message str

arbitrary message.

required value Optional[Exception]

arbitrary exception from which the error is derived. Optional.

None

Raises:

Type Description ValueError

Neither type or message was provided or status is invalid.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.from_exception","title":"from_exception classmethod","text":"
from_exception(\n    ex: Exception, status: Optional[Status] = None\n) -> Error\n

Create an Error from a Python exception, using its class qualified named as type.

The status tries to be inferred, but can be overridden. If it is not provided or cannot be inferred, it defaults to TEMPORARY_ERROR.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.to_exception","title":"to_exception","text":"
to_exception() -> Exception\n

Returns an equivalent exception.

"},{"location":"reference/dispatch/scheduler/","title":" scheduler","text":""},{"location":"reference/dispatch/scheduler/#dispatch.scheduler","title":"scheduler","text":""},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CoroutineResult","title":"CoroutineResult dataclass","text":"
CoroutineResult(\n    coroutine_id: CoroutineID,\n    value: Optional[Any] = None,\n    error: Optional[Exception] = None,\n    call: Optional[Call] = None,\n    status: Status = Status.OK,\n)\n

The result from running a coroutine to completion.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CallResult","title":"CallResult dataclass","text":"
CallResult(\n    call_id: CallID,\n    value: Optional[Any] = None,\n    error: Optional[Exception] = None,\n)\n

The result of an asynchronous function call.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CallFuture","title":"CallFuture dataclass","text":"
CallFuture(\n    result: Optional[CallResult] = None,\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.call() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.AllFuture","title":"AllFuture dataclass","text":"
AllFuture(\n    order: List[CoroutineID] = list(),\n    waiting: Set[CoroutineID] = set(),\n    results: Dict[CoroutineID, CoroutineResult] = dict(),\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.all() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.AnyFuture","title":"AnyFuture dataclass","text":"
AnyFuture(\n    order: List[CoroutineID] = list(),\n    waiting: Set[CoroutineID] = set(),\n    first_result: Optional[CoroutineResult] = None,\n    errors: Dict[CoroutineID, Exception] = dict(),\n    generic_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.any() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.RaceFuture","title":"RaceFuture dataclass","text":"
RaceFuture(\n    waiting: Set[CoroutineID] = set(),\n    first_result: Optional[CoroutineResult] = None,\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.race() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.Coroutine","title":"Coroutine dataclass","text":"
Coroutine(\n    id: CoroutineID,\n    parent_id: Optional[CoroutineID],\n    coroutine: Union[DurableCoroutine, DurableGenerator],\n    result: Optional[Future] = None,\n)\n

An in-flight coroutine.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.State","title":"State dataclass","text":"
State(\n    version: str,\n    suspended: Dict[CoroutineID, Coroutine],\n    ready: List[Coroutine],\n    next_coroutine_id: int,\n    next_call_id: int,\n    prev_callers: List[Coroutine],\n    outstanding_calls: int,\n)\n

State of the scheduler and the coroutines it's managing.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.OneShotScheduler","title":"OneShotScheduler","text":"
OneShotScheduler(\n    entry_point: Callable,\n    version: str = sys.version,\n    poll_min_results: int = 1,\n    poll_max_results: int = 10,\n    poll_max_wait_seconds: Optional[int] = None,\n)\n

Scheduler for local coroutines.

It's a one-shot scheduler because it only runs one round of scheduling. When all local coroutines are suspended, the scheduler yields to Dispatch to take over scheduling asynchronous calls.

Parameters:

Name Type Description Default entry_point Callable

Entry point for the main coroutine.

required version str

Version string to attach to scheduler/coroutine state. If the scheduler sees a version mismatch, it will respond to Dispatch with an INCOMPATIBLE_STATE status code.

version poll_min_results int

Minimum number of call results to wait for before coroutine execution should continue. Dispatch waits until this many results are available, or the poll_max_wait_seconds timeout is reached, whichever comes first.

1 poll_max_results int

Maximum number of calls to receive from Dispatch per request.

10 poll_max_wait_seconds Optional[int]

Maximum amount of time to suspend coroutines while waiting for call results. Optional.

None"},{"location":"reference/dispatch/status/","title":" status","text":""},{"location":"reference/dispatch/status/#dispatch.status","title":"status","text":""},{"location":"reference/dispatch/status/#dispatch.status.Status","title":"Status","text":"

Bases: int, Enum

Enumeration of the possible values that can be used in the return status of functions.

"},{"location":"reference/dispatch/status/#dispatch.status.status_for_error","title":"status_for_error","text":"
status_for_error(error: BaseException) -> Status\n

Returns a Status that corresponds to the specified error.

"},{"location":"reference/dispatch/status/#dispatch.status.status_for_output","title":"status_for_output","text":"
status_for_output(output: Any) -> Status\n

Returns a Status that corresponds to the specified output value.

"},{"location":"reference/dispatch/status/#dispatch.status.register_error_type","title":"register_error_type","text":"
register_error_type(\n    error_type: Type[Exception],\n    status_or_handler: Union[\n        Status, Callable[[Exception], Status]\n    ],\n)\n

Register an error type to Status mapping.

The caller can either register a base exception and a handler, which derives a Status from errors of this type. Or, if there's only one exception to Status mapping to register, the caller can simply pass the exception class and the associated Status.

"},{"location":"reference/dispatch/status/#dispatch.status.register_output_type","title":"register_output_type","text":"
register_output_type(\n    output_type: Type[Any],\n    status_or_handler: Union[\n        Status, Callable[[Any], Status]\n    ],\n)\n

Register an output type to Status mapping.

The caller can either register a base class and a handler, which derives a Status from other classes of this type. Or, if there's only one output class to Status mapping to register, the caller can simply pass the class and the associated Status.

"},{"location":"reference/dispatch/experimental/","title":"Index","text":""},{"location":"reference/dispatch/experimental/#dispatch.experimental","title":"experimental","text":""},{"location":"reference/dispatch/experimental/lambda_handler/","title":" lambda_handler","text":""},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler","title":"lambda_handler","text":"

Integration of Dispatch programmable endpoints for FastAPI.

Example:

from dispatch.experimental.lambda_handler import Dispatch\n\ndispatch = Dispatch(api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@dispatch.function\ndef entrypoint():\n    my_function()\n\ndef handler(event, context):\n    dispatch.handle(event, context, entrypoint=\"entrypoint\")\n
"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch","title":"Dispatch","text":"
Dispatch(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/experimental/durable/","title":"Index","text":""},{"location":"reference/dispatch/experimental/durable/#dispatch.experimental.durable","title":"durable","text":"

A decorator that makes generators and coroutines serializable.

This module defines a @durable decorator that can be applied to generator functions and async functions. The generator and coroutine instances they create can be pickled.

Example usage:

import pickle\nfrom dispatch.experimental.durable import durable\n\n@durable\ndef my_generator():\n    for i in range(3):\n        yield i\n\n# Run the generator to its first yield point:\ng = my_generator()\nprint(next(g))  # 0\n\n# Make a copy, and consume the remaining items:\nb = pickle.dumps(g)\ng2 = pickle.loads(b)\nprint(next(g2))  # 1\nprint(next(g2))  # 2\n\n# The original is not affected:\nprint(next(g))  # 1\nprint(next(g))  # 2\n
"},{"location":"reference/dispatch/experimental/durable/#dispatch.experimental.durable.durable","title":"durable","text":"
durable(fn: Callable) -> Callable\n

Returns a \"durable\" function that creates serializable generators or coroutines.

"},{"location":"reference/dispatch/experimental/durable/function/","title":" function","text":""},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function","title":"function","text":""},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableFunction","title":"DurableFunction","text":"
DurableFunction(fn: FunctionType)\n

A wrapper for generator functions and async functions that make their generator and coroutine instances serializable.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.Serializable","title":"Serializable","text":"
Serializable(\n    g: Union[GeneratorType, CoroutineType],\n    registered_fn: RegisteredFunction,\n    wrapped_coroutine: Union[DurableCoroutine, None],\n    *args: Any,\n    **kwargs: Any\n)\n

A wrapper for a generator or coroutine that makes it serializable.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableCoroutine","title":"DurableCoroutine","text":"
DurableCoroutine(\n    coroutine: CoroutineType,\n    registered_fn: RegisteredFunction,\n    *args: Any,\n    **kwargs: Any\n)\n

Bases: Serializable, Coroutine[_YieldT, _SendT, _ReturnT]

A wrapper for a coroutine that makes it serializable (can be pickled). Instances behave like the coroutines they wrap.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableGenerator","title":"DurableGenerator","text":"
DurableGenerator(\n    generator: GeneratorType,\n    registered_fn: RegisteredFunction,\n    coroutine: Optional[DurableCoroutine],\n    *args: Any,\n    **kwargs: Any\n)\n

Bases: Serializable, Generator[_YieldT, _SendT, _ReturnT]

A wrapper for a generator that makes it serializable (can be pickled). Instances behave like the generators they wrap.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.durable","title":"durable","text":"
durable(fn: Callable) -> Callable\n

Returns a \"durable\" function that creates serializable generators or coroutines.

"},{"location":"reference/dispatch/experimental/durable/registry/","title":" registry","text":""},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry","title":"registry","text":""},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.RegisteredFunction","title":"RegisteredFunction dataclass","text":"
RegisteredFunction(\n    fn: FunctionType,\n    key: str,\n    filename: str,\n    lineno: int,\n    hash: str,\n)\n

A function that can be referenced in durable state.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.register_function","title":"register_function","text":"
register_function(fn: FunctionType) -> RegisteredFunction\n

Register a function in the in-memory function registry.

When serializing a registered function, a reference to the function is stored along with details about its location and contents. When deserializing the function, the registry is consulted in order to find the function associated with the reference (and in order to check whether the function is the same).

Parameters:

Name Type Description Default fn FunctionType

The function to register.

required

Returns:

Name Type Description str RegisteredFunction

Unique identifier for the function.

Raises:

Type Description ValueError

The function conflicts with another registered function.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.lookup_function","title":"lookup_function","text":"
lookup_function(key: str) -> RegisteredFunction\n

Lookup a registered function by key.

Parameters:

Name Type Description Default key str

Unique identifier for the function.

required

Returns:

Name Type Description RegisteredFunction RegisteredFunction

the function that was registered with the specified key.

Raises:

Type Description KeyError

A function has not been registered with this key.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.clear_functions","title":"clear_functions","text":"
clear_functions()\n

Clear functions clears the registry.

"},{"location":"reference/dispatch/integrations/","title":"Index","text":""},{"location":"reference/dispatch/integrations/#dispatch.integrations","title":"integrations","text":""},{"location":"reference/dispatch/integrations/http/","title":" http","text":""},{"location":"reference/dispatch/integrations/http/#dispatch.integrations.http","title":"http","text":""},{"location":"reference/dispatch/integrations/http/#dispatch.integrations.http.http_response_code_status","title":"http_response_code_status","text":"
http_response_code_status(code: int) -> Status\n

Returns a Status that's broadly equivalent to an HTTP response status code.

"},{"location":"reference/dispatch/integrations/httpx/","title":" httpx","text":""},{"location":"reference/dispatch/integrations/httpx/#dispatch.integrations.httpx","title":"httpx","text":""},{"location":"reference/dispatch/integrations/openai/","title":" openai","text":""},{"location":"reference/dispatch/integrations/openai/#dispatch.integrations.openai","title":"openai","text":""},{"location":"reference/dispatch/integrations/requests/","title":" requests","text":""},{"location":"reference/dispatch/integrations/requests/#dispatch.integrations.requests","title":"requests","text":""},{"location":"reference/dispatch/integrations/slack/","title":" slack","text":""},{"location":"reference/dispatch/integrations/slack/#dispatch.integrations.slack","title":"slack","text":""},{"location":"reference/dispatch/signature/","title":"Index","text":""},{"location":"reference/dispatch/signature/#dispatch.signature","title":"signature","text":""},{"location":"reference/dispatch/signature/#dispatch.signature.sign_request","title":"sign_request","text":"
sign_request(\n    request: Request,\n    key: Ed25519PrivateKey,\n    created: datetime,\n)\n

Sign a request using HTTP Message Signatures.

The function adds three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The signature covers the request method, the URL host and path, the Content-Type header, and the request body. At this time, an ED25519 signature is generated with a hard-coded key ID of \"default\".

Parameters:

Name Type Description Default request Request

The request to sign.

required key Ed25519PrivateKey

The Ed25519 private key to use to generate the signature.

required created datetime

The times at which the signature is created.

required"},{"location":"reference/dispatch/signature/#dispatch.signature.verify_request","title":"verify_request","text":"
verify_request(\n    request: Request,\n    key: Ed25519PublicKey,\n    max_age: timedelta,\n)\n

Verify a request containing an HTTP Message Signature.

The function checks three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The function checks signatures that cover at least the request method, the URL host and path, the Content-Type header, and the request body (via the Content-Digest header). At this time, signatures must use a hard-coded key ID of \"default\".

Parameters:

Name Type Description Default request Request

The request to verify.

required key Ed25519PublicKey

The Ed25519 public key to use to verify the signature.

required max_age timedelta

The maximum age of the signature.

required"},{"location":"reference/dispatch/signature/digest/","title":" digest","text":""},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest","title":"digest","text":""},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest.generate_content_digest","title":"generate_content_digest","text":"
generate_content_digest(body: Union[str, bytes]) -> str\n

Returns a SHA-512 Content-Digest header, according to https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers-13

"},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest.verify_content_digest","title":"verify_content_digest","text":"
verify_content_digest(\n    digest_header: Union[str, bytes],\n    body: Union[str, bytes],\n)\n

Verify a SHA-256 or SHA-512 Content-Digest header matches a request body.

"},{"location":"reference/dispatch/signature/key/","title":" key","text":""},{"location":"reference/dispatch/signature/key/#dispatch.signature.key","title":"key","text":""},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.KeyResolver","title":"KeyResolver dataclass","text":"
KeyResolver(\n    key_id: str,\n    public_key: Optional[Ed25519PublicKey] = None,\n    private_key: Optional[Ed25519PrivateKey] = None,\n)\n

Bases: HTTPSignatureKeyResolver

KeyResolver provides public and private keys.

At this time, multiple keys and/or key types are not supported. Keys must be Ed25519 keys and have an ID of DEFAULT_KEY_ID.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.public_key_from_pem","title":"public_key_from_pem","text":"
public_key_from_pem(\n    pem: Union[str, bytes]\n) -> Ed25519PublicKey\n

Returns an Ed25519 public key given a PEM representation.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.public_key_from_bytes","title":"public_key_from_bytes","text":"
public_key_from_bytes(key: bytes) -> Ed25519PublicKey\n

Returns an Ed25519 public key from 32 raw bytes.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.private_key_from_pem","title":"private_key_from_pem","text":"
private_key_from_pem(\n    pem: Union[str, bytes], password: Optional[bytes] = None\n) -> Ed25519PrivateKey\n

Returns an Ed25519 private key given a PEM representation and optional password.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.private_key_from_bytes","title":"private_key_from_bytes","text":"
private_key_from_bytes(key: bytes) -> Ed25519PrivateKey\n

Returns an Ed25519 private key from 32 raw bytes.

"},{"location":"reference/dispatch/signature/request/","title":" request","text":""},{"location":"reference/dispatch/signature/request/#dispatch.signature.request","title":"request","text":""},{"location":"reference/dispatch/signature/request/#dispatch.signature.request.Request","title":"Request dataclass","text":"
Request(\n    method: str,\n    url: str,\n    headers: CaseInsensitiveDict,\n    body: Union[str, bytes],\n)\n

A framework-agnostic representation of an HTTP request.

"},{"location":"reference/dispatch/test/","title":"Index","text":""},{"location":"reference/dispatch/test/#dispatch.test","title":"test","text":""},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient","title":"EndpointClient","text":"
EndpointClient(\n    http_client: HttpClient,\n    signing_key: Optional[Ed25519PrivateKey] = None,\n)\n

Test client for a Dispatch programmable endpoint.

Note that this is different from dispatch.Client, which is a client for the Dispatch API. The EndpointClient is a client similar to the one that Dispatch itself would use to interact with an endpoint that provides functions.

Parameters:

Name Type Description Default http_client HttpClient

Client to use to make HTTP requests.

required signing_key Optional[Ed25519PrivateKey]

Optional Ed25519 private key to use to sign requests.

None"},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient.run","title":"run","text":"
run(request: RunRequest) -> RunResponse\n

Send a run request to an endpoint and return its response.

Parameters:

Name Type Description Default request RunRequest

A FunctionService Run request.

required

Returns:

Name Type Description RunResponse RunResponse

the response from the endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer","title":"DispatchServer","text":"
DispatchServer(\n    service: DispatchServiceServicer,\n    hostname: str = \"127.0.0.1\",\n    port: int = 0,\n)\n

Test server for a Dispatch service. This is useful for testing a mock version of Dispatch locally (e.g. see dispatch.test.DispatchService).

Parameters:

Name Type Description Default service DispatchServiceServicer

Dispatch service to serve.

required hostname str

Hostname to bind to.

'127.0.0.1' port int

Port to bind to, or 0 to bind to any available port.

0"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.url","title":"url property","text":"
url\n

Returns the URL of the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.start","title":"start","text":"
start()\n

Start the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.wait","title":"wait","text":"
wait()\n

Block until the server terminates.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.stop","title":"stop","text":"
stop()\n

Stop the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService","title":"DispatchService","text":"
DispatchService(\n    endpoint_client: EndpointClient,\n    api_key: Optional[str] = None,\n    retry_on_status: Optional[Set[Status]] = None,\n    collect_roundtrips: bool = False,\n)\n

Bases: DispatchServiceServicer

Test instance of Dispatch that provides the bare minimum functionality required to test functions locally.

Parameters:

Name Type Description Default endpoint_client EndpointClient

Client to use to interact with the local Dispatch endpoint (that provides the functions).

required api_key Optional[str]

Expected API key on requests to the service. If omitted, the value of the DISPATCH_API_KEY environment variable is used instead.

None retry_on_status Optional[Set[Status]]

Set of status codes to enable retries for.

None collect_roundtrips bool

Enable collection of request/response round-trips to the configured endpoint.

False"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.Dispatch","title":"Dispatch","text":"
Dispatch(request: DispatchRequest, context)\n

RPC handler for Dispatch requests. Requests are only queued for processing here.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.dispatch_calls","title":"dispatch_calls","text":"
dispatch_calls()\n

Synchronously dispatch pending function calls to the configured endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.start","title":"start","text":"
start()\n

Start starts a background thread to continuously dispatch calls to the configured endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.stop","title":"stop","text":"
stop()\n

Stop stops the background thread that's dispatching calls to the configured endpoint.

"},{"location":"reference/dispatch/test/client/","title":" client","text":""},{"location":"reference/dispatch/test/client/#dispatch.test.client","title":"client","text":""},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient","title":"EndpointClient","text":"
EndpointClient(\n    http_client: HttpClient,\n    signing_key: Optional[Ed25519PrivateKey] = None,\n)\n

Test client for a Dispatch programmable endpoint.

Note that this is different from dispatch.Client, which is a client for the Dispatch API. The EndpointClient is a client similar to the one that Dispatch itself would use to interact with an endpoint that provides functions.

Parameters:

Name Type Description Default http_client HttpClient

Client to use to make HTTP requests.

required signing_key Optional[Ed25519PrivateKey]

Optional Ed25519 private key to use to sign requests.

None"},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient.run","title":"run","text":"
run(request: RunRequest) -> RunResponse\n

Send a run request to an endpoint and return its response.

Parameters:

Name Type Description Default request RunRequest

A FunctionService Run request.

required

Returns:

Name Type Description RunResponse RunResponse

the response from the endpoint.

"},{"location":"reference/dispatch/test/fastapi/","title":" fastapi","text":""},{"location":"reference/dispatch/test/fastapi/#dispatch.test.fastapi","title":"fastapi","text":""},{"location":"reference/dispatch/test/fastapi/#dispatch.test.fastapi.http_client","title":"http_client","text":"
http_client(app: FastAPI) -> HttpClient\n

Build a client for a FastAPI app.

"},{"location":"reference/dispatch/test/flask/","title":" flask","text":""},{"location":"reference/dispatch/test/flask/#dispatch.test.flask","title":"flask","text":""},{"location":"reference/dispatch/test/flask/#dispatch.test.flask.http_client","title":"http_client","text":"
http_client(app: Flask) -> HttpClient\n

Build a client for a Flask app.

"},{"location":"reference/dispatch/test/http/","title":" http","text":""},{"location":"reference/dispatch/test/http/#dispatch.test.http","title":"http","text":""},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpResponse","title":"HttpResponse dataclass","text":"
HttpResponse(status_code: int, body: bytes)\n

Bases: Protocol

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpResponse.raise_for_status","title":"raise_for_status","text":"
raise_for_status()\n

Raise an exception on non-2xx responses.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient","title":"HttpClient","text":"

Bases: Protocol

Protocol for HTTP clients.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.get","title":"get","text":"
get(\n    url: str, headers: Mapping[str, str] = {}\n) -> HttpResponse\n

Make a GET request.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.post","title":"post","text":"
post(\n    url: str, body: bytes, headers: Mapping[str, str] = {}\n) -> HttpResponse\n

Make a POST request.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.url_for","title":"url_for","text":"
url_for(path: str) -> str\n

Get the fully-qualified URL for a path.

"},{"location":"reference/dispatch/test/httpx/","title":" httpx","text":""},{"location":"reference/dispatch/test/httpx/#dispatch.test.httpx","title":"httpx","text":""},{"location":"reference/dispatch/test/server/","title":" server","text":""},{"location":"reference/dispatch/test/server/#dispatch.test.server","title":"server","text":""},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer","title":"DispatchServer","text":"
DispatchServer(\n    service: DispatchServiceServicer,\n    hostname: str = \"127.0.0.1\",\n    port: int = 0,\n)\n

Test server for a Dispatch service. This is useful for testing a mock version of Dispatch locally (e.g. see dispatch.test.DispatchService).

Parameters:

Name Type Description Default service DispatchServiceServicer

Dispatch service to serve.

required hostname str

Hostname to bind to.

'127.0.0.1' port int

Port to bind to, or 0 to bind to any available port.

0"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.url","title":"url property","text":"
url\n

Returns the URL of the server.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.start","title":"start","text":"
start()\n

Start the server.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.wait","title":"wait","text":"
wait()\n

Block until the server terminates.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.stop","title":"stop","text":"
stop()\n

Stop the server.

"},{"location":"reference/dispatch/test/service/","title":" service","text":""},{"location":"reference/dispatch/test/service/#dispatch.test.service","title":"service","text":""},{"location":"reference/dispatch/test/service/#dispatch.test.service.RoundTrip","title":"RoundTrip module-attribute","text":"
RoundTrip: TypeAlias = Tuple[RunRequest, RunResponse]\n

A request to a Dispatch endpoint, and the response that was received.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.CallType","title":"CallType","text":"

Bases: Enum

Type of function call.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService","title":"DispatchService","text":"
DispatchService(\n    endpoint_client: EndpointClient,\n    api_key: Optional[str] = None,\n    retry_on_status: Optional[Set[Status]] = None,\n    collect_roundtrips: bool = False,\n)\n

Bases: DispatchServiceServicer

Test instance of Dispatch that provides the bare minimum functionality required to test functions locally.

Parameters:

Name Type Description Default endpoint_client EndpointClient

Client to use to interact with the local Dispatch endpoint (that provides the functions).

required api_key Optional[str]

Expected API key on requests to the service. If omitted, the value of the DISPATCH_API_KEY environment variable is used instead.

None retry_on_status Optional[Set[Status]]

Set of status codes to enable retries for.

None collect_roundtrips bool

Enable collection of request/response round-trips to the configured endpoint.

False"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.Dispatch","title":"Dispatch","text":"
Dispatch(request: DispatchRequest, context)\n

RPC handler for Dispatch requests. Requests are only queued for processing here.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.dispatch_calls","title":"dispatch_calls","text":"
dispatch_calls()\n

Synchronously dispatch pending function calls to the configured endpoint.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.start","title":"start","text":"
start()\n

Start starts a background thread to continuously dispatch calls to the configured endpoint.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.stop","title":"stop","text":"
stop()\n

Stop stops the background thread that's dispatching calls to the configured endpoint.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Dispatch Python SDK","text":"

This is the API reference for the Python SDK of Dispatch.

"},{"location":"reference/SUMMARY/","title":"SUMMARY","text":""},{"location":"reference/dispatch/","title":"Index","text":""},{"location":"reference/dispatch/#dispatch","title":"dispatch","text":"

The Dispatch SDK for Python.

"},{"location":"reference/dispatch/#dispatch.DispatchID","title":"DispatchID module-attribute","text":"
DispatchID: TypeAlias = str\n

Unique identifier in Dispatch.

It should be treated as an opaque value.

"},{"location":"reference/dispatch/#dispatch.Client","title":"Client","text":"
Client(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Client for the Dispatch API.

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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 the API key is missing.

"},{"location":"reference/dispatch/#dispatch.Client.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/#dispatch.Client.dispatch","title":"dispatch","text":"
dispatch(calls: Iterable[Call]) -> List[DispatchID]\n

Dispatch function calls.

Parameters:

Name Type Description Default calls Iterable[Call]

Calls to dispatch.

required

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order as the inputs.

"},{"location":"reference/dispatch/#dispatch.Registry","title":"Registry","text":"
Registry(\n    endpoint: Optional[str] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Registry of functions.

Parameters:

Name Type Description Default endpoint Optional[str]

URL of the endpoint that the function is accessible from. Uses the value of the DISPATCH_ENDPOINT_URL environment variable by default.

None api_key Optional[str]

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

None api_url Optional[str]

The URL of the Dispatch API to use when dispatching calls to functions. 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.

"},{"location":"reference/dispatch/#dispatch.Registry.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/#dispatch.Registry.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/#dispatch.Registry.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/#dispatch.Registry.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/#dispatch.Reset","title":"Reset","text":"
Reset(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n)\n

Bases: TailCall

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/#dispatch.Call","title":"Call dataclass","text":"
Call(\n    function: str,\n    input: Optional[Any] = None,\n    endpoint: Optional[str] = None,\n    correlation_id: Optional[int] = None,\n)\n

Instruction to call a function.

Though this class can be built manually, it is recommended to use the with_call method of a Function instead.

"},{"location":"reference/dispatch/#dispatch.Error","title":"Error dataclass","text":"
Error(\n    status: Status,\n    type: str,\n    message: str,\n    value: Optional[Exception] = None,\n    traceback: Optional[bytes] = None,\n)\n

Error when running a function.

This is not a Python exception, but potentially part of a CallResult or Output.

Parameters:

Name Type Description Default status Status

categorization of the error.

required type str

arbitrary string, used for humans.

required message str

arbitrary message.

required value Optional[Exception]

arbitrary exception from which the error is derived. Optional.

None

Raises:

Type Description ValueError

Neither type or message was provided or status is invalid.

"},{"location":"reference/dispatch/#dispatch.Error.from_exception","title":"from_exception classmethod","text":"
from_exception(\n    ex: Exception, status: Optional[Status] = None\n) -> Error\n

Create an Error from a Python exception, using its class qualified named as type.

The status tries to be inferred, but can be overridden. If it is not provided or cannot be inferred, it defaults to TEMPORARY_ERROR.

"},{"location":"reference/dispatch/#dispatch.Error.to_exception","title":"to_exception","text":"
to_exception() -> Exception\n

Returns an equivalent exception.

"},{"location":"reference/dispatch/#dispatch.Input","title":"Input","text":"
Input(req: RunRequest)\n

The input to a primitive function.

Functions always take a single argument of type Input. When the function is run for the first time, it receives the input. When the function is a coroutine that's resuming after a yield point, it receives the results of the yield directive. Use the is_first_call and is_resume properties to differentiate between the two cases.

This class is intended to be used as read-only.

"},{"location":"reference/dispatch/#dispatch.Input.input_arguments","title":"input_arguments","text":"
input_arguments() -> Tuple[Tuple[Any, ...], Dict[str, Any]]\n

Returns positional and keyword arguments carried by the input.

"},{"location":"reference/dispatch/#dispatch.Output","title":"Output dataclass","text":"
Output(proto: RunResponse)\n

The output of a primitive function.

This class is meant to be instantiated and returned by authors of functions to indicate the follow up action they need to take. Use the various class methods create an instance of this class. For example Output.value() or Output.poll().

"},{"location":"reference/dispatch/#dispatch.Output.value","title":"value classmethod","text":"
value(\n    value: Any, status: Optional[Status] = None\n) -> Output\n

Terminally exit the function with the provided return value.

"},{"location":"reference/dispatch/#dispatch.Output.error","title":"error classmethod","text":"
error(error: Error) -> Output\n

Terminally exit the function with the provided error.

"},{"location":"reference/dispatch/#dispatch.Output.tail_call","title":"tail_call classmethod","text":"
tail_call(\n    tail_call: Call, status: Status = Status.OK\n) -> Output\n

Terminally exit the function, and instruct the orchestrator to tail call the specified function.

"},{"location":"reference/dispatch/#dispatch.Output.exit","title":"exit classmethod","text":"
exit(\n    result: Optional[CallResult] = None,\n    tail_call: Optional[Call] = None,\n    status: Status = Status.OK,\n) -> Output\n

Terminally exit the function.

"},{"location":"reference/dispatch/#dispatch.Output.poll","title":"poll classmethod","text":"
poll(\n    coroutine_state: Optional[bytes] = None,\n    calls: Optional[List[Call]] = None,\n    min_results: int = 1,\n    max_results: int = 10,\n    max_wait_seconds: Optional[int] = None,\n) -> Output\n

Suspend the function with a set of Calls, instructing the orchestrator to resume the function with the provided state when call results are ready.

"},{"location":"reference/dispatch/#dispatch.Status","title":"Status","text":"

Bases: int, Enum

Enumeration of the possible values that can be used in the return status of functions.

"},{"location":"reference/dispatch/#dispatch.all","title":"all","text":"
all(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until all coroutines return or any coroutine raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.any","title":"any","text":"
any(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or all coroutines raises an error. If all coroutines fail with uncaught exceptions, the exception(s) will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.call","title":"call","text":"
call(call: Call) -> Any\n

Make an asynchronous function call and return its result. If the function call fails with an error, the error is raised.

"},{"location":"reference/dispatch/#dispatch.gather","title":"gather","text":"
gather(*awaitables: Awaitable[Any]) -> List[Any]\n

Alias for all.

"},{"location":"reference/dispatch/#dispatch.race","title":"race","text":"
race(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/#dispatch.run","title":"run","text":"
run(\n    init: Optional[Callable[P, None]] = None,\n    *args: args,\n    **kwargs: kwargs\n)\n

Run the default dispatch server. The default server uses a function registry where functions tagged by the @dispatch.function decorator are registered.

This function is intended to be used with the dispatch CLI tool, which automatically configures environment variables to connect the local server to the Dispatch bridge API.

Parameters:

Name Type Description Default init Optional[Callable[P, None]]

An initialization function called after binding the server address but before entering the event loop to handle requests.

None args args

Positional arguments to pass to the entrypoint.

() kwargs kwargs

Keyword arguments to pass to the entrypoint.

{}

Returns:

Type Description

The return value of the entrypoint function.

"},{"location":"reference/dispatch/#dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Create a new batch object.

"},{"location":"reference/dispatch/aiohttp/","title":" aiohttp","text":""},{"location":"reference/dispatch/aiohttp/#dispatch.aiohttp","title":"aiohttp","text":""},{"location":"reference/dispatch/aiohttp/#dispatch.aiohttp.Dispatch","title":"Dispatch","text":"
Dispatch(\n    registry: Registry,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n)\n

Bases: Application

A Dispatch instance servicing as a http server.

Parameters:

Name Type Description Default registry Registry

The registry of functions to be serviced.

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

The verification key to use for requests.

None"},{"location":"reference/dispatch/asyncio/","title":" asyncio","text":""},{"location":"reference/dispatch/asyncio/#dispatch.asyncio","title":"asyncio","text":""},{"location":"reference/dispatch/asyncio/#dispatch.asyncio.Runner","title":"Runner","text":"
Runner()\n

Runner is a class similar to asyncio.Runner but that we use for backward compatibility with Python 3.10 and earlier.

"},{"location":"reference/dispatch/coroutine/","title":" coroutine","text":""},{"location":"reference/dispatch/coroutine/#dispatch.coroutine","title":"coroutine","text":""},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.AnyException","title":"AnyException","text":"
AnyException(exceptions: List[Exception])\n

Bases: RuntimeError

Error indicating that all coroutines passed to any() failed with an exception.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.call","title":"call","text":"
call(call: Call) -> Any\n

Make an asynchronous function call and return its result. If the function call fails with an error, the error is raised.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.gather","title":"gather","text":"
gather(*awaitables: Awaitable[Any]) -> List[Any]\n

Alias for all.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.all","title":"all","text":"
all(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until all coroutines return or any coroutine raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.any","title":"any","text":"
any(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or all coroutines raises an error. If all coroutines fail with uncaught exceptions, the exception(s) will be re-raised here.

"},{"location":"reference/dispatch/coroutine/#dispatch.coroutine.race","title":"race","text":"
race(*awaitables: Awaitable[Any]) -> List[Any]\n

Concurrently run a set of coroutines, blocking until any coroutine returns or raises an error. If any coroutine fails with an uncaught exception, the exception will be re-raised here.

"},{"location":"reference/dispatch/error/","title":" error","text":""},{"location":"reference/dispatch/error/#dispatch.error","title":"error","text":""},{"location":"reference/dispatch/error/#dispatch.error.DispatchError","title":"DispatchError","text":"

Bases: Exception

Base class for Dispatch exceptions.

"},{"location":"reference/dispatch/error/#dispatch.error.TimeoutError","title":"TimeoutError","text":"

Bases: DispatchError, TimeoutError

Operation timed out.

"},{"location":"reference/dispatch/error/#dispatch.error.ThrottleError","title":"ThrottleError","text":"

Bases: DispatchError

Operation was throttled.

"},{"location":"reference/dispatch/error/#dispatch.error.InvalidArgumentError","title":"InvalidArgumentError","text":"

Bases: DispatchError, ValueError

Invalid argument was received.

"},{"location":"reference/dispatch/error/#dispatch.error.InvalidResponseError","title":"InvalidResponseError","text":"

Bases: DispatchError, ValueError

Invalid response was received.

"},{"location":"reference/dispatch/error/#dispatch.error.TemporaryError","title":"TemporaryError","text":"

Bases: DispatchError

Generic temporary error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.PermanentError","title":"PermanentError","text":"

Bases: DispatchError

Generic permanent error. Used in cases where a more specific error class is not available, but the operation that failed should not be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.IncompatibleStateError","title":"IncompatibleStateError","text":"

Bases: DispatchError

Coroutine state is incompatible with the current interpreter and application revision.

"},{"location":"reference/dispatch/error/#dispatch.error.DNSError","title":"DNSError","text":"

Bases: DispatchError, ConnectionError

Generic DNS error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.TCPError","title":"TCPError","text":"

Bases: DispatchError, ConnectionError

Generic TCP error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.HTTPError","title":"HTTPError","text":"

Bases: DispatchError, ConnectionError

Generic HTTP error. Used in cases where a more specific error class is not available, but the operation that failed should be attempted again.

"},{"location":"reference/dispatch/error/#dispatch.error.UnauthenticatedError","title":"UnauthenticatedError","text":"

Bases: DispatchError

The caller did not authenticate with the resource.

"},{"location":"reference/dispatch/error/#dispatch.error.PermissionDeniedError","title":"PermissionDeniedError","text":"

Bases: DispatchError, PermissionError

The caller does not have access to the resource.

"},{"location":"reference/dispatch/error/#dispatch.error.NotFoundError","title":"NotFoundError","text":"

Bases: DispatchError

Generic not found error. Used in cases where a more specific error class is not available, but the operation that failed should not be attempted again.

"},{"location":"reference/dispatch/fastapi/","title":" fastapi","text":""},{"location":"reference/dispatch/fastapi/#dispatch.fastapi","title":"fastapi","text":"

Integration of Dispatch functions with FastAPI.

Example:

import fastapi\nfrom dispatch.fastapi import Dispatch\n\napp = fastapi.FastAPI()\ndispatch = Dispatch(app, api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@app.get(\"/\")\ndef read_root():\n    my_function.dispatch()\n
"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch","title":"Dispatch","text":"
Dispatch(\n    app: FastAPI,\n    endpoint: Optional[str] = None,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

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 endpoint Optional[str]

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

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 api_key Optional[str]

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

None api_url Optional[str]

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.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/fastapi/#dispatch.fastapi.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/flask/","title":" flask","text":""},{"location":"reference/dispatch/flask/#dispatch.flask","title":"flask","text":"

Integration of Dispatch functions with Flask.

Example:

from flask import Flask\nfrom dispatch.flask import Dispatch\n\napp = Flask(__name__)\ndispatch = Dispatch(app, api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@app.get(\"/\")\ndef read_root():\n    my_function.dispatch()\n
"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch","title":"Dispatch","text":"
Dispatch(\n    app: Flask,\n    endpoint: Optional[str] = None,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

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 endpoint Optional[str]

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

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 api_key Optional[str]

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

None api_url Optional[str]

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.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/flask/#dispatch.flask.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/","title":" function","text":""},{"location":"reference/dispatch/function/#dispatch.function","title":"function","text":""},{"location":"reference/dispatch/function/#dispatch.function.PrimitiveFunctionType","title":"PrimitiveFunctionType module-attribute","text":"
PrimitiveFunctionType: TypeAlias = Callable[\n    [Input], Awaitable[Output]\n]\n

A primitive function is a function that accepts a dispatch.proto.Input and unconditionally returns a dispatch.proto.Output. It must not raise exceptions.

"},{"location":"reference/dispatch/function/#dispatch.function.Function","title":"Function","text":"
Function(\n    endpoint: str,\n    client: Client,\n    name: str,\n    primitive_func: PrimitiveFunctionType,\n)\n

Bases: PrimitiveFunction, Generic[P, T]

Callable wrapper around a function meant to be used throughout the Dispatch Python SDK.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.__call__","title":"__call__","text":"
__call__(\n    *args: args, **kwargs: kwargs\n) -> Coroutine[Any, Any, T]\n

Call the function asynchronously (through Dispatch), and return a coroutine that can be awaited to retrieve the call result.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.dispatch","title":"dispatch","text":"
dispatch(*args: args, **kwargs: kwargs) -> DispatchID\n

Dispatch an asynchronous call to the function without waiting for a result.

The Registry this function was registered with must be initialized with a Client / api_key for this call facility to be available.

Parameters:

Name Type Description Default *args args

Positional arguments for the function.

() **kwargs kwargs

Keyword arguments for the function.

{}

Returns:

Name Type Description DispatchID DispatchID

ID of the dispatched call.

Raises:

Type Description RuntimeError

if a Dispatch client has not been configured.

"},{"location":"reference/dispatch/function/#dispatch.function.Function.build_call","title":"build_call","text":"
build_call(\n    *args: args,\n    correlation_id: Optional[int] = None,\n    **kwargs: kwargs\n) -> Call\n

Create a Call for this function with the provided input. Useful to generate calls when using the Client.

Parameters:

Name Type Description Default *args args

Positional arguments for the function.

() correlation_id Optional[int]

optional arbitrary integer the caller can use to match this call to a call result.

None **kwargs kwargs

Keyword arguments for the function.

{}

Returns:

Name Type Description Call Call

can be passed to Client.dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Reset","title":"Reset","text":"
Reset(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n)\n

Bases: TailCall

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry","title":"Registry","text":"
Registry(\n    endpoint: Optional[str] = None,\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Registry of functions.

Parameters:

Name Type Description Default endpoint Optional[str]

URL of the endpoint that the function is accessible from. Uses the value of the DISPATCH_ENDPOINT_URL environment variable by default.

None api_key Optional[str]

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

None api_url Optional[str]

The URL of the Dispatch API to use when dispatching calls to functions. 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.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/function/#dispatch.function.Registry.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Client","title":"Client","text":"
Client(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Client for the Dispatch API.

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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 the API key is missing.

"},{"location":"reference/dispatch/function/#dispatch.function.Client.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Client.dispatch","title":"dispatch","text":"
dispatch(calls: Iterable[Call]) -> List[DispatchID]\n

Dispatch function calls.

Parameters:

Name Type Description Default calls Iterable[Call]

Calls to dispatch.

required

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order as the inputs.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch","title":"Batch","text":"
Batch(client: Client)\n

A batch of calls to dispatch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.add","title":"add","text":"
add(\n    func: Function[P, T], *args: args, **kwargs: kwargs\n) -> Batch\n

Add a call to the specified function to the batch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.add_call","title":"add_call","text":"
add_call(call: Call) -> Batch\n

Add a Call to the batch.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.dispatch","title":"dispatch","text":"
dispatch() -> List[DispatchID]\n

Dispatch dispatches the calls asynchronously.

The batch is reset when the calls are dispatched successfully.

Returns:

Type Description List[DispatchID]

Identifiers for the function calls, in the same order they

List[DispatchID]

were added.

"},{"location":"reference/dispatch/function/#dispatch.function.Batch.reset","title":"reset","text":"
reset()\n

Reset the batch.

"},{"location":"reference/dispatch/http/","title":" http","text":""},{"location":"reference/dispatch/http/#dispatch.http","title":"http","text":"

Integration of Dispatch functions with http.

"},{"location":"reference/dispatch/http/#dispatch.http.Dispatch","title":"Dispatch","text":"
Dispatch(\n    registry: Registry,\n    verification_key: Optional[\n        Union[Ed25519PublicKey, str, bytes]\n    ] = None,\n)\n

A Dispatch instance servicing as a http server.

Parameters:

Name Type Description Default registry Registry

The registry of functions to be serviced.

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

The verification key to use for requests.

None"},{"location":"reference/dispatch/id/","title":" id","text":""},{"location":"reference/dispatch/id/#dispatch.id","title":"id","text":""},{"location":"reference/dispatch/id/#dispatch.id.DispatchID","title":"DispatchID module-attribute","text":"
DispatchID: TypeAlias = str\n

Unique identifier in Dispatch.

It should be treated as an opaque value.

"},{"location":"reference/dispatch/proto/","title":" proto","text":""},{"location":"reference/dispatch/proto/#dispatch.proto","title":"proto","text":""},{"location":"reference/dispatch/proto/#dispatch.proto.TailCall","title":"TailCall","text":"
TailCall(\n    call: Call, status: Status = Status.TEMPORARY_ERROR\n)\n

Bases: Exception

The current coroutine is aborted and scheduling reset to be replaced with the call embedded in this exception.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Input","title":"Input","text":"
Input(req: RunRequest)\n

The input to a primitive function.

Functions always take a single argument of type Input. When the function is run for the first time, it receives the input. When the function is a coroutine that's resuming after a yield point, it receives the results of the yield directive. Use the is_first_call and is_resume properties to differentiate between the two cases.

This class is intended to be used as read-only.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Input.input_arguments","title":"input_arguments","text":"
input_arguments() -> Tuple[Tuple[Any, ...], Dict[str, Any]]\n

Returns positional and keyword arguments carried by the input.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Arguments","title":"Arguments dataclass","text":"
Arguments(args: Tuple[Any, ...], kwargs: Dict[str, Any])\n

A container for positional and keyword arguments.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output","title":"Output dataclass","text":"
Output(proto: RunResponse)\n

The output of a primitive function.

This class is meant to be instantiated and returned by authors of functions to indicate the follow up action they need to take. Use the various class methods create an instance of this class. For example Output.value() or Output.poll().

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.value","title":"value classmethod","text":"
value(\n    value: Any, status: Optional[Status] = None\n) -> Output\n

Terminally exit the function with the provided return value.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.error","title":"error classmethod","text":"
error(error: Error) -> Output\n

Terminally exit the function with the provided error.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.tail_call","title":"tail_call classmethod","text":"
tail_call(\n    tail_call: Call, status: Status = Status.OK\n) -> Output\n

Terminally exit the function, and instruct the orchestrator to tail call the specified function.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.exit","title":"exit classmethod","text":"
exit(\n    result: Optional[CallResult] = None,\n    tail_call: Optional[Call] = None,\n    status: Status = Status.OK,\n) -> Output\n

Terminally exit the function.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Output.poll","title":"poll classmethod","text":"
poll(\n    coroutine_state: Optional[bytes] = None,\n    calls: Optional[List[Call]] = None,\n    min_results: int = 1,\n    max_results: int = 10,\n    max_wait_seconds: Optional[int] = None,\n) -> Output\n

Suspend the function with a set of Calls, instructing the orchestrator to resume the function with the provided state when call results are ready.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Call","title":"Call dataclass","text":"
Call(\n    function: str,\n    input: Optional[Any] = None,\n    endpoint: Optional[str] = None,\n    correlation_id: Optional[int] = None,\n)\n

Instruction to call a function.

Though this class can be built manually, it is recommended to use the with_call method of a Function instead.

"},{"location":"reference/dispatch/proto/#dispatch.proto.CallResult","title":"CallResult dataclass","text":"
CallResult(\n    correlation_id: Optional[int] = None,\n    output: Optional[Any] = None,\n    error: Optional[Error] = None,\n    dispatch_id: DispatchID = \"\",\n)\n

Result of a Call.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error","title":"Error dataclass","text":"
Error(\n    status: Status,\n    type: str,\n    message: str,\n    value: Optional[Exception] = None,\n    traceback: Optional[bytes] = None,\n)\n

Error when running a function.

This is not a Python exception, but potentially part of a CallResult or Output.

Parameters:

Name Type Description Default status Status

categorization of the error.

required type str

arbitrary string, used for humans.

required message str

arbitrary message.

required value Optional[Exception]

arbitrary exception from which the error is derived. Optional.

None

Raises:

Type Description ValueError

Neither type or message was provided or status is invalid.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.from_exception","title":"from_exception classmethod","text":"
from_exception(\n    ex: Exception, status: Optional[Status] = None\n) -> Error\n

Create an Error from a Python exception, using its class qualified named as type.

The status tries to be inferred, but can be overridden. If it is not provided or cannot be inferred, it defaults to TEMPORARY_ERROR.

"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.to_exception","title":"to_exception","text":"
to_exception() -> Exception\n

Returns an equivalent exception.

"},{"location":"reference/dispatch/scheduler/","title":" scheduler","text":""},{"location":"reference/dispatch/scheduler/#dispatch.scheduler","title":"scheduler","text":""},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CoroutineResult","title":"CoroutineResult dataclass","text":"
CoroutineResult(\n    coroutine_id: CoroutineID,\n    value: Optional[Any] = None,\n    error: Optional[Exception] = None,\n    call: Optional[Call] = None,\n    status: Status = Status.OK,\n)\n

The result from running a coroutine to completion.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CallResult","title":"CallResult dataclass","text":"
CallResult(\n    call_id: CallID,\n    value: Optional[Any] = None,\n    error: Optional[Exception] = None,\n)\n

The result of an asynchronous function call.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.CallFuture","title":"CallFuture dataclass","text":"
CallFuture(\n    result: Optional[CallResult] = None,\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.call() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.AllFuture","title":"AllFuture dataclass","text":"
AllFuture(\n    order: List[CoroutineID] = list(),\n    waiting: Set[CoroutineID] = set(),\n    results: Dict[CoroutineID, CoroutineResult] = dict(),\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.all() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.AnyFuture","title":"AnyFuture dataclass","text":"
AnyFuture(\n    order: List[CoroutineID] = list(),\n    waiting: Set[CoroutineID] = set(),\n    first_result: Optional[CoroutineResult] = None,\n    errors: Dict[CoroutineID, Exception] = dict(),\n    generic_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.any() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.RaceFuture","title":"RaceFuture dataclass","text":"
RaceFuture(\n    waiting: Set[CoroutineID] = set(),\n    first_result: Optional[CoroutineResult] = None,\n    first_error: Optional[Exception] = None,\n)\n

A future result of a dispatch.coroutine.race() operation.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.Coroutine","title":"Coroutine dataclass","text":"
Coroutine(\n    id: CoroutineID,\n    parent_id: Optional[CoroutineID],\n    coroutine: Union[DurableCoroutine, DurableGenerator],\n    result: Optional[Future] = None,\n)\n

An in-flight coroutine.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.State","title":"State dataclass","text":"
State(\n    version: str,\n    suspended: Dict[CoroutineID, Coroutine],\n    ready: List[Coroutine],\n    next_coroutine_id: int,\n    next_call_id: int,\n    prev_callers: List[Coroutine],\n    outstanding_calls: int,\n)\n

State of the scheduler and the coroutines it's managing.

"},{"location":"reference/dispatch/scheduler/#dispatch.scheduler.OneShotScheduler","title":"OneShotScheduler","text":"
OneShotScheduler(\n    entry_point: Callable,\n    version: str = sys.version,\n    poll_min_results: int = 1,\n    poll_max_results: int = 10,\n    poll_max_wait_seconds: Optional[int] = None,\n)\n

Scheduler for local coroutines.

It's a one-shot scheduler because it only runs one round of scheduling. When all local coroutines are suspended, the scheduler yields to Dispatch to take over scheduling asynchronous calls.

Parameters:

Name Type Description Default entry_point Callable

Entry point for the main coroutine.

required version str

Version string to attach to scheduler/coroutine state. If the scheduler sees a version mismatch, it will respond to Dispatch with an INCOMPATIBLE_STATE status code.

version poll_min_results int

Minimum number of call results to wait for before coroutine execution should continue. Dispatch waits until this many results are available, or the poll_max_wait_seconds timeout is reached, whichever comes first.

1 poll_max_results int

Maximum number of calls to receive from Dispatch per request.

10 poll_max_wait_seconds Optional[int]

Maximum amount of time to suspend coroutines while waiting for call results. Optional.

None"},{"location":"reference/dispatch/status/","title":" status","text":""},{"location":"reference/dispatch/status/#dispatch.status","title":"status","text":""},{"location":"reference/dispatch/status/#dispatch.status.Status","title":"Status","text":"

Bases: int, Enum

Enumeration of the possible values that can be used in the return status of functions.

"},{"location":"reference/dispatch/status/#dispatch.status.status_for_error","title":"status_for_error","text":"
status_for_error(error: BaseException) -> Status\n

Returns a Status that corresponds to the specified error.

"},{"location":"reference/dispatch/status/#dispatch.status.status_for_output","title":"status_for_output","text":"
status_for_output(output: Any) -> Status\n

Returns a Status that corresponds to the specified output value.

"},{"location":"reference/dispatch/status/#dispatch.status.register_error_type","title":"register_error_type","text":"
register_error_type(\n    error_type: Type[Exception],\n    status_or_handler: Union[\n        Status, Callable[[Exception], Status]\n    ],\n)\n

Register an error type to Status mapping.

The caller can either register a base exception and a handler, which derives a Status from errors of this type. Or, if there's only one exception to Status mapping to register, the caller can simply pass the exception class and the associated Status.

"},{"location":"reference/dispatch/status/#dispatch.status.register_output_type","title":"register_output_type","text":"
register_output_type(\n    output_type: Type[Any],\n    status_or_handler: Union[\n        Status, Callable[[Any], Status]\n    ],\n)\n

Register an output type to Status mapping.

The caller can either register a base class and a handler, which derives a Status from other classes of this type. Or, if there's only one output class to Status mapping to register, the caller can simply pass the class and the associated Status.

"},{"location":"reference/dispatch/experimental/","title":"Index","text":""},{"location":"reference/dispatch/experimental/#dispatch.experimental","title":"experimental","text":""},{"location":"reference/dispatch/experimental/lambda_handler/","title":" lambda_handler","text":""},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler","title":"lambda_handler","text":"

Integration of Dispatch programmable endpoints for FastAPI.

Example:

from dispatch.experimental.lambda_handler import Dispatch\n\ndispatch = Dispatch(api_key=\"test-key\")\n\n@dispatch.function\ndef my_function():\n    return \"Hello World!\"\n\n@dispatch.function\ndef entrypoint():\n    my_function()\n\ndef handler(event, context):\n    dispatch.handle(event, context, entrypoint=\"entrypoint\")\n
"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch","title":"Dispatch","text":"
Dispatch(\n    api_key: Optional[str] = None,\n    api_url: Optional[str] = None,\n)\n

Bases: Registry

Parameters:

Name Type Description Default api_key Optional[str]

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

None api_url Optional[str]

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"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.function","title":"function","text":"
function(func)\n

Decorator that registers functions.

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.primitive_function","title":"primitive_function","text":"
primitive_function(\n    primitive_func: PrimitiveFunctionType,\n) -> PrimitiveFunction\n

Decorator that registers primitive functions.

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.set_client","title":"set_client","text":"
set_client(client: Client)\n

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

"},{"location":"reference/dispatch/experimental/lambda_handler/#dispatch.experimental.lambda_handler.Dispatch.batch","title":"batch","text":"
batch() -> Batch\n

Returns a Batch instance that can be used to build a set of calls to dispatch.

"},{"location":"reference/dispatch/experimental/durable/","title":"Index","text":""},{"location":"reference/dispatch/experimental/durable/#dispatch.experimental.durable","title":"durable","text":"

A decorator that makes generators and coroutines serializable.

This module defines a @durable decorator that can be applied to generator functions and async functions. The generator and coroutine instances they create can be pickled.

Example usage:

import pickle\nfrom dispatch.experimental.durable import durable\n\n@durable\ndef my_generator():\n    for i in range(3):\n        yield i\n\n# Run the generator to its first yield point:\ng = my_generator()\nprint(next(g))  # 0\n\n# Make a copy, and consume the remaining items:\nb = pickle.dumps(g)\ng2 = pickle.loads(b)\nprint(next(g2))  # 1\nprint(next(g2))  # 2\n\n# The original is not affected:\nprint(next(g))  # 1\nprint(next(g))  # 2\n
"},{"location":"reference/dispatch/experimental/durable/#dispatch.experimental.durable.durable","title":"durable","text":"
durable(fn: Callable) -> Callable\n

Returns a \"durable\" function that creates serializable generators or coroutines.

"},{"location":"reference/dispatch/experimental/durable/function/","title":" function","text":""},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function","title":"function","text":""},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableFunction","title":"DurableFunction","text":"
DurableFunction(fn: FunctionType)\n

A wrapper for generator functions and async functions that make their generator and coroutine instances serializable.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.Serializable","title":"Serializable","text":"
Serializable(\n    g: Union[GeneratorType, CoroutineType],\n    registered_fn: RegisteredFunction,\n    wrapped_coroutine: Union[DurableCoroutine, None],\n    *args: Any,\n    **kwargs: Any\n)\n

A wrapper for a generator or coroutine that makes it serializable.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableCoroutine","title":"DurableCoroutine","text":"
DurableCoroutine(\n    coroutine: CoroutineType,\n    registered_fn: RegisteredFunction,\n    *args: Any,\n    **kwargs: Any\n)\n

Bases: Serializable, Coroutine[_YieldT, _SendT, _ReturnT]

A wrapper for a coroutine that makes it serializable (can be pickled). Instances behave like the coroutines they wrap.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.DurableGenerator","title":"DurableGenerator","text":"
DurableGenerator(\n    generator: GeneratorType,\n    registered_fn: RegisteredFunction,\n    coroutine: Optional[DurableCoroutine],\n    *args: Any,\n    **kwargs: Any\n)\n

Bases: Serializable, Generator[_YieldT, _SendT, _ReturnT]

A wrapper for a generator that makes it serializable (can be pickled). Instances behave like the generators they wrap.

"},{"location":"reference/dispatch/experimental/durable/function/#dispatch.experimental.durable.function.durable","title":"durable","text":"
durable(fn: Callable) -> Callable\n

Returns a \"durable\" function that creates serializable generators or coroutines.

"},{"location":"reference/dispatch/experimental/durable/registry/","title":" registry","text":""},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry","title":"registry","text":""},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.RegisteredFunction","title":"RegisteredFunction dataclass","text":"
RegisteredFunction(\n    fn: FunctionType,\n    key: str,\n    filename: str,\n    lineno: int,\n    hash: str,\n)\n

A function that can be referenced in durable state.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.register_function","title":"register_function","text":"
register_function(fn: FunctionType) -> RegisteredFunction\n

Register a function in the in-memory function registry.

When serializing a registered function, a reference to the function is stored along with details about its location and contents. When deserializing the function, the registry is consulted in order to find the function associated with the reference (and in order to check whether the function is the same).

Parameters:

Name Type Description Default fn FunctionType

The function to register.

required

Returns:

Name Type Description str RegisteredFunction

Unique identifier for the function.

Raises:

Type Description ValueError

The function conflicts with another registered function.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.lookup_function","title":"lookup_function","text":"
lookup_function(key: str) -> RegisteredFunction\n

Lookup a registered function by key.

Parameters:

Name Type Description Default key str

Unique identifier for the function.

required

Returns:

Name Type Description RegisteredFunction RegisteredFunction

the function that was registered with the specified key.

Raises:

Type Description KeyError

A function has not been registered with this key.

"},{"location":"reference/dispatch/experimental/durable/registry/#dispatch.experimental.durable.registry.clear_functions","title":"clear_functions","text":"
clear_functions()\n

Clear functions clears the registry.

"},{"location":"reference/dispatch/integrations/","title":"Index","text":""},{"location":"reference/dispatch/integrations/#dispatch.integrations","title":"integrations","text":""},{"location":"reference/dispatch/integrations/http/","title":" http","text":""},{"location":"reference/dispatch/integrations/http/#dispatch.integrations.http","title":"http","text":""},{"location":"reference/dispatch/integrations/http/#dispatch.integrations.http.http_response_code_status","title":"http_response_code_status","text":"
http_response_code_status(code: int) -> Status\n

Returns a Status that's broadly equivalent to an HTTP response status code.

"},{"location":"reference/dispatch/integrations/httpx/","title":" httpx","text":""},{"location":"reference/dispatch/integrations/httpx/#dispatch.integrations.httpx","title":"httpx","text":""},{"location":"reference/dispatch/integrations/openai/","title":" openai","text":""},{"location":"reference/dispatch/integrations/openai/#dispatch.integrations.openai","title":"openai","text":""},{"location":"reference/dispatch/integrations/requests/","title":" requests","text":""},{"location":"reference/dispatch/integrations/requests/#dispatch.integrations.requests","title":"requests","text":""},{"location":"reference/dispatch/integrations/slack/","title":" slack","text":""},{"location":"reference/dispatch/integrations/slack/#dispatch.integrations.slack","title":"slack","text":""},{"location":"reference/dispatch/signature/","title":"Index","text":""},{"location":"reference/dispatch/signature/#dispatch.signature","title":"signature","text":""},{"location":"reference/dispatch/signature/#dispatch.signature.sign_request","title":"sign_request","text":"
sign_request(\n    request: Request,\n    key: Ed25519PrivateKey,\n    created: datetime,\n)\n

Sign a request using HTTP Message Signatures.

The function adds three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The signature covers the request method, the URL host and path, the Content-Type header, and the request body. At this time, an ED25519 signature is generated with a hard-coded key ID of \"default\".

Parameters:

Name Type Description Default request Request

The request to sign.

required key Ed25519PrivateKey

The Ed25519 private key to use to generate the signature.

required created datetime

The times at which the signature is created.

required"},{"location":"reference/dispatch/signature/#dispatch.signature.verify_request","title":"verify_request","text":"
verify_request(\n    request: Request,\n    key: Ed25519PublicKey,\n    max_age: timedelta,\n)\n

Verify a request containing an HTTP Message Signature.

The function checks three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The function checks signatures that cover at least the request method, the URL host and path, the Content-Type header, and the request body (via the Content-Digest header). At this time, signatures must use a hard-coded key ID of \"default\".

Parameters:

Name Type Description Default request Request

The request to verify.

required key Ed25519PublicKey

The Ed25519 public key to use to verify the signature.

required max_age timedelta

The maximum age of the signature.

required"},{"location":"reference/dispatch/signature/digest/","title":" digest","text":""},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest","title":"digest","text":""},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest.generate_content_digest","title":"generate_content_digest","text":"
generate_content_digest(body: Union[str, bytes]) -> str\n

Returns a SHA-512 Content-Digest header, according to https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers-13

"},{"location":"reference/dispatch/signature/digest/#dispatch.signature.digest.verify_content_digest","title":"verify_content_digest","text":"
verify_content_digest(\n    digest_header: Union[str, bytes],\n    body: Union[str, bytes],\n)\n

Verify a SHA-256 or SHA-512 Content-Digest header matches a request body.

"},{"location":"reference/dispatch/signature/key/","title":" key","text":""},{"location":"reference/dispatch/signature/key/#dispatch.signature.key","title":"key","text":""},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.KeyResolver","title":"KeyResolver dataclass","text":"
KeyResolver(\n    key_id: str,\n    public_key: Optional[Ed25519PublicKey] = None,\n    private_key: Optional[Ed25519PrivateKey] = None,\n)\n

Bases: HTTPSignatureKeyResolver

KeyResolver provides public and private keys.

At this time, multiple keys and/or key types are not supported. Keys must be Ed25519 keys and have an ID of DEFAULT_KEY_ID.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.public_key_from_pem","title":"public_key_from_pem","text":"
public_key_from_pem(\n    pem: Union[str, bytes]\n) -> Ed25519PublicKey\n

Returns an Ed25519 public key given a PEM representation.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.public_key_from_bytes","title":"public_key_from_bytes","text":"
public_key_from_bytes(key: bytes) -> Ed25519PublicKey\n

Returns an Ed25519 public key from 32 raw bytes.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.private_key_from_pem","title":"private_key_from_pem","text":"
private_key_from_pem(\n    pem: Union[str, bytes], password: Optional[bytes] = None\n) -> Ed25519PrivateKey\n

Returns an Ed25519 private key given a PEM representation and optional password.

"},{"location":"reference/dispatch/signature/key/#dispatch.signature.key.private_key_from_bytes","title":"private_key_from_bytes","text":"
private_key_from_bytes(key: bytes) -> Ed25519PrivateKey\n

Returns an Ed25519 private key from 32 raw bytes.

"},{"location":"reference/dispatch/signature/request/","title":" request","text":""},{"location":"reference/dispatch/signature/request/#dispatch.signature.request","title":"request","text":""},{"location":"reference/dispatch/signature/request/#dispatch.signature.request.Request","title":"Request dataclass","text":"
Request(\n    method: str,\n    url: str,\n    headers: CaseInsensitiveDict,\n    body: Union[str, bytes],\n)\n

A framework-agnostic representation of an HTTP request.

"},{"location":"reference/dispatch/test/","title":"Index","text":""},{"location":"reference/dispatch/test/#dispatch.test","title":"test","text":""},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient","title":"EndpointClient","text":"
EndpointClient(\n    http_client: HttpClient,\n    signing_key: Optional[Ed25519PrivateKey] = None,\n)\n

Test client for a Dispatch programmable endpoint.

Note that this is different from dispatch.Client, which is a client for the Dispatch API. The EndpointClient is a client similar to the one that Dispatch itself would use to interact with an endpoint that provides functions.

Parameters:

Name Type Description Default http_client HttpClient

Client to use to make HTTP requests.

required signing_key Optional[Ed25519PrivateKey]

Optional Ed25519 private key to use to sign requests.

None"},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient.run","title":"run","text":"
run(request: RunRequest) -> RunResponse\n

Send a run request to an endpoint and return its response.

Parameters:

Name Type Description Default request RunRequest

A FunctionService Run request.

required

Returns:

Name Type Description RunResponse RunResponse

the response from the endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer","title":"DispatchServer","text":"
DispatchServer(\n    service: DispatchServiceServicer,\n    hostname: str = \"127.0.0.1\",\n    port: int = 0,\n)\n

Test server for a Dispatch service. This is useful for testing a mock version of Dispatch locally (e.g. see dispatch.test.DispatchService).

Parameters:

Name Type Description Default service DispatchServiceServicer

Dispatch service to serve.

required hostname str

Hostname to bind to.

'127.0.0.1' port int

Port to bind to, or 0 to bind to any available port.

0"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.url","title":"url property","text":"
url\n

Returns the URL of the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.start","title":"start","text":"
start()\n

Start the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.wait","title":"wait","text":"
wait()\n

Block until the server terminates.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchServer.stop","title":"stop","text":"
stop()\n

Stop the server.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService","title":"DispatchService","text":"
DispatchService(\n    endpoint_client: EndpointClient,\n    api_key: Optional[str] = None,\n    retry_on_status: Optional[Set[Status]] = None,\n    collect_roundtrips: bool = False,\n)\n

Bases: DispatchServiceServicer

Test instance of Dispatch that provides the bare minimum functionality required to test functions locally.

Parameters:

Name Type Description Default endpoint_client EndpointClient

Client to use to interact with the local Dispatch endpoint (that provides the functions).

required api_key Optional[str]

Expected API key on requests to the service. If omitted, the value of the DISPATCH_API_KEY environment variable is used instead.

None retry_on_status Optional[Set[Status]]

Set of status codes to enable retries for.

None collect_roundtrips bool

Enable collection of request/response round-trips to the configured endpoint.

False"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.Dispatch","title":"Dispatch","text":"
Dispatch(request: DispatchRequest, context)\n

RPC handler for Dispatch requests. Requests are only queued for processing here.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.dispatch_calls","title":"dispatch_calls","text":"
dispatch_calls()\n

Synchronously dispatch pending function calls to the configured endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.start","title":"start","text":"
start()\n

Start starts a background thread to continuously dispatch calls to the configured endpoint.

"},{"location":"reference/dispatch/test/#dispatch.test.DispatchService.stop","title":"stop","text":"
stop()\n

Stop stops the background thread that's dispatching calls to the configured endpoint.

"},{"location":"reference/dispatch/test/client/","title":" client","text":""},{"location":"reference/dispatch/test/client/#dispatch.test.client","title":"client","text":""},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient","title":"EndpointClient","text":"
EndpointClient(\n    http_client: HttpClient,\n    signing_key: Optional[Ed25519PrivateKey] = None,\n)\n

Test client for a Dispatch programmable endpoint.

Note that this is different from dispatch.Client, which is a client for the Dispatch API. The EndpointClient is a client similar to the one that Dispatch itself would use to interact with an endpoint that provides functions.

Parameters:

Name Type Description Default http_client HttpClient

Client to use to make HTTP requests.

required signing_key Optional[Ed25519PrivateKey]

Optional Ed25519 private key to use to sign requests.

None"},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient.run","title":"run","text":"
run(request: RunRequest) -> RunResponse\n

Send a run request to an endpoint and return its response.

Parameters:

Name Type Description Default request RunRequest

A FunctionService Run request.

required

Returns:

Name Type Description RunResponse RunResponse

the response from the endpoint.

"},{"location":"reference/dispatch/test/fastapi/","title":" fastapi","text":""},{"location":"reference/dispatch/test/fastapi/#dispatch.test.fastapi","title":"fastapi","text":""},{"location":"reference/dispatch/test/fastapi/#dispatch.test.fastapi.http_client","title":"http_client","text":"
http_client(app: FastAPI) -> HttpClient\n

Build a client for a FastAPI app.

"},{"location":"reference/dispatch/test/flask/","title":" flask","text":""},{"location":"reference/dispatch/test/flask/#dispatch.test.flask","title":"flask","text":""},{"location":"reference/dispatch/test/flask/#dispatch.test.flask.http_client","title":"http_client","text":"
http_client(app: Flask) -> HttpClient\n

Build a client for a Flask app.

"},{"location":"reference/dispatch/test/http/","title":" http","text":""},{"location":"reference/dispatch/test/http/#dispatch.test.http","title":"http","text":""},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpResponse","title":"HttpResponse dataclass","text":"
HttpResponse(status_code: int, body: bytes)\n

Bases: Protocol

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpResponse.raise_for_status","title":"raise_for_status","text":"
raise_for_status()\n

Raise an exception on non-2xx responses.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient","title":"HttpClient","text":"

Bases: Protocol

Protocol for HTTP clients.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.get","title":"get","text":"
get(\n    url: str, headers: Mapping[str, str] = {}\n) -> HttpResponse\n

Make a GET request.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.post","title":"post","text":"
post(\n    url: str, body: bytes, headers: Mapping[str, str] = {}\n) -> HttpResponse\n

Make a POST request.

"},{"location":"reference/dispatch/test/http/#dispatch.test.http.HttpClient.url_for","title":"url_for","text":"
url_for(path: str) -> str\n

Get the fully-qualified URL for a path.

"},{"location":"reference/dispatch/test/httpx/","title":" httpx","text":""},{"location":"reference/dispatch/test/httpx/#dispatch.test.httpx","title":"httpx","text":""},{"location":"reference/dispatch/test/server/","title":" server","text":""},{"location":"reference/dispatch/test/server/#dispatch.test.server","title":"server","text":""},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer","title":"DispatchServer","text":"
DispatchServer(\n    service: DispatchServiceServicer,\n    hostname: str = \"127.0.0.1\",\n    port: int = 0,\n)\n

Test server for a Dispatch service. This is useful for testing a mock version of Dispatch locally (e.g. see dispatch.test.DispatchService).

Parameters:

Name Type Description Default service DispatchServiceServicer

Dispatch service to serve.

required hostname str

Hostname to bind to.

'127.0.0.1' port int

Port to bind to, or 0 to bind to any available port.

0"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.url","title":"url property","text":"
url\n

Returns the URL of the server.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.start","title":"start","text":"
start()\n

Start the server.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.wait","title":"wait","text":"
wait()\n

Block until the server terminates.

"},{"location":"reference/dispatch/test/server/#dispatch.test.server.DispatchServer.stop","title":"stop","text":"
stop()\n

Stop the server.

"},{"location":"reference/dispatch/test/service/","title":" service","text":""},{"location":"reference/dispatch/test/service/#dispatch.test.service","title":"service","text":""},{"location":"reference/dispatch/test/service/#dispatch.test.service.RoundTrip","title":"RoundTrip module-attribute","text":"
RoundTrip: TypeAlias = Tuple[RunRequest, RunResponse]\n

A request to a Dispatch endpoint, and the response that was received.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.CallType","title":"CallType","text":"

Bases: Enum

Type of function call.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService","title":"DispatchService","text":"
DispatchService(\n    endpoint_client: EndpointClient,\n    api_key: Optional[str] = None,\n    retry_on_status: Optional[Set[Status]] = None,\n    collect_roundtrips: bool = False,\n)\n

Bases: DispatchServiceServicer

Test instance of Dispatch that provides the bare minimum functionality required to test functions locally.

Parameters:

Name Type Description Default endpoint_client EndpointClient

Client to use to interact with the local Dispatch endpoint (that provides the functions).

required api_key Optional[str]

Expected API key on requests to the service. If omitted, the value of the DISPATCH_API_KEY environment variable is used instead.

None retry_on_status Optional[Set[Status]]

Set of status codes to enable retries for.

None collect_roundtrips bool

Enable collection of request/response round-trips to the configured endpoint.

False"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.Dispatch","title":"Dispatch","text":"
Dispatch(request: DispatchRequest, context)\n

RPC handler for Dispatch requests. Requests are only queued for processing here.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.dispatch_calls","title":"dispatch_calls","text":"
dispatch_calls()\n

Synchronously dispatch pending function calls to the configured endpoint.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.start","title":"start","text":"
start()\n

Start starts a background thread to continuously dispatch calls to the configured endpoint.

"},{"location":"reference/dispatch/test/service/#dispatch.test.service.DispatchService.stop","title":"stop","text":"
stop()\n

Stop stops the background thread that's dispatching calls to the configured endpoint.

"}]} \ No newline at end of file diff --git a/main/sitemap.xml.gz b/main/sitemap.xml.gz index 13ef2ff0f032b27cd835fd9a8036a6ac39eaee50..7425bb9a71b1f38410398e1cf5e256f551061246 100644 GIT binary patch delta 12 Tcmb=gXOr*d;E-E3k*yK{7VZO+ delta 12 Tcmb=gXOr*d;MlozB3mT@8Sw-y