Implementation:1kbgz Tributary Streaming Transforms
| Knowledge Sources | |
|---|---|
| Domains | Streaming, Data_Transformation |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete streaming transform functions for applying operations to data streams, provided by the Tributary library.
Description
The streaming transform functions wrap upstream Node instances into new downstream nodes that modify the stream. Window collects values into a sliding window, Apply applies a user-defined function to each value, Delay pauses the stream, Merge combines two streams, Reduce merges N streams with a custom reducer, Debounce filters duplicates, Throttle rate-limits, and Unroll flattens iterables.
Each transform creates a new Node and wires the input via the >> operator.
Usage
Import these functions when you need to transform, filter, window, or merge streaming data. Use Window for sliding-window operations, Apply for per-element transformations, Merge for combining two streams, and Reduce for combining many streams with custom logic.
Code Reference
Source Location
- Repository: Tributary
- File: tributary/streaming/utils.py
Signature
def Window(node, size=-1, full_only=False):
...
def Apply(node, func, func_kwargs=None):
...
def Delay(node, delay=1):
...
def Merge(node1, node2):
...
def ListMerge(node1, node2):
...
def DictMerge(node1, node2):
...
def FixedMap(node, count, mapper=None):
...
def Reduce(*nodes, reducer=None, inject_node=False):
...
def Unroll(node):
...
def UnrollDataFrame(node, json=False, wrap=False):
...
def Debounce(node):
...
def Throttle(node, interval=1, now=None):
...
def Subprocess(node, command, json=False, std_err=False, one_off=False, node_to_command=False):
...
Import
from tributary.streaming import (
Window, Apply, Delay, Merge, ListMerge, DictMerge,
FixedMap, Reduce, Unroll, UnrollDataFrame,
Debounce, Throttle, Subprocess
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| node | Node | Yes | Upstream streaming node |
| size | int | No (Window) | Window size; -1 means unbounded |
| full_only | bool | No (Window) | Only emit when window is full |
| func | callable | Yes (Apply) | Function to apply to each value |
| delay | float | Yes (Delay) | Delay time in seconds |
| reducer | callable | No (Reduce) | Custom reducer function |
| interval | float | Yes (Throttle) | Throttle interval in seconds |
| command | str | Yes (Subprocess) | Shell command to execute |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Node | A new downstream Node that transforms the input stream |
Usage Examples
Window + Apply
import tributary.streaming as ts
# Collect windows of 5 values and compute their mean
source = ts.Random(count=20, interval=0.1)
windowed = Window(source, size=5, full_only=True)
averaged = Apply(windowed, func=lambda vals: sum(vals) / len(vals))
out = ts.Print(averaged)
ts.run(out)
Merge Two Streams
import tributary.streaming as ts
# Merge two constant streams
s1 = Const(value=1, count=5, interval=0.5)
s2 = Const(value=2, count=5, interval=0.5)
merged = Merge(s1, s2)
out = ts.Print(merged)
ts.run(out)
# Output: (1, 2), (1, 2), ...
Reduce with Custom Reducer
import tributary.streaming as ts
# Reduce 3 streams into a sum
s1 = Const(value=10, count=3)
s2 = Const(value=20, count=3)
s3 = Const(value=30, count=3)
reduced = Reduce(s1, s2, s3, reducer=lambda *vals: sum(vals))
out = ts.Print(reduced)
ts.run(out)
# Output: 60, 60, 60
Debounce
import tributary.streaming as ts
# Only emit values that differ from the previous one
source = Curve(value=[1, 1, 2, 2, 3, 3, 3])
debounced = Debounce(source)
out = ts.Print(debounced)
ts.run(out)
# Output: 1, 2, 3
Related Pages
Implements Principle
Requires Environment
- Environment:1kbgz_Tributary_Python_Asyncio_Runtime
- Environment:1kbgz_Tributary_Streaming_IO_Dependencies