pydantic_graph.mermaid
Bases: TypedDict
Parameters to configure mermaid chart generation.
Identifiers of nodes that start the graph.
Type: Sequence[NodeIdent] | NodeIdent
Identifiers of nodes to highlight.
Type: Sequence[NodeIdent] | NodeIdent
CSS to use for highlighting nodes.
Type: str
The title of the diagram.
Whether to include edge labels in the diagram.
Type: bool
Whether to include notes on nodes in the diagram, defaults to true.
Type: bool
The image type to generate. If unspecified, the default behavior is 'jpeg'.
Type: Literal[‘jpeg’, ‘png’, ‘webp’, ‘svg’, ‘pdf’]
When using image_type=‘pdf’, whether to fit the diagram to the PDF page.
Type: bool
When using image_type=‘pdf’, whether to use landscape orientation for the PDF.
This has no effect if using pdf_fit.
Type: bool
When using image_type=‘pdf’, the paper size of the PDF.
Type: Literal[‘letter’, ‘legal’, ‘tabloid’, ‘ledger’, ‘a0’, ‘a1’, ‘a2’, ‘a3’, ‘a4’, ‘a5’, ‘a6’]
The background color of the diagram.
If None, the default transparent background is used. The color value is interpreted as a hexadecimal color
code by default (and should not have a leading ’#’), but you can also use named colors by prefixing the
value with '!'. For example, valid choices include background_color='!white' or background_color='FF0000'.
Type: str
The theme of the diagram. Defaults to ‘default’.
Type: Literal[‘default’, ‘neutral’, ‘dark’, ‘forest’]
The width of the diagram.
Type: int
The height of the diagram.
Type: int
The scale of the diagram.
The scale must be a number between 1 and 3, and you can only set a scale if one or both of width and height are set.
Type: Annotated[float, Ge(1), Le(3)]
An HTTPX client to use for requests, mostly for testing purposes.
Type: httpx.Client
The direction of the state diagram.
Type: StateDiagramDirection
def generate_code(
graph: Graph[Any, Any, Any],
start_node: Sequence[NodeIdent] | NodeIdent | None = None,
highlighted_nodes: Sequence[NodeIdent] | NodeIdent | None = None,
highlight_css: str = DEFAULT_HIGHLIGHT_CSS,
title: str | None = None,
edge_labels: bool = True,
notes: bool = True,
direction: StateDiagramDirection | None,
) -> str
Generate Mermaid state diagram code for a graph.
str — The Mermaid code for the graph.
The graph to generate the image for.
Identifiers of nodes that start the graph.
Identifiers of nodes to highlight.
highlight_css : str Default: DEFAULT_HIGHLIGHT_CSS
CSS to use for highlighting nodes.
The title of the diagram.
edge_labels : bool Default: True
Whether to include edge labels in the diagram.
notes : bool Default: True
Whether to include notes in the diagram.
direction : StateDiagramDirection | None
The direction of flow.
def request_image(
graph: Graph[Any, Any, Any],
kwargs: Unpack[MermaidConfig] = {},
) -> bytes
Generate an image of a Mermaid diagram using mermaid.ink.
bytes — The image data.
The graph to generate the image for.
**kwargs : Unpack[MermaidConfig] Default: \{\}
Additional parameters to configure mermaid chart generation.
def save_image(
path: Path | str,
graph: Graph[Any, Any, Any],
kwargs: Unpack[MermaidConfig] = {},
) -> None
Generate an image of a Mermaid diagram using mermaid.ink and save it to a local file.
path : Path | str
The path to save the image to.
The graph to generate the image for.
**kwargs : Unpack[MermaidConfig] Default: \{\}
Additional parameters to configure mermaid chart generation.
The default CSS to use for highlighting nodes.
Default: 'fill:#fdff32'
Used to specify the direction of the state diagram generated by mermaid.
'TB': Top to bottom, this is the default for mermaid charts.'LR': Left to right'RL': Right to left'BT': Bottom to top
Default: Literal['TB', 'LR', 'RL', 'BT']
A type alias for a node identifier.
This can be:
- A node instance (instance of a subclass of
BaseNode). - A node class (subclass of
BaseNode). - A string representing the node ID.
Type: TypeAlias Default: 'type[BaseNode[Any, Any, Any]] | BaseNode[Any, Any, Any] | str'