Metadata-Version: 2.5
Name: openhorizon-studio
Version: 0.1.2
Summary: OpenHorizon Studio's client: a team's robots and their takes, read and marked through OpenHorizon's relay with an API key.
Project-URL: Homepage, https://openhorizon.so
Author: OpenHorizon Labs
License-Expression: LicenseRef-OpenHorizon-Personal-Use-1.0
License-File: LICENSE
Keywords: lerobot,openhorizon,robot-learning,robotics,teleoperation
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Provides-Extra: session
Requires-Dist: websockets>=15; extra == 'session'
Description-Content-Type: text/markdown

# openhorizon-studio

OpenHorizon Studio's client for Python, and its command line, `oh-studio`: your team's robots and their takes,
read and marked through OpenHorizon's relay with an API key.

## Install

It runs on these computers, with Python 3.10 to 3.14:

| Computer | What it needs |
| --- | --- |
| A Mac with Apple Silicon (M1 or later) | macOS 11 or newer |
| Linux on 64-bit ARM or x86_64: a Jetson, a Thor, a robot's own computer, a PC, a server | glibc 2.28 or newer: Ubuntu 20.04, Debian 10 and later |
| Windows 10 or 11 | WSL 2 with Ubuntu, then the Linux steps inside it |

There is nothing to install on an Intel Mac, or on Windows outside WSL: pip says "no matching distribution".

### With uv (recommended)

uv installs the `oh-studio` command in a folder of its own, and `--python 3.12` makes it use Python 3.12,
which it downloads when the computer has none. macOS's own `python3` is 3.9 and Ubuntu 20.04's is 3.8, both too
old, and the newest Python, 3.15, is not built for yet.

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh     # uv itself; then open a new terminal
uv tool install --python 3.12 openhorizon-studio
oh-studio --version
```

If the terminal says `oh-studio: command not found`, run `uv tool update-shell` and open a new terminal.

Recording a take on a practice robot (below) needs the `session` extra, which adds `websockets`:

```bash
uv tool install --force --python 3.12 'openhorizon-studio[session]'
```

Later, `uv tool upgrade openhorizon-studio` updates it and `uv tool uninstall openhorizon-studio` removes it.

### Without uv

With Python 3.10 to 3.14 (`python3 --version`), make a virtual environment of its own. Ubuntu 23.04 and later
refuse `pip install` into the system's own Python ("externally-managed-environment"):

```bash
python3 -m venv ~/oh-studio
~/oh-studio/bin/pip install openhorizon-studio          # or 'openhorizon-studio[session]'
~/oh-studio/bin/oh-studio --version
```

On Ubuntu, `python3 -m venv` needs `sudo apt install python3-venv` first.

In your own project, `pip install openhorizon-studio` into that project's virtual environment. The library needs
nothing but the standard library.

### On Windows

1. In PowerShell as administrator: `wsl --install -d Ubuntu-24.04`, then restart the computer.
2. Open Ubuntu from the Start menu and make its user.
3. In Ubuntu, follow "With uv" above.

`oh-studio` then runs in the Ubuntu window, not in PowerShell. Its key file is kept in Ubuntu's home folder.

## A key

A team admin makes an API key on Account, API keys. It is shown once. Keep it for this user:

```bash
oh-studio login            # asks for the key, checks it with the relay, keeps it 0600
```

Or set `OH_STUDIO_KEY`, or pass `key=` to `Studio`. A key goes to `https://relay.openhorizon.so` (or
`OH_STUDIO_RELAY`) over https only, and is never printed, logged or put in an error.

A proxy: `HTTPS_PROXY` for the relay (else `https_proxy`), `HTTP_PROXY` for an http address elsewhere, and
`NO_PROXY` to leave hosts out (`*`, a host and its subdomains, `.domain`, an address or a range, each with an
optional port). The proxy sees only where to connect, never the key. This computer (localhost, 127.0.0.1, [::1]) is
never asked through one, whatever is set, and the system's own proxy settings are not read. Only an `http://` proxy
is used; any other is refused in words, so a program never goes straight where its network asked for a proxy.

## The command line

```bash
oh-studio robots                                   # the robots your team reaches
oh-studio takes g1-01 --to-check                   # takes nobody has marked yet, newest first
oh-studio take g1-01 e1700000000000-pick_cube      # one take (--json: whole, ticks too)
oh-studio good g1-01 e1700000000000-pick_cube
oh-studio wrong g1-01 e1700000000001-pick_cube dropped_object
oh-studio frame g1-01 e1700000000000-pick_cube cam_high 0 -o picture.jpg
oh-studio scorecard g1-01
oh-studio stop g1-01                               # press STOP; it never clears it
oh-studio session start --robot http://localhost:9090 --task "pick cube" --seconds 5   # a practice take
oh-studio takes http://localhost:9090              # a practice robot on this computer: no relay, no key
```

