Skip to main content

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 instantiating RPCClient(host, port).
  • Threaded by defaultRPCServer starts 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commlink-0.1.2.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commlink-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page