Skip to main content

View state and graph

NotebookView.state is one consistent, read-only snapshot of browser work.

state = view.state

if (
not state.pending
and state.input_revision is not None
and state.settled_revision == state.input_revision
):
result = state.result("chart")

ViewState

FieldTypeContract
input_revisionoptional intLatest browser update number.
settled_revisionoptional intLatest update where every selected cell finished.
pendingboolWhether the latest update is still running.
resultstuple[CellResult, ...]Selected-cell results in notebook order.
errorstuple[ViewError, ...]Setup or view-level failures.
graphoptional NotebookGraphCurrent read-only dependency graph snapshot.

Before display, both revisions are None. The first browser run uses revision 0. Python updates, browser inputs, and later generator values advance input_revision. While work runs, settled_revision stays at the previous finished revision. Results from older revisions are ignored.

ViewState.result(selector)

Returns the result for a key string, keyed authored Cell, or NotebookCell from the same notebook. Missing results raise KeyError, including requests made before the browser starts. Invalid selector types raise TypeError. Once the state contains results, a handle from another notebook raises ValueError.

CellResult

FieldTypeContract
cellNotebookCellStable selected-cell handle.
revisionintInput revision represented by this result.
statusCellStatus"pending", "success", or "error".
valuesMapping[str, object]Separate, read-only output values.
errorstuple[CellError, ...]Structured failures for this cell.

success means every expected output finished. An error result may still contain values from outputs that succeeded. Read results after the current revision finishes.

Structured errors

CellError contains name, message, phase, and an optional output variable. ViewError contains name, message, and phase. The phase is analysis, evaluation, rendering, or serialization. Browser stack text is not part of the contract.

A JavaScript expression that returns new Error("invalid value") has succeeded. Its value becomes BrowserErrorValue(name, message). A rejected evaluation produces CellError and an error result.

NotebookGraph

MemberContract
cellsImmutable CellInfo records.
edgesImmutable DependencyEdge records.
definesUnique defined names in cell order.
referencesUnique referenced names in cell order.
external_referencesReferenced names absent from evaluated cell outputs.

NotebookGraph.cell(key)

Returns the unique keyed CellInfo. Anonymous cells remain available through graph.cells. Unknown or ambiguous keys raise KeyError.

NotebookGraph.cell_for_variable(variable)

Returns the unique cell that defines a variable. Missing or ambiguous definitions raise KeyError.

Diagram export

graph.to_mermaid() returns a Mermaid flowchart LR string. graph.to_d2() returns a D2 diagram with rightward layout. Diagram labels use the public key and fall back to notebook position for anonymous cells.

CellInfo

CellInfo exposes id, index, mode, key, defines, references, output, outputs, runtime_outputs, autodisplay, autoview, automutable, and optional error fields. The id and index are metadata.

DependencyEdge

Each edge contains source and target CellInfo objects plus the linking variable name.

See Inspect the dependency graph for a live workflow.