draw_mermaid_png() — langchain Function Reference
Architecture documentation for the draw_mermaid_png() function in graph_mermaid.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD affcc91c_bcd9_50c2_5762_c17c81886c6a["draw_mermaid_png()"] c545ef44_a033_15ff_e016_18af37277247["graph_mermaid.py"] affcc91c_bcd9_50c2_5762_c17c81886c6a -->|defined in| c545ef44_a033_15ff_e016_18af37277247 e4ea941d_52a7_cfaa_e5e3_77cb8a320bf3["_render_mermaid_using_api()"] e4ea941d_52a7_cfaa_e5e3_77cb8a320bf3 -->|calls| affcc91c_bcd9_50c2_5762_c17c81886c6a f12768d7_87ad_702b_934f_217228b590c5["requests()"] affcc91c_bcd9_50c2_5762_c17c81886c6a -->|calls| f12768d7_87ad_702b_934f_217228b590c5 bf3680e2_9ce5_0796_dd67_2a37f682c93b["_render_mermaid_using_pyppeteer()"] affcc91c_bcd9_50c2_5762_c17c81886c6a -->|calls| bf3680e2_9ce5_0796_dd67_2a37f682c93b e4ea941d_52a7_cfaa_e5e3_77cb8a320bf3["_render_mermaid_using_api()"] affcc91c_bcd9_50c2_5762_c17c81886c6a -->|calls| e4ea941d_52a7_cfaa_e5e3_77cb8a320bf3 style affcc91c_bcd9_50c2_5762_c17c81886c6a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph_mermaid.py lines 277–331
def draw_mermaid_png(
mermaid_syntax: str,
output_file_path: str | None = None,
draw_method: MermaidDrawMethod = MermaidDrawMethod.API,
background_color: str | None = "white",
padding: int = 10,
max_retries: int = 1,
retry_delay: float = 1.0,
base_url: str | None = None,
proxies: dict[str, str] | None = None,
) -> bytes:
"""Draws a Mermaid graph as PNG using provided syntax.
Args:
mermaid_syntax: Mermaid graph syntax.
output_file_path: Path to save the PNG image.
draw_method: Method to draw the graph.
background_color: Background color of the image.
padding: Padding around the image.
max_retries: Maximum number of retries (MermaidDrawMethod.API).
retry_delay: Delay between retries (MermaidDrawMethod.API).
base_url: Base URL for the Mermaid.ink API.
proxies: HTTP/HTTPS proxies for requests (e.g. `{"http": "http://127.0.0.1:7890"}`).
Returns:
PNG image bytes.
Raises:
ValueError: If an invalid draw method is provided.
"""
if draw_method == MermaidDrawMethod.PYPPETEER:
img_bytes = asyncio.run(
_render_mermaid_using_pyppeteer(
mermaid_syntax, output_file_path, background_color, padding
)
)
elif draw_method == MermaidDrawMethod.API:
img_bytes = _render_mermaid_using_api(
mermaid_syntax,
output_file_path=output_file_path,
background_color=background_color,
max_retries=max_retries,
retry_delay=retry_delay,
base_url=base_url,
proxies=proxies,
)
else:
supported_methods = ", ".join([m.value for m in MermaidDrawMethod])
msg = (
f"Invalid draw method: {draw_method}. "
f"Supported draw methods are: {supported_methods}"
)
raise ValueError(msg)
return img_bytes
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does draw_mermaid_png() do?
draw_mermaid_png() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph_mermaid.py.
Where is draw_mermaid_png() defined?
draw_mermaid_png() is defined in libs/core/langchain_core/runnables/graph_mermaid.py at line 277.
What does draw_mermaid_png() call?
draw_mermaid_png() calls 3 function(s): _render_mermaid_using_api, _render_mermaid_using_pyppeteer, requests.
What calls draw_mermaid_png()?
draw_mermaid_png() is called by 1 function(s): _render_mermaid_using_api.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free