Operating Modes

There are many different ways of sending data to the Rerun Viewer depending on what you're trying to achieve and whether the Viewer is running in the same process as your code, in another process, or even as a separate web application.

In the official examples, these different modes of operation are exposed via a standardized set of flags that we'll cover below. We will also demonstrate how you can achieve the same behavior in your own code.

Before reading this document, you might want to familiarize yourself with the Rerun application model.

Operating modes operating-modes

The Rerun SDK provides multiple modes of operation: spawn, connect_grpc, serve_grpc, save, and stdout.

All of them are optional: when none of these modes are active, the client will simply buffer the logged data in memory, waiting for one of these modes to be enabled so that it can flush it.

[!WARNING] These modes will override each other and destroy any existing sinks; if you want to run multiple sinks concurrently, you'll need to use set_sinks().

spawn spawn

This is the default behavior you get when running all of our C++/Python/Rust examples, and is generally the most convenient when you're experimenting.

C++

RecordingStream::spawn spawns a new Rerun Viewer process using an executable available in your PATH, then streams all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.

Python

Call rr.spawn once at the start of your program to start a Rerun Viewer in an external process and stream all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.

Rust

RecordingStream::spawn spawns a new Rerun Viewer process using an executable available in your PATH, then streams all the data to it via gRPC. If an external Viewer was already running, spawn will connect to that one instead of spawning a new one.

connect_grpc connectgrpc

Connects to a remote Rerun Viewer and streams all the data via gRPC.

You will need to start a stand-alone Viewer first by typing rerun in your terminal.

C++

RecordingStream::connect_grpc

Python

rr.connect_grpc

Rust

RecordingStream::connect_grpc

serve_grpc servegrpc

Calling serve_grpc will start a Rerun gRPC server in your process, and stream logged data to it. This gRPC server can then be connected to from the Rerun Viewer, e.g. by running rerun --connect. The gRPC server acts as a proxy, buffering and forwarding log data to the Rerun Viewer.

You can also connect to the gRPC server from a Rerun Web Viewer. To host a Rerun Web Viewer, you can use the serve_web_viewer function.

"""Demonstrates how to log data to a gRPC server and connect the web viewer to it."""

import time

import rerun as rr

rr.init("rerun_example_serve_web_viewer")
# Start a gRPC server and use it as log sink.
server_uri = rr.serve_grpc()

# Connect the web viewer to the gRPC server and open it in the browser
rr.serve_web_viewer(connect_to=server_uri)

# Log some data to the gRPC server.
rr.log("data", rr.Boxes3D(half_sizes=[2.0, 2.0, 1.0]))

# Keep server running. If we cancel it too early, data may never arrive in the browser.
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\nShutting down server…")

C++

Python

Rust

save save

Streams all logging data into an .rrd file on disk, which can then be loaded into a stand-alone viewer.

To view the saved file, use rerun path/to/file.rrd.

Note: RRD files saved with Rerun 0.23 or later can be opened with a newer Rerun version. For more details and potential limitations, please refer to our blog post.

⚠️ At the moment, we only guarantee compatibility across adjacent minor versions (e.g. Rerun 0.24 can open RRDs from 0.23).

C++

Use RecordingStream::save.

Python

Use rr.save.

Rust

Use RecordingStream::save.

Standard Input/Output (stdout) standard-inputoutput-stdout

Streams all logging data to standard output, which can then be loaded by the Rerun Viewer by streaming it from standard input.

C++

Use RecordingStream::stdout.

Check out our dedicated example.

Python

Use rr.stdout.

Check out our dedicated example.

Rust

Use RecordingStream::stdout.

Check out our dedicated example.

set_sinks setsinks

You can use this to log to multiple sinks concurrently, such as saving to disk while streaming to the viewer.

"""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 a local viewer using the default URL
    rr.GrpcSink(),
    # 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),
)

Python

Use rr.set_sinks

Rust

Use RecordingStream::set_sinks

C++

Use RecordingStream::set_sinks

Adding the standard flags to your programs adding-the-standard-flags-to-your-programs

We provide helpers for both Python & Rust to effortlessly add and properly handle all of these flags in your programs.

Have a look at the official examples to see these helpers in action.