graph_png.py — langchain Source File
Architecture documentation for graph_png.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 7df647ad_c83b_a340_6b52_55758b436999["graph_png.py"] 436f77bc_653d_0edb_555c_c2679d5a59ac["itertools"] 7df647ad_c83b_a340_6b52_55758b436999 --> 436f77bc_653d_0edb_555c_c2679d5a59ac 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 7df647ad_c83b_a340_6b52_55758b436999 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 8551c22a_c7c2_547e_0f94_77eab59053b3["langchain_core.runnables.graph"] 7df647ad_c83b_a340_6b52_55758b436999 --> 8551c22a_c7c2_547e_0f94_77eab59053b3 d21ab087_2db1_2f25_a6f4_9ca06f0eb099["pygraphviz"] 7df647ad_c83b_a340_6b52_55758b436999 --> d21ab087_2db1_2f25_a6f4_9ca06f0eb099 style 7df647ad_c83b_a340_6b52_55758b436999 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Helper class to draw a state graph into a PNG file."""
from itertools import groupby
from typing import Any, cast
from langchain_core.runnables.graph import Graph, LabelsDict
try:
import pygraphviz as pgv # type: ignore[import-not-found]
_HAS_PYGRAPHVIZ = True
except ImportError:
_HAS_PYGRAPHVIZ = False
class PngDrawer:
"""Helper class to draw a state graph into a PNG file.
It requires `graphviz` and `pygraphviz` to be installed.
Example:
```python
drawer = PngDrawer()
drawer.draw(state_graph, "graph.png")
```
"""
def __init__(
self, fontname: str | None = None, labels: LabelsDict | None = None
) -> None:
"""Initializes the PNG drawer.
Args:
fontname: The font to use for the labels. Defaults to "arial".
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.
"""
self.fontname = fontname or "arial"
self.labels = labels or LabelsDict(nodes={}, edges={})
def get_node_label(self, label: str) -> str:
"""Returns the label to use for a node.
Args:
label: The original label.
Returns:
// ... (156 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- itertools
- langchain_core.runnables.graph
- pygraphviz
- typing
Source
Frequently Asked Questions
What does graph_png.py do?
graph_png.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in graph_png.py?
graph_png.py defines 2 function(s): _HAS_PYGRAPHVIZ, pygraphviz.
What does graph_png.py depend on?
graph_png.py imports 4 module(s): itertools, langchain_core.runnables.graph, pygraphviz, typing.
Where is graph_png.py in the architecture?
graph_png.py is located at libs/core/langchain_core/runnables/graph_png.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core/runnables).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free