Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1kbgz Tributary LazyGraph Declarative

From Leeroopedia
Knowledge Sources
Domains Lazy_Evaluation, Declarative_Programming
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete declarative graph class that auto-wires lazy nodes based on AST-analyzed method dependencies, provided by the Tributary library.

Description

The LazyGraph class provides a declarative interface for building lazy computation graphs. Users subclass LazyGraph, define leaf nodes via self.node(name=..., value=...), and decorate computation methods with @node. At construction time, LazyGraph.__init__ scans all methods, finds those with _nodes_to_bind (set by the @node decorator's AST analysis), and wires upstream dependencies using the << operator.

Attribute access is overridden so that graph.xxx returns the Node object for leaf nodes, and graph.xxx = value calls node.setValue(value) to trigger dirty propagation.

Usage

Import this class when you want to build lazy computation graphs declaratively, with automatic dependency wiring based on which self.xxx attributes a method references. This avoids manual << wiring of upstream nodes.

Code Reference

Source Location

  • Repository: Tributary
  • File: tributary/lazy/graph.py

Signature

class LazyGraph(object):
    def __init__(self, *args, **kwargs):
        """Scan all methods, bind self references, wire @node dependencies."""

    def node(self, name, readonly=False, nullable=True, value=None):
        """Create a lazy node attached to this graph.

        Args:
            name: name of the node
            readonly: whether the node should be settable
            nullable: whether node can have value None
            value: initial value for the node
        Returns:
            The newly constructed lazy Node
        """

    def __getattribute__(self, name):
        """Return Node for leaf node names, normal attribute otherwise."""

    def __setattr__(self, name, value):
        """For leaf node names, call node.setValue(value); else normal setattr."""

Import

from tributary.lazy import LazyGraph, node
# or:
from tributary.lazy.graph import LazyGraph
from tributary.lazy.decorator import node

I/O Contract

Inputs

Name Type Required Description
name str Yes (node method) Name of the leaf node
value any No Initial value for the leaf node
readonly bool No Whether the node is settable (default False)
nullable bool No Whether value can be None (default True)

Outputs

Name Type Description
self LazyGraph A graph instance with all nodes wired
evaluate Node The @node-decorated evaluate method returns a Node

Usage Examples

Basic Declarative Graph

from tributary.lazy import LazyGraph, node

class MyGraph(LazyGraph):
    def __init__(self, **kwargs):
        self.node(name="x", value=5)
        self.node(name="y", value=3)
        super().__init__()

    @node
    def evaluate(self):
        return self.x + self.y

graph = MyGraph()
print(graph.evaluate()())  # 8

# Change an input
graph.x = 10
print(graph.evaluate()())  # 13

Dynamic Evaluation

from tributary.lazy import LazyGraph, node
import math

class CircleArea(LazyGraph):
    def __init__(self, **kwargs):
        self.node(name="radius", value=2.0)
        super().__init__()

    @node(dynamic=True)
    def area(self):
        return math.pi * self.radius ** 2

c = CircleArea()
print(c.area())  # 12.566...
c.radius = 5.0
print(c.area())  # 78.539...

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment