Skip to content
esc
Start typing to search the docs
Navigate Open

Sinks

Sinks control where your Rerun data goes. They are the output destinations for your logged data.

Data can go to a live Viewer, a file on disk, memory, or several destinations at once.

Available sink types

Rerun provides these built-in sink types:

GrpcSink

Streams data to a Rerun Viewer over gRPC. This is the most common sink for live visualization.

"""Create and set a GRPC sink."""

import rerun as rr

rr.init("rerun_example_grpc_sink")

# The default URL is `rerun+http://127.0.0.1:9876/proxy`
# This can be used to connect to a viewer on a different machine
rr.set_sinks(rr.GrpcSink("rerun+http://127.0.0.1:9876/proxy"))

FileSink

Writes data to .rrd files on disk.

"""Create and set a file sink."""

import rerun as rr

rr.init("rerun_example_file_sink")

rr.set_sinks(rr.FileSink("recording.rrd"))

Multiple sinks (Tee pattern)

Pass several sinks to set_sinks to send data to all of them at once. For example, a GrpcSink and a FileSink let you view data live and save it to disk in the same run:

"""Log some data to a file and a Viewer at the same time."""

import numpy as np

import rerun as rr

# Initialize the SDK and give our recording a unique name
rr.init("rerun_example_set_sinks")

rr.set_sinks(
    # Connect to an existing local Viewer or gRPC server.
    rr.GrpcSink(),
    # To host a gRPC server instead, replace the sink above with:
    # rr.GrpcServerSink(),
    # Write data to a `data.rrd` file in the current directory
    rr.FileSink("data.rrd"),
)

# Create some data
SIZE = 10

pos_grid = np.meshgrid(*[np.linspace(-10, 10, SIZE)] * 3)
positions = np.vstack([d.reshape(-1) for d in pos_grid]).T

col_grid = np.meshgrid(*[np.linspace(0, 255, SIZE)] * 3)
colors = np.vstack([c.reshape(-1) for c in col_grid]).astype(np.uint8).T

# Log the data
rr.log(
    # name under which this entity is logged (known as "entity path")
    "my_points",
    # log data as a 3D point cloud archetype
    rr.Points3D(positions, colors=colors, radii=0.5),
)

You can also stream to several Viewers or save to several files.

Calling rr.spawn(), rr.connect_grpc(), or rr.save() replaces all existing sinks. To start a Viewer without touching your sinks, call rr.spawn(connect=False): it only starts the Viewer process, and your GrpcSink can then connect to it.

rr.init("rerun_example_spawn_and_save")
rr.spawn(connect=False)  # Start a Viewer, but leave the sinks alone.
rr.set_sinks(rr.GrpcSink(), rr.FileSink("data.rrd"))

Connection lifecycle

These rules apply to the gRPC sink (connect_grpc, spawn, and GrpcSink):

  • Connecting: the SDK connects in the background and retries forever, with a backoff of up to one second between attempts. You can start logging before the Viewer is running: data is queued until the connection is up. If the queue fills up before a connection is made, log calls block.
  • Flushing: flush waits for queued data to be sent. If the SDK has not connected yet, flush gives up after about 5 seconds. In Python, use rec.flush(timeout_sec=…) on a RecordingStream (for example the one returned by rr.get_global_data_recording()) to limit how long it waits; it raises an error on timeout.
  • Shutdown: at shutdown, the SDK waits at most about 5 seconds for a final connection attempt. If it still cannot connect, the queued data is dropped and an error is logged.
  • Disconnects: if an established connection fails (for example because the Viewer was closed), the SDK does not reconnect. Data logged after that is lost for this sink. If you need the data, also log to a FileSink.
  • Status: only the Rust SDK exposes the connection state, through the experimental GrpcSink::status.

If the Viewer cannot start because its port is taken, run rerun --port auto (or rerun --new) to start a new Viewer on a free port, and connect to the port it prints.

See also