{ "info": { "author": "Josh Marshall + Niall Douglas", "author_email": "catchjosh@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable" ], "description": "I have made multiple bug fixes, performance improvements and small\r\nnew features. The upstream authors hasn't replied to requests to\r\nmerge in over six months, so I upload this improved version here.\r\n\r\nNiall Douglas\r\nFebruary 2012\r\n\r\n\r\n\r\nJSONRPClib\r\n==========\r\nThis library is an implementation of the JSON-RPC specification.\r\nIt supports both the original 1.0 specification, as well as the \r\nnew (proposed) 2.0 spec, which includes batch submission, keyword\r\narguments, etc.\r\n\r\nIt is licensed under the Apache License, Version 2.0\r\n(http://www.apache.org/licenses/LICENSE-2.0.html).\r\n\r\nCommunication\r\n-------------\r\nFeel free to send any questions, comments, or patches to our Google Group \r\nmailing list (you'll need to join to send a message): \r\nhttp://groups.google.com/group/jsonrpclib\r\n\r\nSummary\r\n-------\r\nThis library implements the JSON-RPC 2.0 proposed specification in pure Python. \r\nIt is designed to be as compatible with the syntax of xmlrpclib as possible \r\n(it extends where possible), so that projects using xmlrpclib could easily be \r\nmodified to use JSON and experiment with the differences.\r\n\r\nIt is backwards-compatible with the 1.0 specification, and supports all of the \r\nnew proposed features of 2.0, including:\r\n\r\n* Batch submission (via MultiCall)\r\n* Keyword arguments\r\n* Notifications (both in a batch and 'normal')\r\n* Class translation using the 'jsonclass' key.\r\n\r\nI've added a \"SimpleJSONRPCServer\", which is intended to emulate the \r\n\"SimpleXMLRPCServer\" from the default Python distribution.\r\n\r\nRequirements\r\n------------\r\nIt supports cjson and simplejson, and looks for the parsers in that order \r\n(searching first for cjson, then for the \"built-in\" simplejson as json in 2.6+, \r\nand then the simplejson external library). One of these must be installed to \r\nuse this library, although if you have a standard distribution of 2.6+, you \r\nshould already have one. Keep in mind that cjson is supposed to be the \r\nquickest, I believe, so if you are going for full-on optimization you may \r\nwant to pick it up.\r\n\r\nInstallation\r\n------------\r\nYou can install this from PyPI with one of the following commands (sudo\r\nmay be required):\r\n\r\n\teasy_install jsonrpclib\r\n\tpip install jsonrpclib\r\n\r\nAlternatively, you can download the source from the github repository\r\nat http://github.com/joshmarshall/jsonrpclib and manually install it\r\nwith the following commands:\r\n\r\n\tgit clone git://github.com/joshmarshall/jsonrpclib.git\r\n\tcd jsonrpclib\r\n\tpython setup.py install\r\n\r\nClient Usage\r\n------------\r\n\r\nThis is (obviously) taken from a console session.\r\n\r\n\t>>> import jsonrpclib\r\n\t>>> server = jsonrpclib.Server('http://localhost:8080')\r\n\t>>> server.add(5,6)\r\n\t11\r\n\t>>> print jsonrpclib.history.request\r\n\t{\"jsonrpc\": \"2.0\", \"params\": [5, 6], \"id\": \"gb3c9g37\", \"method\": \"add\"}\r\n\t>>> print jsonrpclib.history.response\r\n\t{'jsonrpc': '2.0', 'result': 11, 'id': 'gb3c9g37'}\r\n\t>>> server.add(x=5, y=10)\r\n\t15\r\n\t>>> server._notify.add(5,6)\r\n\t# No result returned...\r\n\t>>> batch = jsonrpclib.MultiCall(server)\r\n\t>>> batch.add(5, 6)\r\n\t>>> batch.ping({'key':'value'})\r\n\t>>> batch._notify.add(4, 30)\r\n\t>>> results = batch()\r\n\t>>> for result in results:\r\n\t>>> ... print result\r\n\t11\r\n\t{'key': 'value'}\r\n\t# Note that there are only two responses -- this is according to spec.\r\n\r\nIf you need 1.0 functionality, there are a bunch of places you can pass that \r\nin, although the best is just to change the value on \r\njsonrpclib.config.version:\r\n\r\n\t>>> import jsonrpclib\r\n\t>>> jsonrpclib.config.version\r\n\t2.0\r\n\t>>> jsonrpclib.config.version = 1.0\r\n\t>>> server = jsonrpclib.Server('http://localhost:8080')\r\n\t>>> server.add(7, 10)\r\n\t17\r\n\t>>> print jsonrpclib..history.request\r\n\t{\"params\": [7, 10], \"id\": \"thes7tl2\", \"method\": \"add\"}\r\n\t>>> print jsonrpclib.history.response\r\n\t{'id': 'thes7tl2', 'result': 17, 'error': None}\r\n\t>>> \r\n\r\nThe equivalent loads and dumps functions also exist, although with minor \r\nmodifications. The dumps arguments are almost identical, but it adds three \r\narguments: rpcid for the 'id' key, version to specify the JSON-RPC \r\ncompatibility, and notify if it's a request that you want to be a \r\nnotification. \r\n\r\nAdditionally, the loads method does not return the params and method like \r\nxmlrpclib, but instead a.) parses for errors, raising ProtocolErrors, and \r\nb.) returns the entire structure of the request / response for manual parsing.\r\n\r\nSimpleJSONRPCServer\r\n-------------------\r\nThis is identical in usage (or should be) to the SimpleXMLRPCServer in the default Python install. Some of the differences in features are that it obviously supports notification, batch calls, class translation (if left on), etc. Note: The import line is slightly different from the regular SimpleXMLRPCServer, since the SimpleJSONRPCServer is distributed within the jsonrpclib library.\r\n\r\n\tfrom jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer\r\n\r\n\tserver = SimpleJSONRPCServer(('localhost', 8080))\r\n\tserver.register_function(pow)\r\n\tserver.register_function(lambda x,y: x+y, 'add')\r\n\tserver.register_function(lambda x: x, 'ping')\r\n\tserver.serve_forever()\r\n\r\nClass Translation\r\n-----------------\r\nI've recently added \"automatic\" class translation support, although it is \r\nturned off by default. This can be devastatingly slow if improperly used, so \r\nthe following is just a short list of things to keep in mind when using it.\r\n\r\n* Keep It (the object) Simple Stupid. (for exceptions, keep reading.)\r\n* Do not require init params (for exceptions, keep reading)\r\n* Getter properties without setters could be dangerous (read: not tested)\r\n\r\nIf any of the above are issues, use the _serialize method. (see usage below)\r\nThe server and client must BOTH have use_jsonclass configuration item on and \r\nthey must both have access to the same libraries used by the objects for \r\nthis to work.\r\n\r\nIf you have excessively nested arguments, it would be better to turn off the \r\ntranslation and manually invoke it on specific objects using \r\njsonrpclib.jsonclass.dump / jsonrpclib.jsonclass.load (since the default \r\nbehavior recursively goes through attributes and lists / dicts / tuples).\r\n\r\n[test_obj.py]\r\n\r\n\t# This object is /very/ simple, and the system will look through the \r\n\t# attributes and serialize what it can.\r\n\tclass TestObj(object):\r\n\t foo = 'bar'\r\n\r\n\t# This object requires __init__ params, so it uses the _serialize method\r\n\t# and returns a tuple of init params and attribute values (the init params\r\n\t# can be a dict or a list, but the attribute values must be a dict.)\r\n\tclass TestSerial(object):\r\n\t foo = 'bar'\r\n\t def __init__(self, *args):\r\n\t self.args = args\r\n\t def _serialize(self):\r\n\t return (self.args, {'foo':self.foo,})\r\n\r\n[usage]\r\n\r\n\timport jsonrpclib\r\n\timport test_obj\r\n\r\n\tjsonrpclib.config.use_jsonclass = True\r\n\r\n\ttestobj1 = test_obj.TestObj()\r\n\ttestobj2 = test_obj.TestSerial()\r\n\tserver = jsonrpclib.Server('http://localhost:8080')\r\n\t# The 'ping' just returns whatever is sent\r\n\tping1 = server.ping(testobj1)\r\n\tping2 = server.ping(testobj2)\r\n\tprint jsonrpclib.history.request\r\n\t# {\"jsonrpc\": \"2.0\", \"params\": [{\"__jsonclass__\": [\"test_obj.TestSerial\", [\"foo\"]]}], \"id\": \"a0l976iv\", \"method\": \"ping\"}\r\n\tprint jsonrpclib.history.result\r\n\t# {'jsonrpc': '2.0', 'result': , 'id': 'a0l976iv'}\r\n\t\r\nTo turn on this behaviour, just set jsonrpclib.config.use_jsonclass to True. \r\nIf you want to use a different method for serialization, just set \r\njsonrpclib.config.serialize_method to the method name. Finally, if you are \r\nusing classes that you have defined in the implementation (as in, not a \r\nseparate library), you'll need to add those (on BOTH the server and the \r\nclient) using the jsonrpclib.config.classes.add() method. \r\n(Examples forthcoming.)\r\n\r\nFeedback on this \"feature\" is very, VERY much appreciated.\r\n\r\nWhy JSON-RPC?\r\n-------------\r\nIn my opinion, there are several reasons to choose JSON over XML for RPC:\r\n\r\n* Much simpler to read (I suppose this is opinion, but I know I'm right. :)\r\n* Size / Bandwidth - Main reason, a JSON object representation is just much smaller.\r\n* Parsing - JSON should be much quicker to parse than XML.\r\n* Easy class passing with jsonclass (when enabled)\r\n\r\nIn the interest of being fair, there are also a few reasons to choose XML \r\nover JSON:\r\n\r\n* Your server doesn't do JSON (rather obvious)\r\n* Wider XML-RPC support across APIs (can we change this? :))\r\n* Libraries are more established, i.e. more stable (Let's change this too.)\r\n\r\nTESTS\r\n-----\r\nI've dropped almost-verbatim tests from the JSON-RPC spec 2.0 page.\r\nYou can run it with:\r\n\r\n\tpython tests.py\r\n\r\nTODO\r\n----\r\n* Use HTTP error codes on SimpleJSONRPCServer\r\n* Test, test, test and optimize", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/downloads/ned14/jsonrpclib/jsonrpclib_ned14-0.1.4_ned14-py2.7.egg", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/joshmarshall/jsonrpclib/", "keywords": "", "license": "http://www.apache.org/licenses/LICENSE-2.0", "maintainer": "", "maintainer_email": "", "name": "jsonrpclib-ned14", "package_url": "https://pypi.org/project/jsonrpclib-ned14/", "platform": "All", "project_url": "https://pypi.org/project/jsonrpclib-ned14/", "project_urls": { "Download": "https://github.com/downloads/ned14/jsonrpclib/jsonrpclib_ned14-0.1.4_ned14-py2.7.egg", "Homepage": "http://github.com/joshmarshall/jsonrpclib/" }, "release_url": "https://pypi.org/project/jsonrpclib-ned14/0.1.4-ned14/", "requires_dist": null, "requires_python": null, "summary": "This project is an implementation of the JSON-RPC v2.0 specification (backwards-compatible) as a client library.", "version": "0.1.4-ned14" }, "last_serial": 803048, "releases": { "0.1.4-ned14": [] }, "urls": [] }