Added my JSON-RPC library to Google Code

Sunday, October 18th, 2009 1:09 am

Recently, I’ve been hacking together a JSON-RPC implementation for Python. It follows the xmlrpclib syntax (because it’s pretty darn simple to use and extend), but also adds some of the new, slick features of the JSON-RPC v2 (proposed) specification like:

  • Batch submissions
  • Keyword arguments
  • Notifications (both via batch and single)

So, unsurprisingly, I called it jsonrpclib. I didn’t see anything called that yet, so I hope I’m not hopping on someone else’s name. But Google Code didn’t have it, and if it’s not on Google, then it doesn’t really exist, right? :)

Project Page for jsonrpclib – http://code.google.com/p/jsonrpclib/

In some simple (read: probably inaccurate) speed tests, my library usually came out on top, about 1.1x faster than the “official” JSON-RPC implementation, and about 1.5-1.7x faster than the xmlrpclib library. I’ve also created a JSON-RPC handler for Tornado (what I used to test it), and I’ll be uploading it plus the XML-RPC Tornado handler to Google Code in the next few days, after I put some shiny paper on it. I didn’t see any other 2.0 server implementations yet (maybe because it’s just a proposed specification :) ) so I figure maybe it will be worthwhile until I can add a standalone JSON-RPC server to the library a la SimpleXMLRPCServer.

Anyway, so usage should be really familiar (this is in a python console):

>>> import jsonrpclib
>>> server = jsonrpclib.Server('http://localhost:8181')
>>> server.add(5, 6)
11
>>> server._notify.add(5, 6)
>>> batch = jsonrpclib.MultiCall(server)
>>> batch.add(10, 17)
>>> batch.ping({'key':'value'})
>>> batch._notify.add(50, 40)
>>> batch()
[27, {'key': 'value'}]

I do have to say inserting a notification into a batch seems a little silly to me since you have to do intelligent parsing afterwards to dismiss the missing notification, but people smarter than I are working on the spec, so I’ll dig for now.

If you play with it, please post in the comments about your experience! Also, add an Issue to the project page if it a.) acts oddly b.) just doesn’t work for you c.) replaces your hard drive with a toaster oven.

Leave a Reply