Registry / communication / foxglove-sdk

foxglove-sdk

JSON →
library0.25.1pypypi✓ verified 81d ago

The Foxglove Python SDK provides tools for streaming data (e.g., sensor data, robot state, custom messages) from Python applications to Foxglove Studio for visualization and debugging. It's actively maintained with regular releases, currently at version 0.21.0, targeting Python 3.10 and newer, leveraging asynchronous operations for efficient data transfer.

pip install foxglove-sdk
INSTALL
IMPORT
SIG · FOXGLOVE-SDK
F
foxglove-sdk
communicationpythonv0.25.1
Install
2.4s avg
Import
Disk
41MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.25.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 25.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 71MB
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MCAPWriter
from foxglove import MCAPWriter
from foxglove import FoxgloveClient

This quickstart demonstrates how to connect to a Foxglove WebSocket server, define a new stream with a JSON schema, and publish messages asynchronously. Ensure you have a Foxglove WebSocket server running (e.g., locally via `npx @foxglove/ws-server` if you have Node.js installed, or connect to a cloud endpoint).

import asyncio import os import time import json from foxglove_sdk import FoxgloveClient from foxglove_sdk.client import AddStreamRequest, ClientError from foxglove_sdk.base import MessageEvent async def main(): # Connect to a local Foxglove WebSocket server (e.g., `npx @foxglove/ws-server`) # or a Foxglove Cloud stream endpoint. websocket_url = os.environ.get("FOXGLOVE_WEBSOCKET_URL", "ws://localhost:8765/") print(f"Attempting to connect to Foxglove WebSocket at {websocket_url}") client = FoxgloveClient(websocket_url) try: await client.connect() print("Successfully connected to Foxglove WebSocket.") # Define a simple JSON schema for a counter stream stream_id = await client.add_stream( AddStreamRequest( topic="my_counter", encoding="json", schemaName="example.Counter", schema=json.dumps({ "type": "object", "properties": { "count": {"type": "integer"}, "timestamp": {"type": "number"} }, "required": ["count", "timestamp"] }) ) ) print(f"Stream 'my_counter' (ID: {stream_id}) added.") # Publish 10 counter messages for i in range(10): current_time_ns = time.time_ns() # Timestamp in nanoseconds message_payload = {"count": i, "timestamp": current_time_ns / 1e9} await client.send_message( MessageEvent( timestamp=current_time_ns, streamId=stream_id, payload=json.dumps(message_payload).encode("utf8") # Payload must be bytes ) ) print(f"Published message {i}: {message_payload}") await asyncio.sleep(1) # Wait for 1 second before next message except ClientError as e: print(f"Foxglove Client Error: {e}") print("Please ensure a Foxglove WebSocket server is running and accessible (e.g., `npx @foxglove/ws-server`).") except Exception as e: print(f"An unexpected error occurred: {e}") finally: if client.connected: await client.disconnect() print("Disconnected from Foxglove WebSocket.") if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
breakingThe `Publisher` class was removed and the main client class was renamed from `Client` to `FoxgloveClient` in version 0.20.0. The API was simplified for direct message sending.
fix
Replace `from foxglove_sdk.client import Client` with `from foxglove_sdk import FoxgloveClient`. Instead of `client.publisher.send()`, use `client.send_message()` directly.
affects: 0.20.0+
breakingThe term 'Channel' was renamed to 'Stream' across the entire API in version 0.18.0. This affects class names (e.g., `AddChannelRequest` to `AddStreamRequest`) and method parameters.
fix
Update all references from 'channel' to 'stream' in class names, method calls, and parameter names (e.g., `add_channel` -> `add_stream`, `channelId` -> `streamId`).
affects: 0.18.0+
gotchaThe Foxglove SDK is built on `asyncio`. All network operations are asynchronous and must be `await`ed within an `async` function. Running synchronous code or attempting to call async methods without `await` will result in `RuntimeError` or unexpected behavior.
fix
Ensure your application uses an `asyncio` event loop. Wrap the main logic in an `async def main():` function and run it with `asyncio.run(main())`. Always use `await` when calling `FoxgloveClient` methods like `connect()`, `add_stream()`, or `send_message()`.
affects: All versions
gotchaData payloads sent via `send_message` must be bytes, not raw Python dicts or strings. The schema defined during `add_stream` must precisely match the structure of the data you send.
fix
Before sending, serialize your message object (e.g., `json.dumps(my_dict).encode('utf8')` for JSON, or `my_proto_message.SerializeToString()` for Protobuf) and ensure the schema and encoding in `AddStreamRequest` match this format.
affects: All versions
Upgrade
Version history
0.25.1latest on PyPI · released Jun 2, 2026
Audit
Dependencies
pydanticrequiredData validation and settings management
websocketsrequiredAsynchronous WebSocket client implementation
httpxrequiredHTTP client for schema uploads (e.g., Protobuf)
Agent activity
42 hits · last 30 days
node
38
OpenAI (training)
1
Resources