Skip to main content

Python library implementing the Foxglove WebSocket protocol for streaming robotics data

Project description

robo-ws-bridge

A Python library implementing the Foxglove WebSocket protocol for streaming robotics data.

Installation

uv add robo-ws-bridge

Features

  • WebSocketBridgeServer: Async server for publishing robotics data over WebSocket
  • WebSocketBridgeClient: Async client for subscribing to data streams
  • Native channel streaming, time synchronization, playback control, subscriptions, and status messages
  • Extensible handlers for parameters, services, client publishing, connection graphs, and assets

Usage

Server Example

import asyncio
from robo_ws_bridge.server import Channel
from robo_ws_bridge import WebSocketBridgeServer

async def main():
    server = WebSocketBridgeServer(host="0.0.0.0", port=8765, name="my-server")

    # Define and advertise a channel
    channel = Channel(
        id=1,
        topic="/sensor/data",
        encoding="json",
        schema_name="SensorData",
        schema='{"type": "object"}',
    )

    await server.start()
    await server.advertise_channel(channel)

    # Publish messages
    while True:
        data = b'{"temperature": 22.5}'
        await server.publish_message(channel.id, data)
        await asyncio.sleep(0.1)

asyncio.run(main())

Playback control

Playback control uses our native async server implementation; it does not depend on the Foxglove SDK. Supplying the recording time range advertises the playbackControl capability; the server accepts the foxglove.sdk.v1 subprotocol by default.

from robo_ws_bridge import (
    PlaybackCommand,
    PlaybackControlRequest,
    PlaybackState,
    PlaybackStatus,
    WebSocketBridgeServer,
)

server = WebSocketBridgeServer(playback_time_range=(start_time_ns, end_time_ns))

async def control(request: PlaybackControlRequest) -> PlaybackState:
    if request.seek_time is not None:
        await recording.seek(request.seek_time)
    await recording.set_speed(request.playback_speed)
    if request.playback_command is PlaybackCommand.PLAY:
        await recording.play()
    else:
        await recording.pause()
    return PlaybackState(
        status=PlaybackStatus.PLAYING if recording.is_playing else PlaybackStatus.PAUSED,
        current_time=recording.current_time,
        playback_speed=recording.speed,
        did_seek=request.seek_time is not None,
    )

server.on_playback_control(control)

Each server endpoint has a unique session ID so reconnecting Foxglove clients discard stale visualization state. Rotate it explicitly when switching runs:

await server.clear_session()

Status IDs provide the same small lifecycle for the Problems panel:

from robo_ws_bridge import StatusLevel

await server.send_status(StatusLevel.ERROR, "Playback failed", status_id="playback")
await server.remove_status(["playback"])

Client Example

import asyncio
from robo_ws_bridge import WebSocketBridgeClient

async def main():
    client = WebSocketBridgeClient("ws://localhost:8765")

    async def handle_message(channel, timestamp, data):
        print(f"{channel['topic']}: {data}")

    async def handle_advertise(channel):
        await client.subscribe(channel["topic"])

    client.on_message(handle_message)
    client.on_advertised_channel(handle_advertise)

    await client.connect()

    # Keep running until interrupted
    try:
        while True:
            await asyncio.sleep(1)
    finally:
        await client.disconnect()

asyncio.run(main())

Protocol Reference

See the Foxglove WebSocket Protocol for protocol details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robo_ws_bridge-0.9.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robo_ws_bridge-0.9.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file robo_ws_bridge-0.9.0.tar.gz.

File metadata

  • Download URL: robo_ws_bridge-0.9.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for robo_ws_bridge-0.9.0.tar.gz
Algorithm Hash digest
SHA256 7f1da3950aa338e45580c4115606e387d4707b0899e870209449ac3eea1e5219
MD5 d0e929304013290f1866a1e210d41f4a
BLAKE2b-256 699be500dd819fd4bd2e4ba608984eba62c9b7189a12e07de1b31efbc24e2569

See more details on using hashes here.

File details

Details for the file robo_ws_bridge-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: robo_ws_bridge-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for robo_ws_bridge-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3763acbd6d238e758c1373256eea01585d6d894494bd096db058992b1187d09d
MD5 fce177257e2ea8efcb0b674c60e6576d
BLAKE2b-256 caa7eec1ee2ecc221b4ccae24a1695d6748b69a4b0408ba9c0272ae3cafc43ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page