grapher.DependencyGraph

Usage

Source

grapher.DependencyGraph()

Parameter Attributes

_nodes: dict[NodeKey, Node] = dict()
_edges: dict[NodeKey, set[NodeKey]] = dict()
_reverse_edges: dict[NodeKey, set[NodeKey]] = dict()
_guards: dict[EdgeKey, GuardExpr] = dict()
_edge_extra: dict[EdgeKey, dict[str, Any]] = dict()
_hooks: list[NodeHook] = list()
leaf_classification: dict[str, str] | None = None
sheet_order: list[str] | None = None
sheet_bounds: dict[str, tuple[int, int]] | None = None
named_ranges: dict[str, tuple[str, str]] | None = None
named_range_ranges: dict[str, tuple[str, str, str]] | None = None

Methods

Name Description
add_edge() Add edge: from_key depends on to_key (from_key -> to_key).
compress_identity_transits() Remove identity transit nodes and rewire dependents.
copy() Return a deep copy of this graph (node hooks are not copied).
evaluation_order() Return nodes in dependency-first order (leaves before formulas that use them).
formula_keys() Return sorted list of keys for nodes that contain formulas.
formula_nodes() Iterate over (key, node) pairs for nodes that contain formulas.
get_dependencies() Return an immutable snapshot of key’s dependencies (cells it reads).
get_dependents() Return an immutable snapshot of cells that depend on key.
get_edge_attrs() Return a typed snapshot of the attributes on edge from_key -> to_key.
get_edge_guard() Return the guard on edge from_key -> to_key, or None if none.
get_node() Return an immutable NodeView snapshot, or None if missing.
keys() Return node keys from source (or the graph) using the selected order.
leaf_keys() Return sorted list of keys for nodes with no dependency edges (leaves).
leaf_node_items() Iterate over (key, node) pairs for leaf nodes (no cell dependencies).
leaves() Iterate over keys of leaf nodes (no dependencies).
remove_node() Remove a node and all of its incident edges.
set_node_formula() Set a node’s formula and normalized_formula durably.
set_node_metadata() Replace a node’s metadata mapping durably.
set_node_value() Set a node’s value field durably. Raises KeyError if missing.
target_keys() Return sorted list of keys marked as original build targets.

add_edge()

Add edge: from_key depends on to_key (from_key -> to_key).

Usage

Source

add_edge(from_key, to_key, *, guard=None, **attrs)

compress_identity_transits()

Remove identity transit nodes and rewire dependents.

Usage

Source

compress_identity_transits(*, record=None)

Transit nodes whose formula is a single cell reference to one dependency are removed, dependents’ formulas are rewritten, and edges are rewired. Requires dependency provenance from graph construction with capture_dependency_provenance=True for safe edges.

Node hooks are not invoked for removed or updated nodes.

Parameters
record: IdentityTransitCompressionRecord | None = None
When provided, populate with removal lineage for projection manifests.
Returns
list[NodeKey]
Keys of removed transit nodes, in removal order.

copy()

Return a deep copy of this graph (node hooks are not copied).

Usage

Source

copy()

evaluation_order()

Return nodes in dependency-first order (leaves before formulas that use them).

Usage

Source

evaluation_order(*, strict=True, iterate_enabled=None)

Edge direction is A -> B meaning A depends on B. This method returns an ordering suitable for sequential evaluation (dependencies first).

If iterate_enabled is True (workbook has iterative calculation on), any must-cycle or may-cycle is rejected: generated Python does not emulate Excel’s iterative convergence. Pass False or None to apply the usual strict / non-strict rules without this check.


formula_keys()

Return sorted list of keys for nodes that contain formulas.

Usage

Source

formula_keys()

formula_nodes()

Iterate over (key, node) pairs for nodes that contain formulas.

Usage

Source

formula_nodes()

get_dependencies()

Return an immutable snapshot of key’s dependencies (cells it reads).

Usage

Source

get_dependencies(key)

get_dependents()

Return an immutable snapshot of cells that depend on key.

Usage

Source

get_dependents(key)

get_edge_attrs()

Return a typed snapshot of the attributes on edge from_key -> to_key.

Usage

Source

get_edge_attrs(from_key, to_key)

When the edge does not exist, returns an EdgeAttrs with all fields set to None.


get_edge_guard()

Return the guard on edge from_key -> to_key, or None if none.

Usage

Source

get_edge_guard(from_key, to_key)

get_node()

Return an immutable NodeView snapshot, or None if missing.

Usage

Source

get_node(key)

keys()

Return node keys from source (or the graph) using the selected order.

Usage

Source

keys(*, order="insertion", source=None)

leaf_keys()

Return sorted list of keys for nodes with no dependency edges (leaves).

Usage

Source

leaf_keys()

leaf_node_items()

Iterate over (key, node) pairs for leaf nodes (no cell dependencies).

Usage

Source

leaf_node_items()

leaves()

Iterate over keys of leaf nodes (no dependencies).

Usage

Source

leaves()

remove_node()

Remove a node and all of its incident edges.

Usage

Source

remove_node(key)

Both outgoing dependency edges and incoming dependent edges are dropped, along with their guards and provenance. Dependent formulas are not rewritten; callers collapsing nodes must update dependents explicitly. Node hooks are not invoked. No-op if the node is absent.


set_node_formula()

Set a node’s formula and normalized_formula durably.

Usage

Source

set_node_formula(key, formula, normalized_formula)

Edges are not recomputed; callers rewiring dependencies must update edges explicitly. Intended for projection authors building export-only graph views. Raises KeyError if the node is missing.


set_node_metadata()

Replace a node’s metadata mapping durably.

Usage

Source

set_node_metadata(key, metadata)

The provided mapping is copied; subsequent mutations to the caller’s object do not affect graph state. Raises KeyError if the node is missing.


set_node_value()

Set a node’s value field durably. Raises KeyError if missing.

Usage

Source

set_node_value(key, value)

target_keys()

Return sorted list of keys marked as original build targets.

Usage

Source

target_keys()