Python SDK reference
The tatolab.stream package, a section at a time. Node declarations, ports and their families, contexts, reading and writing, frames and blocks, GPU tools, graph generators, logging and the clock.
The Python SDK is the tatolab.stream package, installed from PyPI as tatolab-stream. Every node imports from it. It’s fully typed, and it imports and type-checks without the runtime, so your editor, type checker and tests work on any machine.
from tatolab.stream import Image, Input, Output, Records, nodeThe package’s own source is the definitive reference: each class and protocol documents itself in sdk/tatolab-stream/tatolab/stream/. Write a node explains each part with examples.
Declaring nodes
Section titled “Declaring nodes”@node.process
Section titled “@node.process”@node.process(execution="reactive", interval_ms=None, paced_by_real_time=False)class MyNode: ...A class the runtime runs in a process of its own, from the project’s .venv. Bare @node.process takes the defaults.
| Argument | |
|---|---|
execution |
"reactive": process runs when an input has data. "continuous": it runs every interval_ms. "manual": the node drives itself from start. |
interval_ms |
The period of a continuous node |
paced_by_real_time |
The node keeps real time whatever the stream’s clock does, as a device does |
@node.function
Section titled “@node.function”@node.functiondef Clamp(x: float, low: float = 0.0, high: float = 1.0) -> float: ...A plain function whose parameters are inputs, their defaults the values the inputs hold, and whose return is the output result; a returned dataclass gives one output per field. float, int and bool travel as one-channel Channels, and dict as Records. Time, State[R] and Stateful[Out, R] give a function the stream’s time and state that lasts until the project stops. A side-effect check refuses a body that reads the clock or randomness, uses files, sockets or threads, uses global, or reads a mutable module-level value.
@node.shader
Section titled “@node.shader”@node.shader("""float4 Tint(ImageInput image, float amount) { ... }""")def Tint(image: ImageFrame, amount: float = 0.5) -> ImageFrame: ...A Slang function, named for the node, run on the GPU once per pixel of each picture. The Python signature declares the ports: each ImageFrame parameter is an ImageInput with .pixel, .uv and .sample(uv), each float a push constant, and the output result is sized to the first picture input. See GPU effects.
@node.meta
Section titled “@node.meta”@node.meta(category="Analysis", description="What the node does, in a sentence.")Goes above any of the three, and gives the node its category and description in the node catalog.
Input(Family, delivery="newest" | "ordered", requires=(), requires_codec=(), window=None, also_takes=(), default=None, description="")delivery is "newest" or "ordered". An input with a pin type, as an Image input has, reads by its type’s default when it names none (an Image input reads the newest); any other input must name one. requires lists the Records names it needs, requires_codec the codecs a Packets input takes, and window an AudioWindowContract.
Output
Section titled “Output”Output(Family, names=None, codec=None, rate=None, dtype=None, formats=(), description="")names lists the names every record carries, codec a Packets output’s codec, rate and dtype a Channels output’s sample rate and type, formats an Image output’s texture formats. from_config("key") reads names, codec or rate from the node’s settings.
Families
Section titled “Families”| Family | A read returns |
|---|---|
Image |
ImageFrame |
Array |
ArrayFrame |
Channels |
ChannelsBlock |
Packets |
PacketsUnit |
Records |
dict |
AudioWindowContract
Section titled “AudioWindowContract”AudioWindowContract(sample_rate=48_000, channels=1, dtype="f32", window_size=480, hop=None)The audio shape a Channels input wants. The runtime resamples, mixes and frames what arrives, so every block the node reads has this shape. See Audio.
Settings
Section titled “Settings”A node’s settings are the annotation on __init__’s config parameter: a dataclass, a TypedDict or a pydantic model. Annotated[float, "A description."] describes a field in the catalog, and NumberRange bounds a number. A setting changed while the stream runs reaches configure(self, config), if the node defines it; otherwise the change is refused.
Lifecycle
Section titled “Lifecycle”| Method | Context | Called |
|---|---|---|
setup(ctx) |
full | Once, before anything flows |
start(ctx) |
full | When the stream starts; a manual node starts its own work here |
process(ctx) |
limited | Per message, or per tick of a continuous node |
on_pause(ctx), on_resume(ctx) |
limited | When the project pauses and resumes |
stop(ctx) |
full | When the stream stops |
teardown(ctx) |
full | Once, last |
Every method is optional.
Contexts
Section titled “Contexts”RuntimeContextFullAccess and RuntimeContextLimitedAccess share:
| Member | |
|---|---|
inputs, outputs |
Reading and writing ports |
time |
Stream time now, in nanoseconds |
stream_clock |
The stream’s clock, as a reading |
gpu_limited_access |
GPU work that’s safe per frame |
store |
A small key-value store kept for this node: read, write, remove |
node_id, node_name, stream_id, runtime_id |
Who the node is |
stream_project_directory |
The project’s folder, to resolve relative paths |
asset_content_path(asset, from_project=None) |
The file of a project asset, by its UUID |
report_not_ready(reason), report_ready() |
Say the node can’t work yet, such as a setting left unset, and when it can |
is_paused |
Whether the project is paused |
The full context adds gpu_full_access, for allocating and compiling, and open_module_host_table, which a module’s native code takes over the node’s ports through.
Reading and writing
Section titled “Reading and writing”| Call | |
|---|---|
ctx.inputs.read(port) |
The next message, or None. A newest input drains to the latest. |
ctx.inputs.read_with_timestamp(port) |
(payload, timestamp_ns), or (None, None) |
ctx.inputs.read_message(port) |
The next Message, with its payload, timestamp and more |
ctx.inputs.has_data(port) |
Whether a read would return something |
ctx.outputs.write(port, payload, timestamp_ns=None, starts_group=True, start_sample=None) |
Writes one message to every link on the port. Without timestamp_ns, it’s stamped with stream time now. |
ctx.outputs.write_channels_block(port, ...) |
Writes a Channels block by name |
A port is passed as the class attribute, self.video, or its name.
Frames, blocks and units
Section titled “Frames, blocks and units”ImageFrame:width,height,format,colour,timestamp_ns,surface_id. It speaks DLPack (torch.from_dlpack(frame)),with frame.cpu() as pixels:gives a numpy array on the CPU, andframe.writable()opens it to change in place.ImageFrameToWrite.of_texture(texture, colour)writes a texture of your own.ArrayFrame: named arrays or tensors, each on the CPU or the GPU.ChannelsBlock:sample_rate,channel_count,samples_per_channel,dtype,timestamp_ns,start_sample;numpy.from_dlpack(block)reads it as a[channel][sample]array.PacketsUnit:payload,codec,starts_group,pts.
A read lasts only for the process call it was made in; copy what you keep.
ComputeKernel, GraphicsKernel, RayTracingKernel |
Slang kernels a process node compiles in setup and dispatches per frame. See GPU effects. |
ModelInputTensorKernel |
Turns a picture into a model’s input tensor in one pass. See Use your model. |
NodeOutputTextureRing |
A ring of textures a node writes its pictures into |
GpuContextFullAccess, GpuContextLimitedAccess |
The GPU, as ctx.gpu_full_access and ctx.gpu_limited_access |
Graph generators
Section titled “Graph generators”from tatolab.camera import CameraSourcefrom tatolab.stream import StreamBuilder, graph_generator
@graph_generatordef cameras(stream_builder: StreamBuilder) -> None: for index in range(4): stream_builder.add(CameraSource, name=f"camera-{index}", config={"device_id": f"/dev/video{index * 2}"})A function that builds nodes and links in code, which the runtime places in a stream as a fragment and refreshes when its module changes. StreamBuilder.add(NodeClass, name=, config=) returns a reference whose .output(port) and .input(port) connect links. See Graph generators.
Logging
Section titled “Logging”from tatolab.stream import log
log.info("message", key=value, other=1)log.trace, log.debug, log.info, log.warn (or log.warning) and log.error each take a message and any keyword fields. Records appear in tatolab dev and tatolab logs, tagged with the node and stream. See Logs.
The clock
Section titled “The clock”ctx.time |
Stream time now, in nanoseconds |
monotonic_now_ns() |
The machine’s monotonic clock, anywhere in a node’s process |
start_monotonic_timer(interval_ns) |
A timer that ticks on that clock without drifting |
A stream’s clock is named in its graph document: real time, scaled, or stepped. tatolab clock changes a scaled clock’s speed while it runs.