Skip to main content

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

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 obs dict → Server calls policy.infer(obs) → Returns action dict
  • Health: GET /healthz returns 200 OK

Dependencies

  • websockets>=11.0
  • msgpack>=1.0.5
  • numpy>=1.22.4,<2.0.0

License

MIT

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

policy_websocket-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

policy_websocket-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

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

Hashes for policy_websocket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9186c50610324bd92ebef07e54384e3ea238e98a2da95034d81bd9755bf8afe9
MD5 6d2691310c06f678e0ccb28b64a5af12
BLAKE2b-256 586306d5171b0b3f27013e56af56ba1234dcc400395675fc729cfff2c9bfd27a

See more details on using hashes here.

File details

Details for the file policy_websocket-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for policy_websocket-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5aef3688066fd090ce9b59ff7650655a9eb44a3315d8e21e2a2f9083585c6a71
MD5 ca5b87584adba2ab58dc51f5143c6efd
BLAKE2b-256 7f56cfff68de98c44f8a10069789a221446c2f92229975ae4d63316e0ad85611

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