Graph command API¶
On this page¶
Command builders¶
st_graph_workbench.component.commands.add_elements_command ¶
add_elements_command(command_id: ElementId, *, nodes: ElementInput = None, edges: ElementInput = None) -> GraphCommand
Build a command that adds only missing nodes and edges in the browser.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.upsert_elements_command ¶
upsert_elements_command(command_id: ElementId, *, nodes: ElementInput = None, edges: ElementInput = None, replace: bool = True) -> GraphCommand
Build a command that adds or updates nodes and edges by data.id.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.update_data_command ¶
update_data_command(command_id: ElementId, element_id: ElementId, data: Dict[str, Any], *, merge: bool = True) -> GraphCommand
Build a command that updates one existing node or edge data dict.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.delete_elements_command ¶
delete_elements_command(command_id: ElementId, *, node_ids: ElementIdInput = None, edge_ids: ElementIdInput = None, remove_incident_edges: bool = True) -> GraphCommand
Build a command that deletes nodes, edges, and optional incident edges.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.set_elements_command ¶
set_elements_command(command_id: ElementId, elements: Elements) -> GraphCommand
Build a command that replaces the browser graph with full elements.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.clear_graph_command ¶
clear_graph_command(command_id: ElementId) -> GraphCommand
Build a command that clears every node and edge from the browser graph.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.viewport_command ¶
viewport_command(command_id: ElementId, operation: ViewportCommandOperation, **options: Any) -> GraphCommand
Build a non-mutating viewport/layout command.
Source code in st_graph_workbench/component/commands.py
Validation and application¶
st_graph_workbench.component.commands.validate_graph_commands ¶
validate_graph_commands(commands: Optional[Iterable[GraphCommand]], *, elements: Optional[Elements] = None) -> None
Validate incremental graph commands before they are sent to the browser.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.apply_graph_command ¶
apply_graph_command(elements: Elements, command: GraphCommand) -> Elements
Return a new graph after applying one command to Python-owned elements.
This helper is useful in Streamlit apps that keep st.session_state
authoritative while also sending the same command to the browser for an
incremental Cytoscape update.
Source code in st_graph_workbench/component/commands.py
st_graph_workbench.component.commands.apply_graph_commands ¶
apply_graph_commands(elements: Elements, commands: Optional[Iterable[GraphCommand]]) -> Elements
Return a new graph after applying commands in order.
Source code in st_graph_workbench/component/commands.py
Command types and errors¶
st_graph_workbench.component.types.GraphCommand
module-attribute
¶
One incremental command sent to the browser graph.
st_graph_workbench.component.commands.GraphCommandValidationError ¶
Bases: ValueError
Raised when incremental graph commands cannot be applied safely.