Skip to content

Commit 14e7ea7

Browse files
committed
add python example
1 parent dcf792c commit 14e7ea7

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: External data-loader example
3+
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/external_data_loader/main.py?speculative-link
4+
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/external_data_loader/src/main.rs?speculative-link
5+
cpp: https://github.com/rerun-io/rerun/tree/latest/examples/cpp/external_data_loader/main.cpp?speculative-link
6+
thumbnail: https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/480w.png
7+
---
8+
9+
<picture>
10+
<img src="https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/full.png" alt="">
11+
<source media="(max-width: 480px)" srcset="https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/480w.png">
12+
<source media="(max-width: 768px)" srcset="https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/768w.png">
13+
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/1024w.png">
14+
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/external_data_loader_rust/45b1312910063086708d2db52dc3eb619e741d8c/1200w.png">
15+
</picture>
16+
17+
This is an example executable data-loader plugin for the Rerun Viewer.
18+
19+
It will log Python source code files as markdown documents.
20+
To try it out, copy it in your $PATH as `rerun-loader-python-file`, then open a Python source file with Rerun (`rerun file.py`).
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
"""Example of an executable data-loader plugin for the Rerun Viewer."""
3+
from __future__ import annotations
4+
5+
import argparse
6+
import os
7+
8+
import rerun as rr # pip install rerun-sdk
9+
10+
# The Rerun Viewer will always pass these two pieces of information:
11+
# 1. The path to be loaded, as a positional arg.
12+
# 2. A shared recording ID, via the `--recording-id` flag.
13+
#
14+
# It is up to you whether you make use of that shared recording ID or not.
15+
# If you use it, the data will end up in the same recording as all other plugins interested in
16+
# that file, otherwise you can just create a dedicated recording for it. Or both.
17+
parser = argparse.ArgumentParser(
18+
description="""
19+
This is an example executable data-loader plugin for the Rerun Viewer.
20+
21+
It will log Python source code files as markdown documents.
22+
To try it out, copy it in your $PATH as `rerun-loader-python-file`, then open a Python source file with Rerun (`rerun file.py`).
23+
"""
24+
)
25+
parser.add_argument("filepath", type=str)
26+
parser.add_argument("--recording-id", type=str)
27+
args = parser.parse_args()
28+
29+
30+
def main() -> None:
31+
is_file = os.path.isfile(args.filepath)
32+
is_rust_file = os.path.splitext(args.filepath)[1].lower() == ".py"
33+
34+
# We're not interested: just exit silently.
35+
# Don't return an error, as that would show up to the end user in the Rerun Viewer!
36+
if not (is_file and is_rust_file):
37+
return
38+
39+
rr.init("rerun_example_external_loader", recording_id=args.recording_id)
40+
# The most important part of this: log to standard output so the Rerun Viewer can ingest it!
41+
rr.stdout()
42+
43+
with open(args.filepath) as file:
44+
body = file.read()
45+
text = f"""## Some Python code\n```python\n{body}\n```\n"""
46+
rr.log(args.filepath, rr.TextDocument(text, media_type=rr.MediaType.MARKDOWN), timeless=True)
47+
48+
49+
if __name__ == "__main__":
50+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rerun-sdk

0 commit comments

Comments
 (0)