Spaces:
Sleeping
Sleeping
File size: 4,900 Bytes
51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 ec2d8f0 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 ec2d8f0 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 8aedc84 51f51c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# RobotHub TransportServer Python Client
A Python client library for real-time robotics control and video streaming via the RobotHub TransportServer platform. Built with AsyncIO for high-performance concurrent operations.
## π― Purpose
This client library provides **easy access** to the RobotHub TransportServer from Python applications:
- **Robotics Control**: Send joint commands and receive robot state updates
- **Video Streaming**: Stream and receive video feeds via WebRTC
- **Multi-Workspace**: Organize connections across isolated workspaces
- **AsyncIO Support**: Non-blocking operations for real-time robotics
## π¦ Installation
```bash
uv add transport-server-client
```
Or install from source:
```bash
uv pip install -e .
```
## π Quick Start
### Robotics Control
#### Producer (Send Commands)
```python
import asyncio
from transport_server_client import RoboticsProducer
async def main():
producer = RoboticsProducer('http://localhost:8000')
# Create room and connect
room_id = await producer.create_room()
await producer.connect(room_id)
# Send joint commands
await producer.send_joint_update([
{'name': 'shoulder', 'value': 45.0},
{'name': 'elbow', 'value': -20.0}
])
# Send complete state
await producer.send_state_sync({
'shoulder': 60.0,
'elbow': -30.0,
'wrist': 15.0
})
await producer.disconnect()
asyncio.run(main())
```
#### Consumer (Receive Commands)
```python
import asyncio
from transport_server_client import RoboticsConsumer
async def main():
consumer = RoboticsConsumer('http://localhost:8000')
await consumer.connect('room-id')
# Handle joint updates
def on_joint_update(joints):
print('π€ Robot moving:', joints)
# Execute on your robot hardware
def on_state_sync(state):
print('π Robot state:', state)
consumer.on_joint_update(on_joint_update)
consumer.on_state_sync(on_state_sync)
# Keep running
await asyncio.sleep(60)
await consumer.disconnect()
asyncio.run(main())
```
### Video Streaming
```python
import asyncio
from transport_server_client.video import VideoProducer, VideoConsumer
async def video_example():
# Producer - Stream video
producer = VideoProducer('http://localhost:8000')
room_info = await producer.create_room()
await producer.connect(room_info['workspace_id'], room_info['room_id'])
await producer.start_camera()
# Consumer - Receive video
consumer = VideoConsumer('http://localhost:8000')
await consumer.connect(room_info['workspace_id'], room_info['room_id'])
def on_frame(frame_data):
print(f'Frame received: {len(frame_data)} bytes')
consumer.on_frame_update(on_frame)
await consumer.start_receiving()
await asyncio.sleep(30) # Stream for 30 seconds
await producer.disconnect()
await consumer.disconnect()
asyncio.run(video_example())
```
## π API Reference
### RoboticsProducer
```python
# Connection
await producer.connect(workspace_id, room_id)
room_info = await producer.create_room() # Auto-generates IDs
await producer.disconnect()
# Control
await producer.send_joint_update(joints)
await producer.send_state_sync(state)
await producer.send_emergency_stop(reason)
# Room management
rooms = await producer.list_rooms(workspace_id)
await producer.delete_room(workspace_id, room_id)
```
### RoboticsConsumer
```python
# Connection
await consumer.connect(workspace_id, room_id)
state = await consumer.get_state_sync()
# Event callbacks
consumer.on_joint_update(callback)
consumer.on_state_sync(callback)
consumer.on_emergency_stop(callback)
consumer.on_error(callback)
```
### Video APIs
```python
# VideoProducer
await producer.start_camera(config)
await producer.start_screen_share()
await producer.stop_streaming()
# VideoConsumer
await consumer.start_receiving()
consumer.on_frame_update(callback)
consumer.on_stream_started(callback)
```
## β‘ Factory Functions
Quick setup helpers:
```python
from transport_server_client import create_producer_client, create_consumer_client
# Quick producer setup
producer = await create_producer_client('http://localhost:8000')
# Quick consumer setup
consumer = await create_consumer_client('room-id', 'http://localhost:8000')
```
## π§ Context Managers
Automatic cleanup with context managers:
```python
async with RoboticsProducer('http://localhost:8000') as producer:
room_id = await producer.create_room()
await producer.connect(room_id)
await producer.send_state_sync({'joint1': 45.0})
# Automatically disconnected when exiting
```
## π οΈ Development
```bash
# Install dependencies
uv sync
# Install in development mode
uv pip install -e ".[dev]"
# Run tests
pytest
```
---
**Start controlling robots with Python!** π€β¨
|