visualize()

Render a knowledge graph and open it in the browser.

Usage

Source

visualize(
    kg,
    *,
    output=None,
    max_nodes=200,
    node_type=None,
    color_by="type",
    title="Knowledge Graph",
    open_browser=True
)

Writes an interactive HTML file and optionally opens it in the default browser.

Parameters

kg: KnowledgeGraph

The knowledge graph to visualize.

output: str | Path | None = None

Path for the HTML file. Defaults to a temporary file.

max_nodes: int = 200

Maximum nodes to include.

node_type: NodeType | None = None

If provided, only include nodes of this type.

color_by: str = "type"

Color scheme: "type" or "freshness".

title: str = "Knowledge Graph"

Page title.

open_browser: bool = True
If True (default), open the file in the default browser.

Returns

Path
Path to the generated HTML file.

Examples

import talk_box as tb

kg = tb.KnowledgeGraph(":memory:")
# ... add nodes ...
path = tb.visualize(kg, open_browser=False)
path  # PosixPath('/tmp/talk_box_kg_xxxxx.html')