Foxglove Studio WebSocket server
Project description
Foxglove Studio WebSocket server
This package provides a server implementation of the Foxglove Studio WebSocket protocol, enabling Foxglove Studio to ingest arbitrary “live” streamed data.
The protocol is encoding-agnostic, i.e. it can support Protobuf messages, ROS 1 or 2 messages, etc. (as long as the desired encoding is supported by both client and server).
Installation
$ pip install foxglove-websocket
Example server
The following script provides a simple example server which publishes messages on a single topic called example_msg
, using JSON to encode message data and JSON Schema to describe the message layout.
To get started with the example server:
- Copy the script below into a file named
example.py
. - Run
python3 example.py
. - In a browser, open up https://studio.foxglove.dev and initiate a Foxglove WebSocket connection to
ws://localhost:8765/
.
import asyncio
import json
import time
from foxglove_websocket import run_cancellable
from foxglove_websocket.server import FoxgloveServer
async def main():
async with FoxgloveServer("0.0.0.0", 8765, "example server") as server:
chan_id = await server.add_channel(
{
"topic": "example_msg",
"encoding": "json",
"schemaName": "ExampleMsg",
"schema": json.dumps(
{
"type": "object",
"properties": {
"msg": {"type": "string"},
"count": {"type": "number"},
},
}
),
}
)
i = 0
while True:
i += 1
await asyncio.sleep(0.2)
await server.send_message(
chan_id,
time.time_ns(),
json.dumps({"msg": "Hello!", "count": i}).encode("utf8"),
)
if __name__ == "__main__":
run_cancellable(main())
Development
When developing or maintaining the foxglove-websocket package, it is recommended to use pipenv to manage development dependencies and virtualenv.
- Run
pipenv install --dev
to create a virtualenv and install development dependencies. - Run
pipenv shell
to enter the virtualenv.
Project details
Release history Release notifications | RSS feed
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
Hashes for foxglove_websocket-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b9a787c7d3e49eb3716cc2a08c6012a129c2dca9587a6c27e02152a6b068c5e |
|
MD5 | 758b26b430777e5d6626d58e05bbb306 |
|
BLAKE2b-256 | 6b858e1f2df84118a7241fc760dc2fa1903e72d43e75aa64e5ed0c95b623bb1c |