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 Streaming Node

From Leeroopedia
Knowledge Sources
Domains Streaming, Graph_Architecture
Last Updated 2026-10-14 00:00 GMT

Overview

Core async streaming node class with backpressure, tick policies, and dual-number autodiff support, provided by the Tributary library.

Description

The streaming Node class is the fundamental building block of Tributary's streaming subsystem. Each node wraps a callable (function, generator, async function, or async generator) and manages input queues from upstream nodes, downstream propagation, tick policies (drop, replace, repeat), backpressure, rate limiting (delay_interval), execution limits (execution_max), and dual-number arithmetic for automatic differentiation (use_dual).

Nodes are wired together using the >> operator (push downstream) and << operator (pull upstream). The node's __call__ method is async and executes the wrapped callable, propagating results downstream.

Usage

Import this class when you need to create custom streaming nodes, configure tick policies for mismatched timing, or enable dual-number autodiff on streaming graphs. For standard sources and sinks, use the pre-built subclasses (Timer, Const, Func, Print, Collect).

Code Reference

Source Location

  • Repository: Tributary
  • File: tributary/streaming/node.py

Signature

class Node(NodeSerializeMixin, _DagreD3Mixin, object):
    def __init__(
        self,
        func,
        func_kwargs=None,
        name=None,
        inputs=0,
        drop=False,
        replace=False,
        repeat=False,
        graphvizshape="ellipse",
        delay_interval=0,
        execution_max=0,
        use_dual=False,
        **kwargs
    ):
        ...

    async def __call__(self):
        """Execute the callable if possible, and propagate values downstream."""

    def value(self):
        """Get the last value produced by this node."""

    def __rshift__(self, other):
        """Wire self to downstream node (self >> other)."""

    def __lshift__(self, other):
        """Wire other as upstream of self (self << other)."""

    def _backpressure(self):
        """Check if downstream queues are full; if so, don't propagate."""

    async def _output(self, ret):
        """Push value to downstream node input queues."""

    async def _execute(self):
        """Execute the wrapped callable and handle generators/coroutines."""

Import

from tributary.streaming.node import Node
# or:
from tributary.streaming import Node as StreamingNode

I/O Contract

Inputs

Name Type Required Description
func callable Yes Python callable to wrap (function, generator, async function, async generator)
func_kwargs dict No Static keyword arguments for the callable
name str No Display name for the node
inputs int No Number of upstream inputs (default 0)
drop bool No On mismatched tick timing, drop new ticks
replace bool No On mismatched tick timing, replace old ticks with new
repeat bool No On StreamNone, replay last value
delay_interval int/float No Rate limit between executions in seconds
execution_max int No Max execution count (0 = infinite)
use_dual bool No Enable dual-number arithmetic for autodiff

Outputs

Name Type Description
__call__ returns any/StreamNone/StreamEnd The last value produced, or a sentinel
value() returns any The last value pushed downstream

Usage Examples

Basic Node with Tick Policies

import tributary.streaming as ts

# Create a source that emits 1, 2, 3
source = ts.Const(value=1, count=3)

# Create a transform node with drop policy
transform = ts.Node(
    func=lambda x: x * 2,
    name="Double",
    inputs=1,
    drop=True  # drop new ticks if downstream is busy
)
source >> transform

out = ts.Print(transform)
ts.run(out)

Custom Async Node

import tributary.streaming as ts
import asyncio

# Create a node that sleeps before processing
async def slow_process(val):
    await asyncio.sleep(0.1)
    return val ** 2

source = ts.Const(value=5, count=3)
processor = ts.Node(func=slow_process, name="Square", inputs=1)
source >> processor
out = ts.Print(processor)
ts.run(out)
# Output: 25, 25, 25

Dual-Number Node for Autodiff

import tributary.streaming as ts

# Create a node with dual-number mode for autodiff
# value=(f(x), seed) where seed is the derivative seed
source = ts.Node(
    func=lambda: (3.0, 1.0),  # (value=3, derivative seed=1)
    name="x",
    use_dual=True
)

# Compose with operators (automatically use dual-number lambdas)
result = source * source  # x^2, derivative = 2x
out = ts.Print(result)
val = ts.run(out)
# val[0] = 9.0 (function value), val[1] = 6.0 (derivative)

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

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