Skip to content

Stateflow Graph

StateflowGraph(name, operator_state_backend)

Bases: object

Represents a dataflow graph of operators in a Styx application.

Each node in the graph is an operator. The graph tracks the execution structure, provides utilities for topic resolution, and enables operator lookup and iteration.

Initializes the StateflowGraph.

Parameters:

Name Type Description Default
name str

Name of the graph.

required
operator_state_backend LocalStateBackend

The state backend used by all operators.

required

__iter__()

Returns an iterator over (operator_name, operator) pairs.

Returns:

Type Description
Iterator[tuple[str, BaseOperator]]

Iterator[tuple[str, BaseOperator]]: Iterable of name-operator pairs.

add_operator(operator)

Adds a single operator to the graph.

Parameters:

Name Type Description Default
operator BaseOperator

Operator instance to add.

required

add_operators(*operators)

Adds multiple operators to the graph.

Parameters:

Name Type Description Default
*operators BaseOperator

Variable-length list of BaseOperator instances.

()

get_egress_topic_names()

Returns the Kafka egress topic names for all operators.

Returns:

Type Description
list[str]

list[str]: A list of topic names with '--OUT' suffix.

get_operator(operator)

Retrieves an operator from the graph by name.

Parameters:

Name Type Description Default
operator BaseOperator

The operator whose name will be used as a key.

required

Returns:

Name Type Description
BaseOperator BaseOperator

The corresponding operator instance.