A robot is named by its id or its name, as `oh-studio robots` lists them. Every command takes `--json`. A failure
exits 1 with its cause and what to do on stderr (with `--json`, as an object with `error`, `fix`, `status` and
`code`).

## The library

```python
from openhorizon_studio import Studio, StudioError, TAKE_REASONS, checked

studio = Studio()  # the key from OH_STUDIO_KEY or `oh-studio login`
robot = studio.robot("g1-01")
for take in robot.takes():
    if not checked(take):
        print(take["id"], take.get("skill"))

robot.good("e1700000000000-pick_cube")
robot.wrong("e1700000000001-pick_cube", "dropped_object")  # one of TAKE_REASONS

try:
    robot.take("e1-nothing")
except StudioError as e:
    print(e.status, e.code, e.cause, e.fix)
```

Answers are the robot's own, as its API documents them, never reshaped.
`robot.frame(take, camera, tick)` gives the JPEG's bytes; a picture cut short on the way is an error, never a picture.
`Robot.local("http://localhost:9090")` asks a robot's runtime straight, with no relay and no key.

## A take from a program

Asked straight with no key, a program records a take only on a practice robot on this computer (`openhorizon serve
--g1 --loopback`), never a real one. Before anything is sent, the address must be localhost,
127.0.0.1 or [::1], and the robot's first message must say it is a practice robot that records takes; a robot that
does not say so is sent nothing.

Through the relay, with a team's operator key, a program records a take that it steers, on a robot started with
`--relay-programs` and `--execute` (`--relay-drive` lets people steer, never a program):
`Studio().robot("g1-01").session("pick cube")`. The relay and the robot decide: a
take that would not steer is refused, and one that steered nothing is not kept. For about the first second the
relay holds steering while it measures the delay (`take.held` says why), and every command passes the same
round-trip gate as the page's. A key revoked, a plan ended or a robot removed mid-take closes the socket, and the
robot ends the take.

```python
from openhorizon_studio import Robot

robot = Robot.local("http://localhost:9090")
with robot.session("pick cube") as take:
    take.walk(2.0, vx=0.5)  # 20 commands a second for 2 s, on this thread, then a zero
    take.drive(wz=-0.3)  # ONE command: the robot zeroes it 0.3 s later unless it is sent again
print(take.id)  # the kept take; leaving the block with an error keeps it as abandoned
```

Each axis runs from -1 to 1, and the axes are the robot's own (`take.axes`). Nothing in the client sends from a
thread or a timer, so a program that hangs goes quiet and the robot stops by itself. `take.stop()` presses STOP; a
STOP not confirmed also closes the take's socket, so the robot ends the take. `oh-studio session start` records a
take steering nothing, on a practice robot here only; Ctrl-C ends it early, kept as abandoned.

## STOP

`oh-studio stop ROBOT` and `robot.stop()` press STOP and return the robot's own answer. Neither clears it: that is
a person's who has looked, on the page.

A program's STOP is never anyone's only stop. A person's STOP on the page goes straight to the robot. A key's is
checked by the relay's key service first; the relay holds its answer a while after the key last listed
robots, and once that has lapsed, a key service out of reach (503) or too many keys being checked (429) means the
STOP is refused. A STOP that was refused or not answered raises `StudioError` ("STOP not confirmed"), and one that
could not be sent ("STOP was not sent": no key, a robot name not found); its `fix` says to press STOP on the page
and keep the robot's own stop at hand. That is a G1's handheld remote, the program that drives an OpenArm, or the
person beside an Asimov.

## What a key cannot do

Clear STOP, open a headset's link or make keys. Those are a person's, signed in on the page. A key lists robots,
reads takes, their pictures and the scorecard, marks takes, and presses STOP. An operator key may also steer a take
of its own through the relay, on a robot started with `--relay-programs` and `--execute` (above).

## Licence

Source-available, not open source: the OpenHorizon Personal Use License 1.0 (`LICENSE` in this folder). An individual may use it for their own personal purposes. A company, a school or university, a research lab or any other organisation needs a written licence from OpenHorizon Labs; a team on a paid OpenHorizon Studio plan has one for its own programs and the robots paired to it. See `COMMERCIAL-LICENSE.md` at the repository's root.
