langchain_core.runnables.graph_png
.PngDrawer¶
- class langchain_core.runnables.graph_png.PngDrawer(fontname: Optional[str] = None, labels: Optional[LabelsDict] = None)[source]¶
A helper class to draw a state graph into a PNG file. Requires graphviz and pygraphviz to be installed. :param fontname: The font to use for the labels :param labels: A dictionary of label overrides. The dictionary
should have the following format: {
- “nodes”: {
“node1”: “CustomLabel1”, “node2”: “CustomLabel2”, “__end__”: “End Node”
}, “edges”: {
“continue”: “ContinueLabel”, “end”: “EndLabel”
}
} The keys are the original labels, and the values are the new labels.
- Usage:
drawer = PngDrawer() drawer.draw(state_graph, ‘graph.png’)
Methods
__init__
([fontname, labels])add_edge
(viz, source, target[, label])add_edges
(viz, graph)add_node
(viz, node)add_nodes
(viz, graph)draw
(graph[, output_path])Draws the given state graph into a PNG file.
get_edge_label
(label)get_node_label
(label)update_styles
(viz, graph)- Parameters
fontname (Optional[str]) –
labels (Optional[LabelsDict]) –
- __init__(fontname: Optional[str] = None, labels: Optional[LabelsDict] = None) None [source]¶
- Parameters
fontname (Optional[str]) –
labels (Optional[LabelsDict]) –
- Return type
None
- add_edge(viz: Any, source: str, target: str, label: Optional[str] = None) None [source]¶
- Parameters
viz (Any) –
source (str) –
target (str) –
label (Optional[str]) –
- Return type
None
- add_edges(viz: Any, graph: Graph) None [source]¶
- Parameters
viz (Any) –
graph (Graph) –
- Return type
None
- add_nodes(viz: Any, graph: Graph) None [source]¶
- Parameters
viz (Any) –
graph (Graph) –
- Return type
None
- draw(graph: Graph, output_path: Optional[str] = None) Optional[bytes] [source]¶
Draws the given state graph into a PNG file. Requires graphviz and pygraphviz to be installed. :param graph: The graph to draw :param output_path: The path to save the PNG. If None, PNG bytes are returned.
- Parameters
graph (Graph) –
output_path (Optional[str]) –
- Return type
Optional[bytes]