WebSocket-based policy client/server for robot learning
Project description
policy-websocket
WebSocket-based policy client/server for robot learning. Provides a minimal, dependency-light interface for running policies remotely over WebSocket.
Compatible with openpi, RoboCasa, and other robot environments.
Installation
pip install policy-websocket
For development from source:
git clone https://github.com/YufengJin/policy_websocket.git && cd policy_websocket
pip install -e .
Quick Start
# Terminal 1: Start single-step server
python examples/policy_server.py --port 8000
# Terminal 2: Run client
python examples/policy_client.py --host localhost --port 8000 --steps 10
Or run the Action Chunk server (policy_server_ac.py) and integration test (examples/run_example_test.py).
Components
| Class | Description |
|---|---|
BasePolicy |
Abstract base: infer(obs) -> dict, reset() |
WebsocketClientPolicy |
Client that sends obs to a remote server, returns actions |
WebsocketPolicyServer |
Server that wraps any BasePolicy and serves over WebSocket |
ActionChunkBroker |
Wraps chunk-returning policies to yield one action per step |
Documentation
- Policy Server Setup Guide — Wrap PyTorch models, Action Chunk, RoboCasa integration
- Module Reference — Component overview, data flow, API details
- Examples — Single-step server, Action Chunk server, client, integration test
- Stress Test — 3-view RGB-D 720p throughput, FPS and loss measurement
Usage
Server (wrap your policy)
from policy_websocket import BasePolicy, WebsocketPolicyServer
import numpy as np
class MyPolicy(BasePolicy):
def infer(self, obs):
return {"actions": np.zeros(7)}
server = WebsocketPolicyServer(policy=MyPolicy(), host="0.0.0.0", port=8000)
server.serve_forever()
Client
from policy_websocket import WebsocketClientPolicy
policy = WebsocketClientPolicy(host="localhost", port=8000)
action_dict = policy.infer(obs_dict)
action = action_dict["actions"]
ActionChunkBroker (predict N, execute M)
from policy_websocket import BasePolicy, WebsocketPolicyServer, ActionChunkBroker
# Inner policy returns (16, action_dim) chunks
chunk_policy = MyChunkPolicy()
broker = ActionChunkBroker(policy=chunk_policy, action_horizon=8)
server = WebsocketPolicyServer(policy=broker, port=8000)
Protocol
- Transport: WebSocket
- Serialization: msgpack with NumPy array support
- Flow: Client sends
obsdict → Server callspolicy.infer(obs)→ Returns action dict - Health: GET
/healthzreturns 200 OK
Dependencies
websockets>=11.0msgpack>=1.0.5numpy>=1.22.4,<2.0.0
License
MIT
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
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 policy_websocket-0.1.0.tar.gz.
File metadata
- Download URL: policy_websocket-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9186c50610324bd92ebef07e54384e3ea238e98a2da95034d81bd9755bf8afe9
|
|
| MD5 |
6d2691310c06f678e0ccb28b64a5af12
|
|
| BLAKE2b-256 |
586306d5171b0b3f27013e56af56ba1234dcc400395675fc729cfff2c9bfd27a
|
File details
Details for the file policy_websocket-0.1.0-py3-none-any.whl.
File metadata
- Download URL: policy_websocket-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aef3688066fd090ce9b59ff7650655a9eb44a3315d8e21e2a2f9083585c6a71
|
|
| MD5 |
ca5b87584adba2ab58dc51f5143c6efd
|
|
| BLAKE2b-256 |
7f56cfff68de98c44f8a10069789a221446c2f92229975ae4d63316e0ad85611
|