diff --git a/main/objects.inv b/main/objects.inv index 7db2e72..b9c94fa 100644 Binary files a/main/objects.inv and b/main/objects.inv differ diff --git a/main/reference/dispatch/error/index.html b/main/reference/dispatch/error/index.html index f41c2bc..e0fe11d 100644 --- a/main/reference/dispatch/error/index.html +++ b/main/reference/dispatch/error/index.html @@ -470,6 +470,69 @@
DispatchError
+
+
+
+
TimeoutError
+
+
+
+
ThrottleError
+
+
+
+
InvalidArgumentError
+
+
+
+
InvalidResponseError
+
+
+
+
TemporaryError
+
+
+
+
PermanentError
+
+
+
+
DNSError
+
+
+
+
TCPError
+
+
+
+
HTTPError
+
+
+
+
UnauthenticatedError
+
+
+
+
PermissionDeniedError
+
+
+
+
NotFoundError
+
+
+
DispatchError
+
+
+
+
TimeoutError
+
+
+
+
ThrottleError
+
+
+
+
InvalidArgumentError
+
+
+
+
InvalidResponseError
+
+
+
+
TemporaryError
+
+
+
+
PermanentError
+
+
+
+
DNSError
+
+
+
+
TCPError
+
+
+
+
HTTPError
+
+
+
+
UnauthenticatedError
+
+
+
+
PermissionDeniedError
+
+
+
+
NotFoundError
+
+
+
IncompatibleStateError
+
DispatchError
-¤Exception
- Coroutine state is incompatible with the current interpreter -and application revision.
+Base class for Dispatch exceptions.
+ + + + +
TimeoutError
+
+
+¤
+ Bases: DispatchError
, TimeoutError
Operation timed out.
+ + + + +
ThrottleError
+
+
+¤
InvalidArgumentError
+
+
+¤
+ Bases: DispatchError
, ValueError
Invalid argument was received.
+ + + + +
InvalidResponseError
+
+
+¤
+ Bases: DispatchError
, ValueError
Invalid response was received.
+ + + + +
TemporaryError
+
+
+¤
+ 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.
+ + + + +
PermanentError
+
+
+¤
+ 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.
+ + + + +
IncompatibleStateError
+
+
+¤
+ Bases: DispatchError
Coroutine state is incompatible with the current interpreter +and application revision.
+ + + + +
DNSError
+
+
+¤
+ 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.
+ + + + +
TCPError
+
+
+¤
+ 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.
+ + + + +
HTTPError
+
+
+¤
+ 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.
+ + + + +
UnauthenticatedError
+
+
+¤
+ Bases: DispatchError
The caller did not authenticate with the resource.
+ + + + +
PermissionDeniedError
+
+
+¤
+ Bases: DispatchError
, PermissionError
The caller does not have access to the resource.
+ + + + +
NotFoundError
+
+
+¤
+ 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.
+ + + + +This is the API reference for the Python SDK of Dispatch.
The Dispatch SDK for Python.
"},{"location":"reference/dispatch/#dispatch.DispatchID","title":"DispatchIDmodule-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 Defaultapi_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 DescriptionValueError
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 Defaultcalls
Iterable[Call]
Calls to dispatch.
requiredReturns:
Type DescriptionList[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 Defaultendpoint
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 DescriptionValueError
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":"Calldataclass
","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":"Errordataclass
","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 Defaultstatus
Status
categorization of the error.
requiredtype
str
arbitrary string, used for humans.
requiredmessage
str
arbitrary message.
requiredvalue
Optional[Exception]
arbitrary exception from which the error is derived. Optional.
None
Raises:
Type DescriptionValueError
Neither type or message was provided or status is invalid.
"},{"location":"reference/dispatch/#dispatch.Error.from_exception","title":"from_exceptionclassmethod
","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":"Outputdataclass
","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":"valueclassmethod
","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":"errorclassmethod
","text":"error(error: Error) -> Output\n
Terminally exit the function with the provided error.
"},{"location":"reference/dispatch/#dispatch.Output.tail_call","title":"tail_callclassmethod
","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":"exitclassmethod
","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":"pollclassmethod
","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 Defaultinit
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 DescriptionThe return value of the entrypoint function.
"},{"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.IncompatibleStateError","title":"IncompatibleStateError","text":" Bases: Exception
Coroutine state is incompatible with the current interpreter and application revision.
"},{"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 Defaultapp
FastAPI
The FastAPI app to configure.
requiredendpoint
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 DescriptionValueError
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/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[[Input], Output]\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 DescriptionDispatchID
DispatchID
ID of the dispatched call.
Raises:
Type DescriptionRuntimeError
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 DescriptionCall
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 Defaultendpoint
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 DescriptionValueError
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 Defaultapi_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 DescriptionValueError
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 Defaultcalls
Iterable[Call]
Calls to dispatch.
requiredReturns:
Type DescriptionList[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 DescriptionList[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 to be serviced by a http server. The Dispatch class acts as a factory for DispatchHandler objects, by capturing the variables that would be shared between all DispatchHandler instances it created.
Parameters:
Name Type Description Defaultregistry
Registry
The registry of functions to be serviced.
required"},{"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":"Argumentsdataclass
","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":"Outputdataclass
","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":"valueclassmethod
","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":"errorclassmethod
","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_callclassmethod
","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":"exitclassmethod
","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":"pollclassmethod
","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":"Calldataclass
","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":"CallResultdataclass
","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":"Errordataclass
","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 Defaultstatus
Status
categorization of the error.
requiredtype
str
arbitrary string, used for humans.
requiredmessage
str
arbitrary message.
requiredvalue
Optional[Exception]
arbitrary exception from which the error is derived. Optional.
None
Raises:
Type DescriptionValueError
Neither type or message was provided or status is invalid.
"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.from_exception","title":"from_exceptionclassmethod
","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":"CallResultdataclass
","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":"CallFuturedataclass
","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":"AllFuturedataclass
","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":"AnyFuturedataclass
","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":"RaceFuturedataclass
","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":"Coroutinedataclass
","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":"Statedataclass
","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 Defaultentry_point
Callable
Entry point for the main coroutine.
requiredversion
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 handler: Callable[[Exception], Status],\n)\n
Register an error type, and a handler which derives a Status from errors of this type.
"},{"location":"reference/dispatch/status/#dispatch.status.register_output_type","title":"register_output_type","text":"register_output_type(\n output_type: Type[Any], handler: Callable[[Any], Status]\n)\n
Register an output type, and a handler which derives a Status from outputs of this type.
"},{"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 Defaultapi_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 Defaultfn
FunctionType
The function to register.
requiredReturns:
Name Type Descriptionstr
RegisteredFunction
Unique identifier for the function.
Raises:
Type DescriptionValueError
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 Defaultkey
str
Unique identifier for the function.
requiredReturns:
Name Type DescriptionRegisteredFunction
RegisteredFunction
the function that was registered with the specified key.
Raises:
Type DescriptionKeyError
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 Defaultrequest
Request
The request to sign.
requiredkey
Ed25519PrivateKey
The Ed25519 private key to use to generate the signature.
requiredcreated
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 Defaultrequest
Request
The request to verify.
requiredkey
Ed25519PublicKey
The Ed25519 public key to use to verify the signature.
requiredmax_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: Client,\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 Defaulthttp_client
Client
Client to use to make HTTP requests.
requiredsigning_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 Defaultrequest
RunRequest
A FunctionService Run request.
requiredReturns:
Name Type DescriptionRunResponse
RunResponse
the response from the endpoint.
"},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient.from_url","title":"from_urlclassmethod
","text":"from_url(\n url: str,\n signing_key: Optional[Ed25519PrivateKey] = None,\n)\n
Returns an EndpointClient for a Dispatch endpoint URL.
"},{"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 Defaultservice
DispatchServiceServicer
Dispatch service to serve.
requiredhostname
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 Defaultendpoint_client
EndpointClient
Client to use to interact with the local Dispatch endpoint (that provides the functions).
requiredapi_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: Client,\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 Defaulthttp_client
Client
Client to use to make HTTP requests.
requiredsigning_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 Defaultrequest
RunRequest
A FunctionService Run request.
requiredReturns:
Name Type DescriptionRunResponse
RunResponse
the response from the endpoint.
"},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient.from_url","title":"from_urlclassmethod
","text":"from_url(\n url: str,\n signing_key: Optional[Ed25519PrivateKey] = None,\n)\n
Returns an EndpointClient for a Dispatch endpoint URL.
"},{"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 Defaultservice
DispatchServiceServicer
Dispatch service to serve.
requiredhostname
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 Defaultendpoint_client
EndpointClient
Client to use to interact with the local Dispatch endpoint (that provides the functions).
requiredapi_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.
The Dispatch SDK for Python.
"},{"location":"reference/dispatch/#dispatch.DispatchID","title":"DispatchIDmodule-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 Defaultapi_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 DescriptionValueError
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 Defaultcalls
Iterable[Call]
Calls to dispatch.
requiredReturns:
Type DescriptionList[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 Defaultendpoint
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 DescriptionValueError
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":"Calldataclass
","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":"Errordataclass
","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 Defaultstatus
Status
categorization of the error.
requiredtype
str
arbitrary string, used for humans.
requiredmessage
str
arbitrary message.
requiredvalue
Optional[Exception]
arbitrary exception from which the error is derived. Optional.
None
Raises:
Type DescriptionValueError
Neither type or message was provided or status is invalid.
"},{"location":"reference/dispatch/#dispatch.Error.from_exception","title":"from_exceptionclassmethod
","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":"Outputdataclass
","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":"valueclassmethod
","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":"errorclassmethod
","text":"error(error: Error) -> Output\n
Terminally exit the function with the provided error.
"},{"location":"reference/dispatch/#dispatch.Output.tail_call","title":"tail_callclassmethod
","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":"exitclassmethod
","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":"pollclassmethod
","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 Defaultinit
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 DescriptionThe return value of the entrypoint function.
"},{"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 Defaultapp
FastAPI
The FastAPI app to configure.
requiredendpoint
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 DescriptionValueError
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/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[[Input], Output]\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 DescriptionDispatchID
DispatchID
ID of the dispatched call.
Raises:
Type DescriptionRuntimeError
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 DescriptionCall
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 Defaultendpoint
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 DescriptionValueError
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 Defaultapi_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 DescriptionValueError
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 Defaultcalls
Iterable[Call]
Calls to dispatch.
requiredReturns:
Type DescriptionList[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 DescriptionList[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 to be serviced by a http server. The Dispatch class acts as a factory for DispatchHandler objects, by capturing the variables that would be shared between all DispatchHandler instances it created.
Parameters:
Name Type Description Defaultregistry
Registry
The registry of functions to be serviced.
required"},{"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":"Argumentsdataclass
","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":"Outputdataclass
","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":"valueclassmethod
","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":"errorclassmethod
","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_callclassmethod
","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":"exitclassmethod
","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":"pollclassmethod
","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":"Calldataclass
","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":"CallResultdataclass
","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":"Errordataclass
","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 Defaultstatus
Status
categorization of the error.
requiredtype
str
arbitrary string, used for humans.
requiredmessage
str
arbitrary message.
requiredvalue
Optional[Exception]
arbitrary exception from which the error is derived. Optional.
None
Raises:
Type DescriptionValueError
Neither type or message was provided or status is invalid.
"},{"location":"reference/dispatch/proto/#dispatch.proto.Error.from_exception","title":"from_exceptionclassmethod
","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":"CallResultdataclass
","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":"CallFuturedataclass
","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":"AllFuturedataclass
","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":"AnyFuturedataclass
","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":"RaceFuturedataclass
","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":"Coroutinedataclass
","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":"Statedataclass
","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 Defaultentry_point
Callable
Entry point for the main coroutine.
requiredversion
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 handler: Callable[[Exception], Status],\n)\n
Register an error type, and a handler which derives a Status from errors of this type.
"},{"location":"reference/dispatch/status/#dispatch.status.register_output_type","title":"register_output_type","text":"register_output_type(\n output_type: Type[Any], handler: Callable[[Any], Status]\n)\n
Register an output type, and a handler which derives a Status from outputs of this type.
"},{"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 Defaultapi_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 Defaultfn
FunctionType
The function to register.
requiredReturns:
Name Type Descriptionstr
RegisteredFunction
Unique identifier for the function.
Raises:
Type DescriptionValueError
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 Defaultkey
str
Unique identifier for the function.
requiredReturns:
Name Type DescriptionRegisteredFunction
RegisteredFunction
the function that was registered with the specified key.
Raises:
Type DescriptionKeyError
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 Defaultrequest
Request
The request to sign.
requiredkey
Ed25519PrivateKey
The Ed25519 private key to use to generate the signature.
requiredcreated
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 Defaultrequest
Request
The request to verify.
requiredkey
Ed25519PublicKey
The Ed25519 public key to use to verify the signature.
requiredmax_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: Client,\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 Defaulthttp_client
Client
Client to use to make HTTP requests.
requiredsigning_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 Defaultrequest
RunRequest
A FunctionService Run request.
requiredReturns:
Name Type DescriptionRunResponse
RunResponse
the response from the endpoint.
"},{"location":"reference/dispatch/test/#dispatch.test.EndpointClient.from_url","title":"from_urlclassmethod
","text":"from_url(\n url: str,\n signing_key: Optional[Ed25519PrivateKey] = None,\n)\n
Returns an EndpointClient for a Dispatch endpoint URL.
"},{"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 Defaultservice
DispatchServiceServicer
Dispatch service to serve.
requiredhostname
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 Defaultendpoint_client
EndpointClient
Client to use to interact with the local Dispatch endpoint (that provides the functions).
requiredapi_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: Client,\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 Defaulthttp_client
Client
Client to use to make HTTP requests.
requiredsigning_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 Defaultrequest
RunRequest
A FunctionService Run request.
requiredReturns:
Name Type DescriptionRunResponse
RunResponse
the response from the endpoint.
"},{"location":"reference/dispatch/test/client/#dispatch.test.client.EndpointClient.from_url","title":"from_urlclassmethod
","text":"from_url(\n url: str,\n signing_key: Optional[Ed25519PrivateKey] = None,\n)\n
Returns an EndpointClient for a Dispatch endpoint URL.
"},{"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 Defaultservice
DispatchServiceServicer
Dispatch service to serve.
requiredhostname
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 Defaultendpoint_client
EndpointClient
Client to use to interact with the local Dispatch endpoint (that provides the functions).
requiredapi_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 0fee438..fe4daf4 100644 Binary files a/main/sitemap.xml.gz and b/main/sitemap.xml.gz differ