ZeroMQ-based publisher/subscriber and RPC utilities
Project description
Commlink
Commlink exposes a lightweight Remote Procedure Call (RPC) layer on top of ZeroMQ that lets you interact with objects running in a different process or host as if they were local. You can wrap any existing object with a single line and obtain a client-side proxy that transparently mirrors attribute access, mutation, and callable invocation for anything that can be pickled. Simple publisher/subscriber helpers are also available for broadcast-style messaging when you need them.
Installation
pip install commlink
RPC quickstart
Server
from commlink import RPCServer
class TemperatureController:
def __init__(self):
self.target_celsius = 20
def get_reading(self):
"""Pretend to talk to a sensor and return the current reading."""
return self.target_celsius
def setpoint(self, value):
self.target_celsius = value
return f"Set target temperature to {value}°C"
if __name__ == "__main__":
# Wrap the object with a one-line RPC server. The server runs in a background thread by default.
server = RPCServer(TemperatureController(), port=6000)
server.start()
server.thread.join() # Optional: keep the process alive while the server thread runs.
Client
from commlink import RPCClient
# Instantiate the remote object locally – attribute access, setters, and method calls all proxy to the server.
controller = RPCClient("localhost", port=6000)
print(controller.get_reading()) # Call remote methods with any pickle-able arguments or return values.
print(controller.setpoint(25))
controller.target_celsius = 18 # Mutate attributes on the remote instance.
print(controller.target_celsius)
# When you're finished, politely stop the remote server.
controller.stop_server()
RPC capabilities
- Transparent calls – Functions and methods execute remotely with arbitrary pickle-able arguments and return values.
- Attribute access – Reading or setting attributes forwards the operation to the remote object.
- Drop-in adoption – Wrap any pre-existing object with
RPCServer(obj, ...)and obtain a live proxy by instantiatingRPCClient(host, port). - Threaded by default –
RPCServerstarts in a background thread so your host application can continue doing work or cleanly manage lifecycle events.
Publisher/subscriber helpers
If you also need broadcast-style messaging, Commlink ships with simple ZeroMQ publishers and subscribers:
from commlink import Publisher, Subscriber
publisher = Publisher("*", port=5555)
subscriber = Subscriber("localhost", port=5555, topics=["updates"])
publisher.publish("updates", {"message": "Hello, world!"})
print(subscriber.get())
Development
Run the automated test suite with:
pytest
License
Commlink is distributed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file commlink-0.1.2.tar.gz.
File metadata
- Download URL: commlink-0.1.2.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93f9688de053a1974fc219d924f47815be599e48399fc9580d17bf63babd2395
|
|
| MD5 |
4161ed8779734f0c0480dcde0017066f
|
|
| BLAKE2b-256 |
3ff01a8d8dc732725b4ccf00ce7fb6e4bb900a4873d1e2de14219705890f200a
|
File details
Details for the file commlink-0.1.2-py3-none-any.whl.
File metadata
- Download URL: commlink-0.1.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f41826e5b9052fa85c0878dca982df41fd5d63699cc4c82f6cd09641eeda6c5
|
|
| MD5 |
b0a090487d1195ad374456c87e8f4dd3
|
|
| BLAKE2b-256 |
dacc0b12602dc0e248c7b7d4613fa08e228fa97f22f8adbaf597324802238a67
|