sim2bot — Python client for the Sim2Bot simulator
Control a robot in Sim2Bot from Python, the same way you would talk to a real one: send joint or Cartesian targets, read telemetry, open and close a gripper, subscribe to camera feeds.
from sim2bot import Robot
with Robot(auto_bridge=True, wait_for_sim=True) as robot:
arm = robot.describe()[0]
robot.move_to(arm.home)
robot.wait_until_reached(arm.home)
print(robot.state().q)
How the pieces fit
Sim2Bot runs the physics (MuJoCo, compiled to WebAssembly) in your browser. This package talks to that tab through a small local relay — the bridge — that ships inside the package itself:
your Python script ──► sim2bot bridge (localhost) ──► Sim2Bot tab in your browser
commands relay only MuJoCo physics
telemetry ◄── ◄── cameras, sensors
The bridge forwards messages and holds no robot state of its own. Nothing about your scene leaves your machine.
Install
pip install sim2bot # control + telemetry
pip install "sim2bot[cv2]" # + camera frames decoded to numpy images
Python 3.9 or newer.
First run
- Run your script.
auto_bridge=Truestarts the local bridge if it is not already running, andwait_for_sim=Truewaits for the browser. - Open app.sim2bot.com, load a robot, and click Tools → Bridge → Connect.
from sim2bot import Robot
with Robot(auto_bridge=True, wait_for_sim=True) as robot:
for info in robot.describe():
print(f"[{info.index}] {info.name} id={info.id} dof={info.dof}")
wait_for_sim=True blocks until a simulator announces at least one robot; pass
wait_for_sim_timeout=30 for a finite wait.
What you can do
from sim2bot import Robot
with Robot() as robot: # ws://localhost:8765/ws
info = robot.describe() # dof, home, limits, gripper, cameras, ...
print(info[0].index, info[0].id, info[0].name, info[0].dof)
robot.move_to(info[0].home) # joint position target
robot.set_velocity([0.1] * info[0].dof) # joint velocity target
robot.move_to_pose([0.45, 0.0, 0.35]) # Cartesian target, solved by browser IK
robot.move_trajectory([(0.0, q0), (1.5, q1)]) # timed joint trajectory
robot.stop()
state = robot.state()
print(state.q, state.qd, state.qdd, state.qddd) # position ... jerk
print(state.tcp, state.tcp_orientation) # TCP position + quaternion
print(state.tcp_linear_velocity, state.tcp_angular_velocity)
if info[0].has_gripper:
robot.gripper(1.0) # 0.0 closed .. 1.0 open
robot.base_velocity(vx=0.4, omega=0.35) # mobile / aerial bases
robot.marker("goal", "sphere", position=[0.45, 0, 0.35], scale=0.06)
for device in robot.room_devices(): # doors and windows in the scene
if device.motion == "actuated":
robot.set_room_opening(device.id, 1.0)
for cam in robot.cameras():
print(cam["id"], cam["label"])
with robot.camera("model:0", fps=30) as feed: # codec="raw" for lowest latency
frame = feed.read(timeout=2.0)
image = frame.image() # numpy BGR — needs the [cv2] extra
Telemetry and camera reads are latest-value, drop-don't-queue: they return the present, never a backlog.
Robot discovery gives you both index and id. Address commands by index
(robot.move_to(q, robot=info.index)); use id to recognise the same scene
robot across the app and your script.
Camera parameters you leave unset (fps, width, height, quality, codec)
inherit that camera's setting in the app, so your script overrides the GUI only
where it says so.
Runnable versions of all of this are in examples/.
Command line
sim2bot bridge # run the local bridge explicitly
sim2bot doctor # check bridge, browser, TCP/UDP, video, OpenCV
sim2bot list-robots # wait for the simulator and print index / id / name
sim2bot open # open the app (override with SIM2BOT_APP_URL)
Transport
WebSocket by default. For a lower-latency control path with no TCP head-of-line blocking:
Robot(transport="udp") # control + telemetry over UDP (8771)
Camera frames always use the binary video WebSocket, because one frame is far larger than a datagram. On localhost the two transports perform about the same; UDP's advantage shows over a real network.
More than one simulator, and other machines
Use a room to pair one script with one browser tab:
Robot(room="bench-a") # or SIM2BOT_BRIDGE_ROOM=bench-a
Without a room, commands go to the most recently connected tab.
Scripts on the same machine need no credentials. To drive the bridge from another machine on the LAN, bind it to a LAN interface with a token — the bridge refuses non-loopback clients otherwise:
SIM2BOT_BRIDGE_TOKEN=choose-a-secret sim2bot bridge --host 0.0.0.0
Robot(url="ws://192.168.1.42:8765/ws", api_key="choose-a-secret")
Protocol
The wire format is documented in docs/protocol.md, and
fixtures/v1/ holds one example message per type. Those
fixtures are the contract: the tests here check this SDK against them, and the
Sim2Bot app checks its own implementation against the same files. If you are
writing a client in another language, implement against the fixtures.
Versions
The package version is the version to quote in a bug report. Each release says
which Sim2Bot app versions it is verified against in
CHANGELOG.md.
Contributing
Issues and pull requests are welcome — see CONTRIBUTING.md.
This repository holds the Python client, the relay and the protocol fixtures.
The Sim2Bot application itself is closed source, so bugs in the simulator, the
GUI or rendering are reported here but fixed there.
Licence
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sim2bot-0.1.0.tar.gz.
File metadata
- Download URL: sim2bot-0.1.0.tar.gz
- Upload date:
- Size: 39.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0821522d4e60937b9b6e3f3c20f6477c593a0f3639acc09da690453ed3db501
|
|
| MD5 |
6de46f62bb52ed3af9f0447dcf13c2b1
|
|
| BLAKE2b-256 |
d8368c4e21dc112aadd4ba4b50f8357032c52e8f33de61234fad30036422057c
|
Provenance
The following attestation bundles were made for sim2bot-0.1.0.tar.gz:
Publisher:
publish.yml on Source-Robotics/sim2bot-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sim2bot-0.1.0.tar.gz -
Subject digest:
c0821522d4e60937b9b6e3f3c20f6477c593a0f3639acc09da690453ed3db501 - Sigstore transparency entry: 2860378641
- Sigstore integration time:
-
Permalink:
Source-Robotics/sim2bot-python@4fa9de85b7e868d7a7675857e0c37ac87dbbedbe -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Source-Robotics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4fa9de85b7e868d7a7675857e0c37ac87dbbedbe -
Trigger Event:
release
-
Statement type:
File details
Details for the file sim2bot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sim2bot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f63bf5a21a057b18d7a39775ae28808ef95b0e45c38c906b83840334fbe6087
|
|
| MD5 |
5e638c91a61442ab3974360744223bc4
|
|
| BLAKE2b-256 |
743d2c69686261a84a912d1defe9af8a4a8bb0bfcd88e7552592dce2d8ee1e67
|
Provenance
The following attestation bundles were made for sim2bot-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Source-Robotics/sim2bot-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sim2bot-0.1.0-py3-none-any.whl -
Subject digest:
7f63bf5a21a057b18d7a39775ae28808ef95b0e45c38c906b83840334fbe6087 - Sigstore transparency entry: 2860378696
- Sigstore integration time:
-
Permalink:
Source-Robotics/sim2bot-python@4fa9de85b7e868d7a7675857e0c37ac87dbbedbe -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Source-Robotics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4fa9de85b7e868d7a7675857e0c37ac87dbbedbe -
Trigger Event:
release
-
Statement type: