pydispatch

Simple Python message dispatcher


License
Other
Install
pip install pydispatch==1.1.0

Documentation

Welcome to pydispatch.

pydispatch is a super-simple library that uses JSON to send messages from a client to a server, where the server processes the message in a defined way and sends back a response accordingly.

pydispatch allows you to quickly get a server running, with complete (and verbose) logging functionality, and define its actions as Python functions, and then connect to it from elsewhere and perform those actions.

Making a server is as simple as subclassing two classes -- a server class and a handler class. The server class declares how the server should be run, and the handler class defines what the server knows how to do (what requests it understands).

import dispatch

class MyHandler(dispatch.Handler):
    def action_sum(self, x, y):
        return {
            'sum': x + y,
        }

class MyServer(dispatch.Server):
    bind_interface = '127.0.0.1'
    port = 8000
    handler = MyHandler

Run the server by instantiating it and calling the start method to run in the background, or the run method to run in the foreground.

Once the server is running, communicating with it requires minimal code:

>>> import dispatch
>>> c = dispatch.Client(port=8000)
>>> c.sum(x=10, y=20)
{ 'status': 'ok', 'sum': 30 }

Installation

pydispatch is compatible with Python 2.7 and Python 3.3.

Install with pip:

pip install pydispatch

Or, clone the repo and run the standard steps:

python setup.py build
python setup.py install

License

New BSD