Explore graphs and reasoning offline

GestaltDB turns selected graph records, query results, samples and reasoning explanations into offline interactive HTML or static SVG. The viewer is packaged with the base library: no JavaScript toolchain, CDN, server or network access is required to render it. A database-backed example still needs an installed backend; explicit collections and standalone reasoning figures do not.

Choose the data to show before rendering

Input

Entry point

Boundary

Nodes and edges already in memory

visualize_nodes_edges

Base install; caller selects the records

Current graph query or live neighborhood

graph.visualize(cypher=...) or graph.visualize(seeds=..., pattern=...)

Explicit backend; query/sample before displaying a large graph

Array-native sampling batch

visualize_sampler_batch(batch, snapshot)

Requires the batch’s exact snapshot for ID conversion

Claim, proof, audit, supports or ontology

The corresponding visualize_* builder

Displayed evidence is not an independent proof or truth certificate

Query and sample a small graph

This disposable example renders the same two-person graph from a query and a typed neighborhood sample. HTML files include their data and viewer; SVG is generated directly from the Python figure without a browser. Replace the temporary output directory with your own destination to retain an artifact.

Standalone example. Choose the capability-qualified installation tab below.

The graph-query visualization accepts these simple stored values. Rendering remains independent of backend choice.

1python -m pip install "gestaltdb[leveldb]"
 1from pathlib import Path
 2from tempfile import TemporaryDirectory
 3from gestaltdb.graphdb import Edge, GraphDB, Node
 4from gestaltdb.viz.api import VizOptions
 5
 6with TemporaryDirectory() as directory:
 7    with GraphDB.create(f"{directory}/db", backend='leveldb', serializer='pickle') as graph:
 8        graph.put_nodes([
 9            Node("alice", labels=["Person"], properties={"name": "Alice"}),
10            Node("bob", labels=["Person"], properties={"name": "Bob"}),
11        ])
12        graph.put_edge(Edge("e1", "alice", "bob", {"type": "knows"}))
13        options = VizOptions(node_label_property="name", edge_labels="all")
14        figure = graph.visualize(
15            'MATCH (a:Person)-[r:knows]->(b) RETURN a, r, b', options=options,
16        )
17        sampled = graph.visualize(
18            seeds=["alice"], pattern=[{"edge_type": "knows", "sample_size": 5}], options=options,
19        )
20        assert figure.viz.node_ids == ("alice", "bob")
21        assert sampled.viz.edge_ids == ("e1",)
22    # Figures contain their selected payload; the database can now be closed.
23    html_path = figure.save(Path(directory) / "knows.html")
24    svg_path = figure.save_svg(Path(directory) / "knows.svg", layout="circle")
25    sampled.save(Path(directory) / "neighborhood.html")
26    assert "Alice" in html_path.read_text() and "<svg" in svg_path.read_text()

Inspect a standalone reasoning witness

An ontology can derive that Alice is a Person from her employment relation. A witness records one route to that conclusion. This backend-free example renders the witness and the ontology separately; it does not write claims, merge identifiers or certify the supplied employment fact.

Standalone example. Install with python -m pip install "gestaltdb".

 1from pathlib import Path
 2from tempfile import TemporaryDirectory
 3from gestaltdb.ontology import Domain, Ontology, TYPE_PREDICATE, compile_ontology
 4from gestaltdb.reasoning import DatalogEngine, Fact, ReasoningLimits
 5from gestaltdb.viz.api import VizOptions, visualize_ontology, visualize_proof_explanation
 6
 7ontology = Ontology("people", [Domain("worksFor", "Person")])
 8compiled = compile_ontology(ontology)
 9result = DatalogEngine().evaluate(
10    compiled.program, [Fact("alice", "worksFor", "lab")],
11    limits=ReasoningLimits(), collect_proofs=True,
12)
13explanation = result.explain(Fact("alice", TYPE_PREDICATE, "Person"))
14assert not explanation.truncated
15options = VizOptions(node_label_property="label", edge_labels="all")
16proof = visualize_proof_explanation(explanation, options=options)
17schema = visualize_ontology(ontology, options=options)
18with TemporaryDirectory() as directory:
19    proof.save(Path(directory) / "witness.html")
20    svg_path = proof.save_svg(Path(directory) / "witness.svg")
21    schema.save_svg(Path(directory) / "ontology.svg")
22    assert "alice" in svg_path.read_text()

The generated witness figure in Facts, Rules, and Explanations uses these same public APIs. For historical claim explanations and model-output audits, follow Sourced claims and conflicting evidence and Unified inference audit. Exact builder directions, shapes and all-support versus first-witness display are in Visualization controls and export reference.

Choose an output, not an implied synchronization mode

  • HTML / Jupyter: save writes a self-contained interactive artifact; displaying figure in a notebook embeds its HTML in a height-bounded iframe. It does not query the database again or synchronize changes with Python.

  • Python SVG: save_svg uses deterministic layouts or supplied coordinates. It does not capture browser dragging, filters, selection or zoom. Reasoning figures suggest a layered tree; ordinary graph figures default to a circle.

  • Browser SVG/PNG: export the current viewport or all visible content with the active browser styling/filters. Direct Python PNG rasterization is not provided. Browser export is not a replacement for the underlying graph data.

  • View-state JSON: restores positions, pins, settings and simulation state only for the same embedded topology. It is separate from graph JSON; loading it neither loads new records nor contacts a notebook kernel or database.

Figures cap displayed topology (defaults 2,000 nodes / 5,000 edges) and warn on deterministic truncation; exceeding absolute ceilings raises. Use a bounded query or sample for large graphs rather than assuming rendering is out-of-core. Artifacts embed selected data/properties: browser hiding is not access control. Select only data you intend to distribute before saving the artifact.

Continue with Notebook Usage for kernel/lifetime setup, Exchange current graphs with NetworkX and GEXF for materialized graph exchange and Performance and Benchmarks for separate extraction, layout/export and application costs.