Giter Club home page Giter Club logo

pyrpc's Introduction

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.

Requirements

This module uses ZeroMQ for the messaging functionality: http://www.zeromq.org/ It should get installed by the setup.py installation process. But on some systems you may need to install this seperately.

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

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)

# we can ask the remote server what services are available
resp = remote.availableServices()
for service in resp.result:
	print "\nService: %(service)s \nDescription: %(doc)s \nUsage: %(format)s\n" % service


# calls remote 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)

pyrpc's People

Contributors

justinfx avatar mattpaletta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.