pyRpc

A simple remote procedure call module using ZeroMQ

Remote Procedure Call support, for exposing local function as public services, and calling public services on remote applications.

Wraps around ZeroMQ for messaging. http://www.zeromq.org/

This is a very basic module that allows you to create an application which exports various functions as services, and then to have client apps call these services almost like a native python call.

1. Requirements

This module uses ZeroMQ for the messaging functionality: http://www.zeromq.org/
pyzmq is installed during the setup.py but you should make sure to have zmq installed.

The GUI examples require PyQt4: http://www.riverbankcomputing.co.uk/software/pyqt/download http://qt.nokia.com/downloads

2. Install

python setup.py install

3. Documentation

Read documentation here

4. Basic Example

Exporting functions as services (server)

import time
from pyRpc import PyRpc

def add(a, b):
    """ Returns a + b """
    return a+b

def favoriteColor():
    """ Tell you our favorite color """
    return "red"

myRpc = PyRpc("com.myCompany.MyApplication") 
time.sleep(.1)

myRpc.publishService(add)
myRpc.publishService(favoriteColor)
myRpc.start()

try:
    while True:
        time.sleep(1)

except KeyboardInterrupt:
    myRpc.stop()

Calling remote services from a client



import time
from pyRpc import RpcConnection

def response(resp):
    print "Got response:", resp
    print "1 + 2 =", resp.result

remote = RpcConnection("com.myCompany.MyApplication")
time.sleep(.1)

resp = remote.availableServices()
for service in resp.result:
    print "\nService: %(service)s \nDescription: %(doc)s \nUsage: %(format)s\n" % service


# calls remove add() and does not wait. Result will be returned to response()
remote.call("add", args=(1, 2), callback=response)

# blocks while waiting for a response
resp = remote.call("favoriteColor")
print "Favorite color:", resp.result

time.sleep(1)

remote.close()

time.sleep(1)