test
¤
EndpointClient
¤
EndpointClient(
http_client: Client,
signing_key: Ed25519PrivateKey | None = None,
)
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, for example a FastAPI app.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
http_client |
Client
|
Client to use to make HTTP requests. |
required |
signing_key |
Ed25519PrivateKey | None
|
Optional Ed25519 private key to use to sign requests. |
None
|
run
¤
run(request: RunRequest) -> RunResponse
Send a run request to an endpoint and return its response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request |
RunRequest
|
A FunctionService Run request. |
required |
Returns:
Name | Type | Description |
---|---|---|
RunResponse |
RunResponse
|
the response from the endpoint. |
from_url
classmethod
¤
from_url(
url: str, signing_key: Ed25519PrivateKey | None = None
)
Returns an EndpointClient for a Dispatch endpoint URL.
from_app
classmethod
¤
from_app(
app: FastAPI,
signing_key: Ed25519PrivateKey | None = None,
)
Returns an EndpointClient for a Dispatch endpoint bound to a FastAPI app instance.
DispatchServer
¤
DispatchServer(
service: DispatchServiceServicer,
hostname: str = "127.0.0.1",
port: int = 0,
)
Test server for a Dispatch service. This is useful for testing a mock version of Dispatch locally (e.g. see dispatch.test.DispatchService).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service |
DispatchServiceServicer
|
Dispatch service to serve. |
required |
hostname |
str
|
Hostname to bind to. |
'127.0.0.1'
|
port |
int
|
Port to bind to, or 0 to bind to any available port. |
0
|
DispatchService
¤
DispatchService(
endpoint_client: EndpointClient,
api_key: str | None = None,
retry_on_status: set[Status] | None = None,
collect_roundtrips: bool = False,
)
Bases: DispatchServiceServicer
Test instance of Dispatch that provides the bare minimum functionality required to test functions locally.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
endpoint_client |
EndpointClient
|
Client to use to interact with the local Dispatch endpoint (that provides the functions). |
required |
api_key |
str | None
|
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 |
set[Status] | None
|
Set of status codes to enable retries for. |
None
|
collect_roundtrips |
bool
|
Enable collection of request/response round-trips to the configured endpoint. |
False
|
Dispatch
¤
Dispatch(request: DispatchRequest, context)
RPC handler for Dispatch requests. Requests are only queued for processing here.
dispatch_calls
¤
dispatch_calls()
Synchronously dispatch pending function calls to the configured endpoint.
start
¤
start()
Start starts a background thread to continuously dispatch calls to the configured endpoint.