function
¤
PrimitiveFunctionType
module-attribute
¤
A primitive function is a function that accepts a dispatch.proto.Input and unconditionally returns a dispatch.proto.Output. It must not raise exceptions.
Function
¤
Function(
endpoint: str,
client: Client,
name: str,
primitive_func: PrimitiveFunctionType,
func: Callable,
)
Bases: PrimitiveFunction
, Generic[P, T]
Callable wrapper around a function meant to be used throughout the Dispatch Python SDK.
__call__
¤
__call__(
*args: args, **kwargs: kwargs
) -> Coroutine[Any, Any, T]
Call the function asynchronously (through Dispatch), and return a coroutine that can be awaited to retrieve the call result.
dispatch
¤
dispatch(*args: args, **kwargs: kwargs) -> DispatchID
Dispatch an asynchronous call to the function without waiting for a result.
The Registry this function was registered with must be initialized with a Client / api_key for this call facility to be available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
args
|
Positional arguments for the function. |
()
|
**kwargs |
kwargs
|
Keyword arguments for the function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
DispatchID |
DispatchID
|
ID of the dispatched call. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if a Dispatch client has not been configured. |
build_call
¤
build_call(
*args: args,
correlation_id: int | None = None,
**kwargs: kwargs
) -> Call
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 |
int | None
|
optional arbitrary integer the caller can use to match this call to a call result. |
None
|
**kwargs |
kwargs
|
Keyword arguments for the function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Call |
Call
|
can be passed to Client.dispatch. |
Registry
¤
Registry(endpoint: str, client: Client)
Registry of local functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint |
str
|
URL of the endpoint that the function is accessible from. |
required |
client |
Client
|
Client for the Dispatch API. Used to dispatch calls to local functions. |
required |
primitive_function
¤
primitive_function(
primitive_func: PrimitiveFunctionType,
) -> PrimitiveFunction
Decorator that registers primitive functions.