Data and element helper API¶
On this page¶
Record conversion¶
st_graph_workbench.component.records.dataframe_to_records ¶
dataframe_to_records(dataframe: Any, *, drop_missing: bool = False) -> list[Record]
Convert a dataframe-like object to JSON-friendly record dictionaries.
Supports pandas dataframes, Polars dataframes, and Arrow-like tables that
expose one of the common record-export methods. Scalar missing values become
None so records can be passed safely into graph_workbench(...).
Nested tuples, sets, array-like values, datetimes, and decimals are
normalized into deterministic JSON-friendly values.
Source code in st_graph_workbench/component/records.py
st_graph_workbench.component.records.records_to_dataframe ¶
records_to_dataframe(records: Mapping[str, Any] | Sequence[Mapping[str, Any]], *, group_key: str = 'record_group', flatten_data: bool = True) -> Any
Convert record dictionaries to a pandas dataframe.
records may be a normal list of dictionaries, a dictionary of named
record groups such as {"sightings": [...]}, a graph element dictionary
such as {"nodes": [...], "edges": [...]}, or the element records in a
selection/search event. Graph and event element data fields are
flattened into columns by default so returned records are immediately
useful in Streamlit and notebooks.
Source code in st_graph_workbench/component/records.py
Element helpers¶
st_graph_workbench.component.elements.get_element ¶
Return a copy of a node or edge by ID, or None when it is not present.
Source code in st_graph_workbench/component/elements.py
st_graph_workbench.component.elements.upsert_elements ¶
upsert_elements(elements: Elements, *, nodes: ElementInput = None, edges: ElementInput = None, replace: bool = True) -> Elements
Return a graph with nodes and edges added or updated by data.id.
Source code in st_graph_workbench/component/elements.py
st_graph_workbench.component.elements.update_element_data ¶
update_element_data(elements: Elements, element_id: ElementId, data: dict[str, Any], *, merge: bool = True) -> Elements
Return a graph with one node or edge data dict updated.
Source code in st_graph_workbench/component/elements.py
st_graph_workbench.component.elements.delete_elements ¶
delete_elements(elements: Elements, *, node_ids: ElementIdInput = None, edge_ids: ElementIdInput = None, remove_incident_edges: bool = True) -> Elements
Return a graph with selected nodes, edges, and optional incident edges removed.
Source code in st_graph_workbench/component/elements.py
Validation¶
st_graph_workbench.component.validation.validate_elements ¶
Validate Streamlit graph elements before they are sent to Cytoscape.
Cytoscape treats IDs as strings and requires every edge source/target to reference an existing node. This helper catches common data-shape mistakes on the Python side so Streamlit apps get actionable errors instead of a browser-side rendering failure.
Source code in st_graph_workbench/component/validation.py
st_graph_workbench.component.validation.ElementValidationError ¶
Bases: ValueError
Raised when graph elements cannot be safely rendered by Cytoscape.
Element types¶
st_graph_workbench.component.types.Element
module-attribute
¶
One Cytoscape node or edge dictionary.
st_graph_workbench.component.types.ElementId
module-attribute
¶
One node, edge, command, source, target, or parent identifier.
st_graph_workbench.component.types.ElementIdInput
module-attribute
¶
One identifier, an iterable of identifiers, or no identifiers.
st_graph_workbench.component.types.Elements
module-attribute
¶
A graph dictionary containing nodes and edges lists.
st_graph_workbench.component.types.Record
module-attribute
¶
One table-like or JSON-ready record dictionary.
st_graph_workbench.component.types.Layout
module-attribute
¶
A named layout or a Cytoscape layout options dictionary.