phystack-hub-client 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phystack/hub_client/__init__.py +90 -0
- phystack/hub_client/client.py +701 -0
- phystack/hub_client/instances/__init__.py +11 -0
- phystack/hub_client/instances/base_instance.py +225 -0
- phystack/hub_client/instances/edge_instance.py +212 -0
- phystack/hub_client/instances/peripheral_instance.py +186 -0
- phystack/hub_client/services/__init__.py +5 -0
- phystack/hub_client/services/phyhub_connection.py +272 -0
- phystack/hub_client/services/webrtc/__init__.py +23 -0
- phystack/hub_client/services/webrtc/data_channel.py +527 -0
- phystack/hub_client/services/webrtc/media_stream.py +571 -0
- phystack/hub_client/twin_messaging.py +287 -0
- phystack/hub_client/twin_registry.py +158 -0
- phystack/hub_client/types/__init__.py +15 -0
- phystack/hub_client/types/twin_types.py +136 -0
- phystack_hub_client-0.2.0.dist-info/METADATA +174 -0
- phystack_hub_client-0.2.0.dist-info/RECORD +18 -0
- phystack_hub_client-0.2.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phystack-hub-client
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python client for PhyHub - events, actions, DataChannel, and MediaStream
|
|
5
|
+
Project-URL: Homepage, https://github.com/phystack/phystack-pypi
|
|
6
|
+
Project-URL: Documentation, https://docs.phystack.com
|
|
7
|
+
Project-URL: Repository, https://github.com/phystack/phystack-pypi
|
|
8
|
+
Author-email: Phystack <dev@phystack.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
19
|
+
Requires-Dist: aiortc>=1.6.0
|
|
20
|
+
Requires-Dist: numpy>=1.24.0
|
|
21
|
+
Requires-Dist: opencv-python>=4.8.0
|
|
22
|
+
Requires-Dist: python-socketio[asyncio-client]>=5.10.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: mypy>=1.5.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Phystack Hub Client (Python)
|
|
32
|
+
|
|
33
|
+
Python client for PhyHub that provides:
|
|
34
|
+
- Events and Actions via twin messaging
|
|
35
|
+
- WebRTC DataChannel for P2P data
|
|
36
|
+
- WebRTC MediaStream for P2P video/audio (with webcam support)
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install phystack-hub-client
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or install from source:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install -e .
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Basic Connection
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import asyncio
|
|
56
|
+
from phystack.hub_client import PhyHubClient
|
|
57
|
+
|
|
58
|
+
async def main():
|
|
59
|
+
# Create client from environment variables
|
|
60
|
+
async with PhyHubClient.from_env() as client:
|
|
61
|
+
instance = await client.get_instance()
|
|
62
|
+
print(f"Connected as twin: {instance.id}")
|
|
63
|
+
|
|
64
|
+
asyncio.run(main())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Environment Variables
|
|
68
|
+
|
|
69
|
+
- `DEVICE_ID` or `PHYGRID_DEVICE_ID`: Device identifier
|
|
70
|
+
- `ACCESS_KEY` or `PHYGRID_DEVICE_KEY`: Access key
|
|
71
|
+
- `PHYHUB_URL` or `PHYHUB_REGION`: Server URL or region (eu, us, etc.)
|
|
72
|
+
- `TWIN_ID` or `INSTANCE_ID`: Optional specific twin ID
|
|
73
|
+
|
|
74
|
+
### Events
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
# Listen for events
|
|
78
|
+
instance.on("my-event", lambda data, respond: print(f"Received: {data}"))
|
|
79
|
+
|
|
80
|
+
# Send events to a peer
|
|
81
|
+
instance.to(peer_twin_id).emit("my-event", {"message": "hello"})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Actions (Request-Response)
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
def on_result(result):
|
|
88
|
+
print(f"Response: {result.status} - {result.message}")
|
|
89
|
+
|
|
90
|
+
# Send action with callback
|
|
91
|
+
instance.to(peer_twin_id).emit("my-action", {"command": "process"}, callback=on_result)
|
|
92
|
+
|
|
93
|
+
# Handle actions
|
|
94
|
+
def handle_action(data, respond):
|
|
95
|
+
if respond:
|
|
96
|
+
respond(TwinMessageResult(
|
|
97
|
+
status=TwinMessageResultStatus.SUCCESS,
|
|
98
|
+
message="Processed",
|
|
99
|
+
data={"result": "done"}
|
|
100
|
+
))
|
|
101
|
+
|
|
102
|
+
instance.on("my-action", handle_action)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### WebRTC DataChannel
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# Create DataChannel connection
|
|
109
|
+
dc = await client.create_data_channel(peer_twin_id, is_initiator=True)
|
|
110
|
+
|
|
111
|
+
# Send data
|
|
112
|
+
dc.send({"message": "hello via WebRTC"})
|
|
113
|
+
|
|
114
|
+
# Receive data
|
|
115
|
+
dc.on_message(lambda data: print(f"Received: {data}"))
|
|
116
|
+
|
|
117
|
+
# Close when done
|
|
118
|
+
dc.close()
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### WebRTC MediaStream (with Webcam)
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
# Create MediaStream connection (streams from webcam)
|
|
125
|
+
stream = await client.create_media_stream(peer_twin_id, is_initiator=True)
|
|
126
|
+
|
|
127
|
+
# Check if streaming
|
|
128
|
+
print(f"Streaming: {stream.is_open()}")
|
|
129
|
+
print(f"Has video: {stream.video_track is not None}")
|
|
130
|
+
|
|
131
|
+
# Close when done
|
|
132
|
+
stream.close()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Testing
|
|
136
|
+
|
|
137
|
+
### Python-Node Interoperability Test
|
|
138
|
+
|
|
139
|
+
Test communication between Python and Node.js hub-client implementations:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Setup credentials
|
|
143
|
+
./scripts/python-node-test.sh setup
|
|
144
|
+
|
|
145
|
+
# Run test (Python initiator, Node.js responder)
|
|
146
|
+
./scripts/python-node-test.sh run
|
|
147
|
+
|
|
148
|
+
# Run reversed (Node.js initiator, Python responder)
|
|
149
|
+
./scripts/python-node-test.sh run-rev
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Browser Test Backend
|
|
153
|
+
|
|
154
|
+
Use the Python client as initiator for the browser-based responder:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
export DEVICE_ID=your-device-id
|
|
158
|
+
export ACCESS_KEY=your-access-key
|
|
159
|
+
export PEER_TWIN_ID=browser-responder-twin-id
|
|
160
|
+
export PHYHUB_REGION=eu
|
|
161
|
+
|
|
162
|
+
python examples/browser_test_backend.py
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Dependencies
|
|
166
|
+
|
|
167
|
+
- `python-socketio[asyncio]` - Socket.IO client
|
|
168
|
+
- `aiortc` - WebRTC implementation
|
|
169
|
+
- `opencv-python` - Webcam capture
|
|
170
|
+
- `aiohttp` - HTTP client
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
phystack/hub_client/__init__.py,sha256=0Z_Ws7GqnUQy8OAN_iIZCvOlgq4EULS0h6VoD9vG1-k,2486
|
|
2
|
+
phystack/hub_client/client.py,sha256=sk8Z_fHAyJX8Fa1Xpl0yob40NXfM__g6Hjr5QeOsq14,24245
|
|
3
|
+
phystack/hub_client/twin_messaging.py,sha256=wVHcONAtDdrSipcf5533BlW-dkn9WcqYLXuEkfotugk,10285
|
|
4
|
+
phystack/hub_client/twin_registry.py,sha256=Ov9j__-ORSbutAgmgxBsGxstqMorbttOgITWyLx8dHI,4773
|
|
5
|
+
phystack/hub_client/instances/__init__.py,sha256=Ad9_T_6fm9tioY6iNeNLbptf9cnxjgSEHkxgsF2x1QU,345
|
|
6
|
+
phystack/hub_client/instances/base_instance.py,sha256=m-mKVoMSYz8gNBBm9MjQJ8sJYKfBwNzsNb0pHnTj530,7035
|
|
7
|
+
phystack/hub_client/instances/edge_instance.py,sha256=d2lRoXrpM2lAu-Aq5G_AhCyGXn7130wbQ16cGJAc8FQ,7793
|
|
8
|
+
phystack/hub_client/instances/peripheral_instance.py,sha256=Lxpe_RI_j9KAFkgF-gxGAlBCuRniYBaKZTSkgMQ_iZg,6998
|
|
9
|
+
phystack/hub_client/services/__init__.py,sha256=5ypwM-PIMhrjX-_wD-WFKtmIZRfVanz-zfa6rvhRpk4,143
|
|
10
|
+
phystack/hub_client/services/phyhub_connection.py,sha256=1KfE3zabWLaN45XFcI6aisG-WI2L9LchcdhVo84ABw0,8924
|
|
11
|
+
phystack/hub_client/services/webrtc/__init__.py,sha256=yRLfXJ0ig39l-JPPLjdvsSYABbiNNa_y-45VPB6o9OU,547
|
|
12
|
+
phystack/hub_client/services/webrtc/data_channel.py,sha256=g5TIrl6ngzHzhlpFcL_vk-l8E1T-S91DGs9NyDF_RVk,19422
|
|
13
|
+
phystack/hub_client/services/webrtc/media_stream.py,sha256=pC1ALh9DwD_5LJ2nLR0iZtPSwUgy2ez0P5WR_ioT6Jk,20209
|
|
14
|
+
phystack/hub_client/types/__init__.py,sha256=giUyamw1C5whZi3szMIyAGJqcDJ2US1A3rsYxyPOlkk,295
|
|
15
|
+
phystack/hub_client/types/twin_types.py,sha256=hTtT8Eb54kEtXyFZ0BL6av-e2aI6EduexgcQWvSqlbk,3891
|
|
16
|
+
phystack_hub_client-0.2.0.dist-info/METADATA,sha256=-Rs1FS1MDUg3hL7qriKc2K_0VtAjw7_f5C3idmImGf4,4358
|
|
17
|
+
phystack_hub_client-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
18
|
+
phystack_hub_client-0.2.0.dist-info/RECORD,,
|