phystack-hub-client 0.2.0__tar.gz

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.
Files changed (23) hide show
  1. phystack_hub_client-0.2.0/.gitignore +56 -0
  2. phystack_hub_client-0.2.0/PKG-INFO +174 -0
  3. phystack_hub_client-0.2.0/README.md +144 -0
  4. phystack_hub_client-0.2.0/examples/browser_test_backend.py +415 -0
  5. phystack_hub_client-0.2.0/pyproject.toml +63 -0
  6. phystack_hub_client-0.2.0/scripts/python-node-test.sh +359 -0
  7. phystack_hub_client-0.2.0/scripts/webrtc-test.sh +357 -0
  8. phystack_hub_client-0.2.0/src/phystack/hub_client/__init__.py +90 -0
  9. phystack_hub_client-0.2.0/src/phystack/hub_client/client.py +701 -0
  10. phystack_hub_client-0.2.0/src/phystack/hub_client/instances/__init__.py +11 -0
  11. phystack_hub_client-0.2.0/src/phystack/hub_client/instances/base_instance.py +225 -0
  12. phystack_hub_client-0.2.0/src/phystack/hub_client/instances/edge_instance.py +212 -0
  13. phystack_hub_client-0.2.0/src/phystack/hub_client/instances/peripheral_instance.py +186 -0
  14. phystack_hub_client-0.2.0/src/phystack/hub_client/services/__init__.py +5 -0
  15. phystack_hub_client-0.2.0/src/phystack/hub_client/services/phyhub_connection.py +272 -0
  16. phystack_hub_client-0.2.0/src/phystack/hub_client/services/webrtc/__init__.py +23 -0
  17. phystack_hub_client-0.2.0/src/phystack/hub_client/services/webrtc/data_channel.py +527 -0
  18. phystack_hub_client-0.2.0/src/phystack/hub_client/services/webrtc/media_stream.py +571 -0
  19. phystack_hub_client-0.2.0/src/phystack/hub_client/twin_messaging.py +287 -0
  20. phystack_hub_client-0.2.0/src/phystack/hub_client/twin_registry.py +158 -0
  21. phystack_hub_client-0.2.0/src/phystack/hub_client/types/__init__.py +15 -0
  22. phystack_hub_client-0.2.0/src/phystack/hub_client/types/twin_types.py +136 -0
  23. phystack_hub_client-0.2.0/tests/test_communication.py +555 -0
@@ -0,0 +1,56 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ venv/
25
+ ENV/
26
+ env/
27
+ .venv/
28
+
29
+ # IDE
30
+ .idea/
31
+ .vscode/
32
+ *.swp
33
+ *.swo
34
+
35
+ # Testing
36
+ .pytest_cache/
37
+ .coverage
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+
42
+ # Logs
43
+ *.log
44
+
45
+ # Environment files
46
+ .env
47
+ .env.*
48
+ !.env.example
49
+
50
+ # OS
51
+ .DS_Store
52
+ Thumbs.db
53
+
54
+ # Test configuration (contains secrets)
55
+ .env.webrtc-test
56
+ .env.interop-test
@@ -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,144 @@
1
+ # Phystack Hub Client (Python)
2
+
3
+ Python client for PhyHub that provides:
4
+ - Events and Actions via twin messaging
5
+ - WebRTC DataChannel for P2P data
6
+ - WebRTC MediaStream for P2P video/audio (with webcam support)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install phystack-hub-client
12
+ ```
13
+
14
+ Or install from source:
15
+
16
+ ```bash
17
+ pip install -e .
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Basic Connection
23
+
24
+ ```python
25
+ import asyncio
26
+ from phystack.hub_client import PhyHubClient
27
+
28
+ async def main():
29
+ # Create client from environment variables
30
+ async with PhyHubClient.from_env() as client:
31
+ instance = await client.get_instance()
32
+ print(f"Connected as twin: {instance.id}")
33
+
34
+ asyncio.run(main())
35
+ ```
36
+
37
+ ### Environment Variables
38
+
39
+ - `DEVICE_ID` or `PHYGRID_DEVICE_ID`: Device identifier
40
+ - `ACCESS_KEY` or `PHYGRID_DEVICE_KEY`: Access key
41
+ - `PHYHUB_URL` or `PHYHUB_REGION`: Server URL or region (eu, us, etc.)
42
+ - `TWIN_ID` or `INSTANCE_ID`: Optional specific twin ID
43
+
44
+ ### Events
45
+
46
+ ```python
47
+ # Listen for events
48
+ instance.on("my-event", lambda data, respond: print(f"Received: {data}"))
49
+
50
+ # Send events to a peer
51
+ instance.to(peer_twin_id).emit("my-event", {"message": "hello"})
52
+ ```
53
+
54
+ ### Actions (Request-Response)
55
+
56
+ ```python
57
+ def on_result(result):
58
+ print(f"Response: {result.status} - {result.message}")
59
+
60
+ # Send action with callback
61
+ instance.to(peer_twin_id).emit("my-action", {"command": "process"}, callback=on_result)
62
+
63
+ # Handle actions
64
+ def handle_action(data, respond):
65
+ if respond:
66
+ respond(TwinMessageResult(
67
+ status=TwinMessageResultStatus.SUCCESS,
68
+ message="Processed",
69
+ data={"result": "done"}
70
+ ))
71
+
72
+ instance.on("my-action", handle_action)
73
+ ```
74
+
75
+ ### WebRTC DataChannel
76
+
77
+ ```python
78
+ # Create DataChannel connection
79
+ dc = await client.create_data_channel(peer_twin_id, is_initiator=True)
80
+
81
+ # Send data
82
+ dc.send({"message": "hello via WebRTC"})
83
+
84
+ # Receive data
85
+ dc.on_message(lambda data: print(f"Received: {data}"))
86
+
87
+ # Close when done
88
+ dc.close()
89
+ ```
90
+
91
+ ### WebRTC MediaStream (with Webcam)
92
+
93
+ ```python
94
+ # Create MediaStream connection (streams from webcam)
95
+ stream = await client.create_media_stream(peer_twin_id, is_initiator=True)
96
+
97
+ # Check if streaming
98
+ print(f"Streaming: {stream.is_open()}")
99
+ print(f"Has video: {stream.video_track is not None}")
100
+
101
+ # Close when done
102
+ stream.close()
103
+ ```
104
+
105
+ ## Testing
106
+
107
+ ### Python-Node Interoperability Test
108
+
109
+ Test communication between Python and Node.js hub-client implementations:
110
+
111
+ ```bash
112
+ # Setup credentials
113
+ ./scripts/python-node-test.sh setup
114
+
115
+ # Run test (Python initiator, Node.js responder)
116
+ ./scripts/python-node-test.sh run
117
+
118
+ # Run reversed (Node.js initiator, Python responder)
119
+ ./scripts/python-node-test.sh run-rev
120
+ ```
121
+
122
+ ### Browser Test Backend
123
+
124
+ Use the Python client as initiator for the browser-based responder:
125
+
126
+ ```bash
127
+ export DEVICE_ID=your-device-id
128
+ export ACCESS_KEY=your-access-key
129
+ export PEER_TWIN_ID=browser-responder-twin-id
130
+ export PHYHUB_REGION=eu
131
+
132
+ python examples/browser_test_backend.py
133
+ ```
134
+
135
+ ## Dependencies
136
+
137
+ - `python-socketio[asyncio]` - Socket.IO client
138
+ - `aiortc` - WebRTC implementation
139
+ - `opencv-python` - Webcam capture
140
+ - `aiohttp` - HTTP client
141
+
142
+ ## License
143
+
144
+ MIT