Data model
These are the classes that make up ipyflow’s dataflow graph. The The dataflow model page explains how they fit together; this page is the class reference. They are internal-heavy – only the user-facing members are documented here.
Timestamp
- class ipyflow.data_model.timestamp.Timestamp(cell_num: int, stmt_num: int)[source]
A
(cell_num, stmt_num)pair naming one point in execution.cell_numis the cell execution counter (1-indexed, strictly increasing across the session);stmt_numis the 0-indexed statement within that cell execution. Comparing the timestamp of a symbol against those of its dependencies is how ipyflow decides staleness.
Symbol
Obtain a Symbol from a value with lift(value), or from the graph via the
deps / users helpers.
- class ipyflow.data_model.symbol.Symbol(name: str | int | bool | None | Tuple[str | int | bool | None, ...], symbol_type: SymbolType, obj: Any, containing_scope: Scope, stmt_node: stmt | Lambda | None = None, symbol_node: AST | None = None, refresh_cached_obj: bool = False, implicit: bool = False)[source]
A node in the dataflow graph: a variable binding or object member.
A
Symboltracks the name it is bound under, a reference to the underlying Python object (obj), theTimestampat which it was last written, and its dataflow edges –parents(the symbols it was computed from) andchildren(the symbols computed from it). The publicipyflow.apihelpers (deps,users,code,timestamp, …) are thin wrappers that resolve a value to itsSymboland read these attributes. Uselift(value)to obtain one directly.- remove_tag(tag_value: str) None[source]
Remove the string tag
tag_valuefrom this symbol (a no-op if absent).
- property timestamp: Timestamp
The
Timestampof the last write, accounting for updates to the symbol’s namespace members.
- code(format_type: Type[FormatType] | None = None, version: int = -1) Slice[source]
Return the backward program slice that reconstructs this symbol.
- Parameters:
format_type – optional output format (e.g.
str); defaults to a richHTMLwhen available, otherwise plain text.version – which historical version of the symbol to slice for.
-1(the default) is the current version.
In addition to the documented members above, a Symbol exposes obj (the
underlying object), parents and children (the dataflow edges, as dicts
keyed by Symbol), and containing_scope.
Cell
Access cells with cells() (the class) and cells(id) (an instance); see
Model accessors (ipyflow.models).
- class ipyflow.data_model.cell.Cell(cell_id: str | int, cell_ctr: int, content: str, tags: Tuple[str, ...], prev_cell: Cell | None = None, placeholder_id: bool = False, memoized_output_level: MemoizedOutputLevel | None = None)[source]
A notebook code cell and its place in the dataflow graph.
Each
Cellrecords the frontendcell_id, the execution countercell_ctrat which it ran, its sourcecontent, itstags, and itspositionin the notebook. Cell-to-cell dataflow edges are derived from the symbol edges the tracer records. Access cells with thecells()accessor:cells()returns this class (use classmethods likeat_counterandcurrent_cell), andcells(id)returns a specific instance.- slice(stmts: bool = False, seed_only: bool = False, format_type: Type[FormatType] | None = None, include_cell_headers: bool = True) Slice[source]
Return the backward slice needed to reconstruct this cell.
- Parameters:
stmts – if
True, slice at statement granularity (dropping unneeded statements within cells); otherwise include whole cells.seed_only – restrict the slice to this cell alone (no upstream).
format_type – optional output format (e.g.
str).include_cell_headers – whether to emit
# Cell Nheaders.
Instances also carry the attributes set at execution time: cell_id (frontend
id), cell_ctr (execution counter), current_content / executed_content
(source), position (notebook order), and tags.
Scope, Namespace, and Statement
A Scope is a symbol table mapping names to
symbols. A Namespace is a Scope
attached to a particular object, representing its attributes and items (for
example df.columns or d["key"]); this is what enables dependency tracking
below the variable level. A Statement is
the per-AST-statement analog of a Cell and underpins statement-level slicing.
These classes are primarily internal; interact with them through the accessors in
Model accessors (ipyflow.models) (scopes(), namespaces(), statements()) and the concepts
overview in The dataflow model.
Watchpoints
- class ipyflow.tracing.watchpoint.Watchpoints(iterable=(), /)[source]
The collection of
Watchpointobjects registered on a symbol.Obtain one with
watchpoints(sym). It behaves like a read-only list; add watchpoints withadd()rather than the usual list-mutation methods (which are disabled).- add(pred: Callable[[...], bool] | None = None, name: str | None = None)[source]
Register a watchpoint.
- Parameters:
pred – a callable invoked as
pred(obj, position=(cell_num, stmt_num), symbol_name=...)on each write to the watched symbol, returning truthy when the condition is met.Nonealways passes.name – an optional label for the watchpoint (used in
repr).
- class ipyflow.tracing.watchpoint.Watchpoint(name: str | None, pred: Callable[[...], bool] | None)[source]
A single named predicate evaluated whenever a watched symbol is written.
The predicate is called as
pred(obj, position=(cell_num, stmt_num), symbol_name=...)and should return a truthy value when the watchpoint condition is met. ANonepredicate always passes.