pyRpc is a simple remote procedure call Python 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.
Install
Download and:
python setup.py install
or
pip install pyRpc
or
easy_install pyRpc
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)
Package Documentation
Product's homepage
Requirements:
· Python
· ZeroMQ
· PyQt