Skip to content

Python RPC library using zmq for transport, and BSON for buffers

Notifications You must be signed in to change notification settings

geoffwatts/zmqrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

ZMQRPC

A Python library that exports a class for RPC via zmq, using BSON for data interchange.

Installation

zmqrpc is registered at pypi.

Install using pip or easy_install:

$> pip install zmqrpc

Prerequisites

Contributing and Enhancements

Go for it, fork away and fix it up. There's a lot of performance tweaks that can be made, this is very much 0.1

Most notably, I think the bson encoding should happen inside pyzmq.

Usage

A basic server:

This server will listen on TCP port 5000, and start 2 worker threads for the class Test

    class Test(object):

        def __init__(self):
            self.count = 0

        def test(self):
            self.count += 1
            return self.count        


    from zmqrpc.server import ZMQRPCServer, LISTEN, CONNECT

    server = ZMQRPCServer(Test)
    server.queue('tcp://0.0.0.0:5000',thread=True)
    server.work(workers=2)

A basic client:

This client connects to our server, then runs the test() method 5000 times. It then prints the last output of rpc.test(), and pprint's the server status.

    from zmqrpc.client import ZMQRPC 
    import sys
    import pprint

    rpc = ZMQRPC("tcp://127.0.0.1:5000",timeout=5)
    for i in range(5000):
        x = rpc.test()

    print x
    servers = rpc.__serverstatus__()
    pprint.pprint(servers)

Usage Notes

This library is still very early. The API is likely to change.

About

Python RPC library using zmq for transport, and BSON for buffers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages