Alright, I know it hasn’t been more than an hour since I last posted about this, but I decided to solve this problem myself.
If there’s a better solution out there, I’d be glad to hear it, but here’s my version 0.1 attempt to make this work: http://www.alloscomp.com/bitcoin/btcjsonrpc.pys
Let me know if you like it, hate it, or see any obvious flaws with it. There’s some getting started docs in the source, but here’s the code of the test suite: Code: from btcjsonrpc import Service s = Service() print ‘preparing getbalance; id:‘,s.getbalance() # Each call returns its ID so you can find it later in the results print ‘preparing getdifficulty; id:‘,s.getdifficulty() print ‘preparing listreceivedbyaddress; id:‘,s.listreceivedbyaddress(10000) # Call with a parameter print ‘preparing getbalance; id:‘,s.getbalance(id=‘getbalance 2’) # You can also specify your own ID print ‘\nexecuting call\n\nresults:’ results = s() # Get the results by calling the Service object for id,value in results.iteritems(): print id,value # If you’d prefer to work directly with the JSON responses instead of a dict of IDs, then access the list Service.responses. print ‘\njson responses’ print s.responses
And here’s the output, including the docstr: Code:$ ./btcjsonrpc.py Socket-based, Bitcoin-compatible JSON-RPC v1.0 client. By: Eric Swanson (http://www.alloscomp.com/bitcoin) Version 0.1, July 21, 2010 Don’t use this for one-off request->response pairs. Use something like the reference python-jsonrpc library, or urllib2 + json. This client is hackish, but it works for me (and has sped up my JSON-RPC accesses tremendously).
For details of WHY exactly I felt the need to redo python-jsonrpc using a raw socket, check out the follow forum post: topic 528
Usage is fairly straightforward, and a code sample can be found below the library code (in the if name==‘main’ clause).
preparing getbalance; id: jss-1 preparing getdifficulty; id: jss-2 preparing listreceivedbyaddress; id: jss-3 preparing getbalance; id: getbalance 2
executing call
results: jss-2 181.543289364 jss-3 ] getbalance 2 2345.94 jss-1 2345.94
json responses [{u’id’: u’jss-2’, u’result’: 181.54328936405051, u’error’: None}, {u’id’: u’jss-3’, u’result’: ], u’error’: None}, {u’id’: u’getbalance 2’, u’result’: 2345.9400000000001, u’error’: None}, {u’id’: u’jss-1’, u’result’: 2345.9400000000001, u’error’: None}]