Managed expansion API¶
On this page¶
Managed expansion keeps application-owned source data separate from cached records and the displayed graph. Start with the branch guide.
Controller¶
st_graph_workbench.component.expansion.ExpansionController ¶
ExpansionController(elements: Elements, *, source_id: str = 'graph', source_version: str = '1', config: ExpansionConfig | None = None)
Maintain reversible graph views, independent of a Streamlit runtime.
Initialize with the starting graph. Store one controller per application
session/component. Call request then the provider, then apply_response;
or use expand for a synchronous batch. view is safe to render and
loaded includes collapsed records. Neither returns mutable internal data.
Source code in st_graph_workbench/component/expansion.py
branch_id ¶
branch_id(node_id: ElementId, query: dict[str, Any] | None = None) -> str
Return a stable identity for a starting node and normalized filters.
Source code in st_graph_workbench/component/expansion.py
request ¶
request(node_id: ElementId, *, query: dict[str, Any] | None = None, more: bool = False) -> ExpansionRequest | None
Start a batch, or restore a cached branch without fetching again.
Source code in st_graph_workbench/component/expansion.py
apply_response ¶
apply_response(response: ExpansionResponse) -> bool
Atomically accept a current response; return false for stale/duplicate data.
Source code in st_graph_workbench/component/expansion.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
fail ¶
Finish a failed request without advancing its cursor or changing its view.
Source code in st_graph_workbench/component/expansion.py
expand ¶
expand(node_id: ElementId, provider: ExpansionProvider, *, query: dict[str, Any] | None = None, more: bool = False) -> bool
Accept one synchronous batch, preserving the last valid view on failure.
Return true for an accepted provider response. Restoring cached branches,
already-pending requests, and failures return false; inspect describe
for pending/error status and view for the resulting graph.
Source code in st_graph_workbench/component/expansion.py
collapse ¶
collapse(node_ids: list[ElementId] | None = None, *, branch_id: str | None = None) -> None
Close branches, retaining anchors; an explicit branch_id takes precedence.
Source code in st_graph_workbench/component/expansion.py
collapse_all ¶
Close all branches, preserving starting and explicitly protected records.
protect ¶
protect(element_ids: list[ElementId], *, enabled: bool = True) -> None
Keep records visible independently of branch state; not a position lock.
Source code in st_graph_workbench/component/expansion.py
set_visibility ¶
Set independent hide/filter masks; an empty list restores only that mask.
Source code in st_graph_workbench/component/expansion.py
update_records ¶
update_records(elements: Elements) -> None
Apply explicit application-owned edits to the cache, including positions.
Source code in st_graph_workbench/component/expansion.py
delete_records ¶
delete_records(element_ids: list[ElementId]) -> None
Apply actual source deletion, unlike collapse; suppress stale resurrection.
Source code in st_graph_workbench/component/expansion.py
invalidate ¶
invalidate(elements: Elements, *, source_version: str) -> None
Replace the source checkpoint explicitly, clearing incompatible exploration.
Source code in st_graph_workbench/component/expansion.py
commands ¶
commands(previous: Elements, *, restore_positions: bool = False) -> list[GraphCommand]
Reconcile the view; restore_positions explicitly reapplies saved positions.
Source code in st_graph_workbench/component/expansion.py
start_bulk ¶
start_bulk(node_ids: list[ElementId], *, query: dict[str, Any] | None = None) -> None
Queue breadth-first bounded exploration; call step once per application tick.
Source code in st_graph_workbench/component/expansion.py
step ¶
step(provider: ExpansionProvider) -> bool
Process at most one batch. Return whether more bulk work remains.
Source code in st_graph_workbench/component/expansion.py
cancel ¶
Invalidate outstanding responses and stop scheduling new bulk batches.
Source code in st_graph_workbench/component/expansion.py
retry_bulk ¶
reveal ¶
reveal(element_id: ElementId) -> None
Restore a cached result through recorded branches, including real context.
Source code in st_graph_workbench/component/expansion.py
reveal_search_result ¶
Validate and reveal a provider-supplied real path from an existing anchor.
Source code in st_graph_workbench/component/expansion.py
snapshot ¶
Export state without provider objects; source properties may be sensitive.
Source code in st_graph_workbench/component/expansion.py
restore
classmethod
¶
restore(snapshot: dict[str, Any], *, source_version: str, source_id: str | None = None) -> ExpansionController
Restore a compatible snapshot; require explicit invalidation for new sources.
Source code in st_graph_workbench/component/expansion.py
describe ¶
describe(provider: ExpansionProvider | None = None) -> dict[str, Any]
Return JSON configuration for graph_workbench(expansion=...).
Includes independent expand/collapse availability and exact next-change counts when a local preview exists. Unknown remote counts remain None.
Source code in st_graph_workbench/component/expansion.py
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | |
handle_event ¶
handle_event(event: GraphEvent | None, provider: ExpansionProvider) -> None
Handle explicit expansion intents; applications schedule bulk step separately.
Source code in st_graph_workbench/component/expansion.py
Requests and providers¶
st_graph_workbench.component.expansion.ExpansionRequest
dataclass
¶
ExpansionRequest(request_id: str, branch_id: str, node_id: str, query: dict[str, Any], cursor: Any, limit: int, source_id: str, source_version: str, revision: int)
One versioned, repeatable provider query, with an opaque JSON cursor.
st_graph_workbench.component.expansion.ExpansionResponse
dataclass
¶
ExpansionResponse(request_id: str, elements: Elements, has_more: bool = False, cursor: Any = None, total_nodes: int | None = None, total_edges: int | None = None)
One complete batch; edges may reference records in the loaded cache.
Totals count distinct nodes and edges separately, not domain rows. None
means unknown. A continuing response must advance its cursor.
st_graph_workbench.component.expansion.ExpansionProvider ¶
Bases: Protocol
Application-owned loader. Optional search/analyze stay explicit.
Implement expand(request) to return a batch or raise an actionable error.
Optional preview(request) returns the same batch without I/O, enabling
exact next-change counts. It must not fetch from a remote service on render.
expand ¶
expand(request: ExpansionRequest) -> ExpansionResponse
st_graph_workbench.component.expansion_provider.InMemoryExpansionProvider ¶
InMemoryExpansionProvider(elements: Elements)
Expand dataframe-derived dictionaries without modifying the source graph.
Pages contain distinct neighboring nodes and all matching edges to them.
Relationship labels and direction filter edges; attributes match the merged
edge/neighbor data (neighbor values win). Time filters use ISO-8601 values
from the configured edge field, falling back to the neighboring node field.
search returns verified paths from supplied roots, not isolated matches.
Source code in st_graph_workbench/component/expansion_provider.py
expand ¶
expand(request: ExpansionRequest) -> ExpansionResponse
Return an immutable source page, with separate exact node and edge totals.
Source code in st_graph_workbench/component/expansion_provider.py
preview ¶
preview(request: ExpansionRequest) -> ExpansionResponse
Preview the next page using the local index, without remote I/O.
search ¶
Search source node properties and return real connecting paths from roots.
Disconnected matches are reported separately and are not silently added as new exploration anchors. Applications may explicitly protect/load them.
Source code in st_graph_workbench/component/expansion_provider.py
Configuration and operations¶
st_graph_workbench.component.expansion.ExpansionConfig
dataclass
¶
ExpansionConfig(page_size: int = 50, max_depth: int = 3, max_nodes: int = 500, max_edges: int = 2000)
Finite exploration limits; bulk limits count additional displayed records.
st_graph_workbench.component.expansion.ExpansionOperation
module-attribute
¶
ExpansionOperation = Literal['expand', 'load_more', 'collapse', 'collapse_all', 'expand_all', 'protect', 'unprotect', 'cancel', 'retry', 'reveal', 'search', 'analyze', 'continue']
Explicit operations emitted by opt-in expansion controls.
Events use action="expansion". The operation is one of expand, load_more,
collapse, collapse_all, expand_all, protect, unprotect, cancel,
retry, reveal, search, analyze, or continue.
The exploration dialog is browser-local; continue schedules a single bulk batch.
Applications normally pass returned events to controller.handle_event(event, provider).