13 Oct 2010


The django-hessian library serves objects via Django using the Hessian RPC protocol.


The django-hessian library requires a version of the mustaine Python Hessian library >=0.1.3 which includes a Hessian WSGI server implementation.



Objects can be served using a djangohessian.Dispatcher at a given URL with an entry The following example serves an object of type server.Calculator at the URL http://localhost:8000/rpc/calculator/ in the Django development server:

# mysite/myapp/
from djangohessian import exposed

class Calculator(object):
    def add(self, a, b):
        return a + b

    def subtract(self, a, b):
        return a - b
# mysite/
from django.conf.urls.defaults import *

urlpatterns = patterns('',
    url(r'^rpc/', include('mysite.myapp.urls')),
# mysite/myapp/
from django.conf.urls.defaults import *
from djangohessian import Dispatcher

from server import Calculator

urlpatterns = patterns('',
   url(r'^calculator/', Dispatcher(Calculator())),

Note that any methods you wish to expose on the served object must be decorated with @exposed.

The following is a sample client interactive session written using the mustaine Hessian library:

>>> from mustaine.client import HessianProxy
>>> h = HessianProxy('http://localhost:8000/rpc/calculator/')
>>> h.add(2, 3)
>>> h.subtract(7, 3)

Full source can be found at