vrpc 2.4.0__tar.gz → 3.0.2__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.
vrpc-3.0.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Heisenware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
vrpc-3.0.2/PKG-INFO ADDED
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.4
2
+ Name: vrpc
3
+ Version: 3.0.2
4
+ Summary: Asynchronous remote procedure calls for Python over MQTT
5
+ Author-email: "Dr. Burkhard C. Heisen" <burkhard.heisen@heisenware.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Heisenware
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://vrpc.io
29
+ Project-URL: Repository, https://github.com/heisenware/vrpc-py
30
+ Project-URL: Issues, https://github.com/heisenware/vrpc-py/issues
31
+ Keywords: rpc,mqtt,async,iot,remote-procedure-call
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.8
37
+ Classifier: Programming Language :: Python :: 3.9
38
+ Classifier: Programming Language :: Python :: 3.10
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Operating System :: OS Independent
42
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
43
+ Requires-Python: >=3.8
44
+ Description-Content-Type: text/markdown
45
+ License-File: LICENSE
46
+ Requires-Dist: aiomqtt>=2.0.0
47
+ Requires-Dist: nanoid>=2.0.0
48
+ Requires-Dist: docstring-parser>=0.15
49
+ Requires-Dist: pyee>=11.1.0
50
+ Provides-Extra: test
51
+ Requires-Dist: pytest; extra == "test"
52
+ Requires-Dist: pytest-asyncio; extra == "test"
53
+ Requires-Dist: pytest-mock; extra == "test"
54
+ Dynamic: license-file
55
+
56
+ # vrpc
57
+
58
+ > **Variadic Remote Procedure Calls for Python**
59
+
60
+ `vrpc` is an asynchronous, event-driven Remote Procedure Call (RPC) framework for Python. It allows you to seamlessly expose standard Python classes and functions over an MQTT message broker, making them instantly callable from anywhere in the world.
61
+
62
+ By leveraging MQTT and Python's `asyncio`, `vrpc` bypasses NATs, firewalls, and complex networking setups, allowing for bi-directional communication, dynamic object instantiation, and remote continuous event streaming.
63
+
64
+ It is 100% protocol-compatible with the [Node.js / JS `vrpc` implementation](https://github.com/heisenware/vrpc).
65
+
66
+ ## ✨ Features
67
+
68
+ - **Zero Boilerplate:** Register existing Python classes without modifying their code.
69
+ - **Fully Asynchronous:** Built from the ground up on modern `asyncio` and `aiomqtt`.
70
+ - **Stateful Instances:** Create, manage, and delete remote object instances dynamically. Shared instances can be interacted with by multiple clients simultaneously.
71
+ - **Remote Event Listeners:** Pass Python callables as arguments to remote functions. VRPC automatically binds them to MQTT streams (perfect for real-time sensor data or status updates).
72
+ - **Batch Executions:** Broadcast method calls to all instances of a class across multiple distributed agents in a single line of code (`call_all`).
73
+
74
+ ## 📦 Installation
75
+
76
+ Since `vrpc` is modern Python package (PEP 621), you can install it directly via pip:
77
+
78
+ ```bash
79
+ pip install vrpc
80
+ ```
81
+
82
+ _Requirements: Python 3.8+_
83
+
84
+ ## 🚀 Quick Start
85
+
86
+ To use VRPC, you need two components: an **Agent** (which hosts your code) and a **Client** (which remotely calls it). Both connect to a central MQTT broker.
87
+
88
+ ### 1. The Agent (Server)
89
+
90
+ First, write a standard Python class. Let's create a `Counter` that maintains state and can emit continuous events via a callback.
91
+
92
+ ```python
93
+ # agent.py
94
+ import asyncio
95
+ from vrpc import VrpcAdapter, VrpcAgent
96
+
97
+ class Counter:
98
+ def __init__(self, initial_value=0):
99
+ self._count = initial_value
100
+ self._callback = None
101
+
102
+ def on_change(self, callback):
103
+ """Registers a callback for continuous state updates."""
104
+ self._callback = callback
105
+
106
+ def increment(self, step=1):
107
+ """Increments the counter and triggers the callback."""
108
+ self._count += step
109
+ if self._callback:
110
+ self._callback(self._count)
111
+ return self._count
112
+
113
+ # 1. Register the class so VRPC knows about it
114
+ VrpcAdapter.register(Counter)
115
+
116
+ async def main():
117
+ # 2. Configure the Agent to connect to a broker
118
+ agent = VrpcAgent(
119
+ domain="my.custom.domain",
120
+ agent="python-agent-1",
121
+ broker="mqtt://broker.hivemq.com:1883" # Public test broker
122
+ )
123
+
124
+ print("Agent is starting...")
125
+ await agent.serve()
126
+
127
+ if __name__ == "__main__":
128
+ asyncio.run(main())
129
+ ```
130
+
131
+ ### 2. The Client
132
+
133
+ Now, from a completely different machine, process, or network, we can connect a client, create an instance of that `Counter`, and interact with it.
134
+
135
+ ```python
136
+ # client.py
137
+ import asyncio
138
+ from vrpc import VrpcClient
139
+
140
+ async def main():
141
+ # 1. Connect to the same broker and domain
142
+ client = VrpcClient(
143
+ domain="my.custom.domain",
144
+ broker="mqtt://broker.hivemq.com:1883"
145
+ )
146
+ await client.connect()
147
+
148
+ # 2. Create a remote instance of the Counter
149
+ print("Creating remote Counter instance...")
150
+ counter = await client.create(
151
+ agent="python-agent-1",
152
+ class_name="Counter",
153
+ instance="my-shared-counter",
154
+ args=[10] # Passes '10' to initial_value
155
+ )
156
+
157
+ # 3. Define a local function to handle remote events
158
+ def handle_update(new_val):
159
+ print(f" -> Continuous Event Received! Counter is now: {new_val}")
160
+
161
+ # VRPC magically wires this Python function over MQTT
162
+ await counter.on_change(handle_update)
163
+
164
+ # 4. Call remote methods
165
+ print("Calling increment(5)...")
166
+ result = await counter.increment(5)
167
+ print(f"RPC Returned: {result}")
168
+
169
+ # Cleanup
170
+ await client.end()
171
+
172
+ if __name__ == "__main__":
173
+ asyncio.run(main())
174
+ ```
175
+
176
+ ## 🏗 Architecture Concepts
177
+
178
+ VRPC organizes remote execution using a specific hierarchy:
179
+
180
+ - **Domain:** The highest level of isolation. Agents and Clients must share the same domain to see each other.
181
+ - **Agent:** A physical process hosting VRPC code. A single domain can have hundreds of distributed agents.
182
+ - **Class:** A registered Python class available for instantiation.
183
+ - **Instance:** A specific, stateful object created from a Class. Instances can be **Shared** (visible to all clients) or **Isolated** (visible only to the client that created it).
184
+
185
+ ## 🤝 Contributing
186
+
187
+ Contributions, issues, and feature requests are welcome!
188
+
189
+ 1. Fork the project.
190
+ 2. Install with test dependencies: `pip install -e .[test]`
191
+ 3. Run local adapter tests: `pytest tests/adapter/test_adapter.py`
192
+ 4. Run integration tests (requires Docker): `cd tests/agent && ./test.sh`
193
+
194
+ ## 📝 License
195
+
196
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
vrpc-3.0.2/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # vrpc
2
+
3
+ > **Variadic Remote Procedure Calls for Python**
4
+
5
+ `vrpc` is an asynchronous, event-driven Remote Procedure Call (RPC) framework for Python. It allows you to seamlessly expose standard Python classes and functions over an MQTT message broker, making them instantly callable from anywhere in the world.
6
+
7
+ By leveraging MQTT and Python's `asyncio`, `vrpc` bypasses NATs, firewalls, and complex networking setups, allowing for bi-directional communication, dynamic object instantiation, and remote continuous event streaming.
8
+
9
+ It is 100% protocol-compatible with the [Node.js / JS `vrpc` implementation](https://github.com/heisenware/vrpc).
10
+
11
+ ## ✨ Features
12
+
13
+ - **Zero Boilerplate:** Register existing Python classes without modifying their code.
14
+ - **Fully Asynchronous:** Built from the ground up on modern `asyncio` and `aiomqtt`.
15
+ - **Stateful Instances:** Create, manage, and delete remote object instances dynamically. Shared instances can be interacted with by multiple clients simultaneously.
16
+ - **Remote Event Listeners:** Pass Python callables as arguments to remote functions. VRPC automatically binds them to MQTT streams (perfect for real-time sensor data or status updates).
17
+ - **Batch Executions:** Broadcast method calls to all instances of a class across multiple distributed agents in a single line of code (`call_all`).
18
+
19
+ ## 📦 Installation
20
+
21
+ Since `vrpc` is modern Python package (PEP 621), you can install it directly via pip:
22
+
23
+ ```bash
24
+ pip install vrpc
25
+ ```
26
+
27
+ _Requirements: Python 3.8+_
28
+
29
+ ## 🚀 Quick Start
30
+
31
+ To use VRPC, you need two components: an **Agent** (which hosts your code) and a **Client** (which remotely calls it). Both connect to a central MQTT broker.
32
+
33
+ ### 1. The Agent (Server)
34
+
35
+ First, write a standard Python class. Let's create a `Counter` that maintains state and can emit continuous events via a callback.
36
+
37
+ ```python
38
+ # agent.py
39
+ import asyncio
40
+ from vrpc import VrpcAdapter, VrpcAgent
41
+
42
+ class Counter:
43
+ def __init__(self, initial_value=0):
44
+ self._count = initial_value
45
+ self._callback = None
46
+
47
+ def on_change(self, callback):
48
+ """Registers a callback for continuous state updates."""
49
+ self._callback = callback
50
+
51
+ def increment(self, step=1):
52
+ """Increments the counter and triggers the callback."""
53
+ self._count += step
54
+ if self._callback:
55
+ self._callback(self._count)
56
+ return self._count
57
+
58
+ # 1. Register the class so VRPC knows about it
59
+ VrpcAdapter.register(Counter)
60
+
61
+ async def main():
62
+ # 2. Configure the Agent to connect to a broker
63
+ agent = VrpcAgent(
64
+ domain="my.custom.domain",
65
+ agent="python-agent-1",
66
+ broker="mqtt://broker.hivemq.com:1883" # Public test broker
67
+ )
68
+
69
+ print("Agent is starting...")
70
+ await agent.serve()
71
+
72
+ if __name__ == "__main__":
73
+ asyncio.run(main())
74
+ ```
75
+
76
+ ### 2. The Client
77
+
78
+ Now, from a completely different machine, process, or network, we can connect a client, create an instance of that `Counter`, and interact with it.
79
+
80
+ ```python
81
+ # client.py
82
+ import asyncio
83
+ from vrpc import VrpcClient
84
+
85
+ async def main():
86
+ # 1. Connect to the same broker and domain
87
+ client = VrpcClient(
88
+ domain="my.custom.domain",
89
+ broker="mqtt://broker.hivemq.com:1883"
90
+ )
91
+ await client.connect()
92
+
93
+ # 2. Create a remote instance of the Counter
94
+ print("Creating remote Counter instance...")
95
+ counter = await client.create(
96
+ agent="python-agent-1",
97
+ class_name="Counter",
98
+ instance="my-shared-counter",
99
+ args=[10] # Passes '10' to initial_value
100
+ )
101
+
102
+ # 3. Define a local function to handle remote events
103
+ def handle_update(new_val):
104
+ print(f" -> Continuous Event Received! Counter is now: {new_val}")
105
+
106
+ # VRPC magically wires this Python function over MQTT
107
+ await counter.on_change(handle_update)
108
+
109
+ # 4. Call remote methods
110
+ print("Calling increment(5)...")
111
+ result = await counter.increment(5)
112
+ print(f"RPC Returned: {result}")
113
+
114
+ # Cleanup
115
+ await client.end()
116
+
117
+ if __name__ == "__main__":
118
+ asyncio.run(main())
119
+ ```
120
+
121
+ ## 🏗 Architecture Concepts
122
+
123
+ VRPC organizes remote execution using a specific hierarchy:
124
+
125
+ - **Domain:** The highest level of isolation. Agents and Clients must share the same domain to see each other.
126
+ - **Agent:** A physical process hosting VRPC code. A single domain can have hundreds of distributed agents.
127
+ - **Class:** A registered Python class available for instantiation.
128
+ - **Instance:** A specific, stateful object created from a Class. Instances can be **Shared** (visible to all clients) or **Isolated** (visible only to the client that created it).
129
+
130
+ ## 🤝 Contributing
131
+
132
+ Contributions, issues, and feature requests are welcome!
133
+
134
+ 1. Fork the project.
135
+ 2. Install with test dependencies: `pip install -e .[test]`
136
+ 3. Run local adapter tests: `pytest tests/adapter/test_adapter.py`
137
+ 4. Run integration tests (requires Docker): `cd tests/agent && ./test.sh`
138
+
139
+ ## 📝 License
140
+
141
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "vrpc"
7
+ version = "3.0.2"
8
+ description = "Asynchronous remote procedure calls for Python over MQTT"
9
+ readme = {file = "README.md", content-type = "text/markdown"}
10
+ requires-python = ">=3.8"
11
+ license = {file = "LICENSE"}
12
+ authors = [
13
+ {name = "Dr. Burkhard C. Heisen", email = "burkhard.heisen@heisenware.com"}
14
+ ]
15
+ keywords = ["rpc", "mqtt", "async", "iot", "remote-procedure-call"]
16
+ classifiers = [
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Operating System :: OS Independent",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ ]
29
+
30
+ # Core dependencies needed to run the package
31
+ dependencies = [
32
+ "aiomqtt>=2.0.0",
33
+ "nanoid>=2.0.0",
34
+ "docstring-parser>=0.15",
35
+ "pyee>=11.1.0"
36
+ ]
37
+
38
+ # Optional dependencies for development and testing
39
+ [project.optional-dependencies]
40
+ test = [
41
+ "pytest",
42
+ "pytest-asyncio",
43
+ "pytest-mock"
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://vrpc.io"
48
+ Repository = "https://github.com/heisenware/vrpc-py"
49
+ Issues = "https://github.com/heisenware/vrpc-py/issues"
50
+
51
+ [tool.pytest.ini_options]
52
+ norecursedirs = "tests/adapter/fixtures"
53
+ asyncio_mode = "auto"
File without changes