Async Styx Client
AsyncStyxClient(styx_coordinator_adr, styx_coordinator_port, kafka_url)
¶
Bases: BaseStyxClient
Asynchronous client for interacting with a Styx deployment using asyncio and aiokafka.
Handles event submission, result polling, and metadata updates over Kafka.
Initializes an asynchronous Styx client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styx_coordinator_adr
|
str
|
Address of the Styx coordinator. |
required |
styx_coordinator_port
|
int
|
Port of the Styx coordinator. |
required |
kafka_url
|
str
|
Kafka bootstrap server URL. |
required |
close()
async
¶
Closes the client by stopping Kafka consumers/producers and cancelling tasks.
flush()
async
¶
Flushes the Kafka producer buffer to ensure all messages are sent.
get_operator_partition(key, operator)
async
¶
Returns the partition for a given key/operator pair.
Waits for the metadata graph to be known before resolving the partition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Any
|
Partitioning key. |
required |
operator
|
BaseOperator
|
Operator to resolve. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Partition number. |
open(consume=True)
async
¶
Initializes the Kafka producer and optionally starts result and metadata consumer tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
consume
|
bool
|
Whether to consume results in a background task. Defaults to True. |
True
|
send_event(operator, key, function, params=tuple(), serializer=Serializer.MSGPACK)
async
¶
Sends a single function invocation event to an operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
BaseOperator
|
Target operator. |
required |
key
|
Any
|
Partitioning key for the event. |
required |
function
|
Type | str
|
Function or method to invoke. |
required |
params
|
tuple
|
Parameters to the function. |
tuple()
|
serializer
|
Serializer
|
Serialization strategy. Defaults to MSGPACK. |
MSGPACK
|
Returns:
Name | Type | Description |
---|---|---|
StyxAsyncFuture |
StyxAsyncFuture
|
Future representing the pending result of the event. |
submit_dataflow(stateflow_graph, external_modules=None)
async
¶
Submits a dataflow graph to the Styx coordinator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stateflow_graph
|
StateflowGraph
|
The graph to submit. |
required |
external_modules
|
tuple
|
External modules required by the graph. |
None
|