An open API service indexing awesome lists of open source software.

https://github.com/fiddlerwoaroof/jsonrpc

A JSON-RPC implementation in Python
https://github.com/fiddlerwoaroof/jsonrpc

Last synced: about 1 year ago
JSON representation

A JSON-RPC implementation in Python

Awesome Lists containing this project

README

          

A JSON-RPC 2.0 implementation for Python (Python 3 now supported!)

## Getting Started
### Installing the librarary:

% python setup.py install

Alternatively, one can use the following commands from the directory which contains the 'setup.py' file.

### Start the Server:

% python -m jsonrpc.example_server
Listening on port 8007...

### Start the Client:

Python 2.7: `python -m jsonrpc `

Python 2.6: `python -m jsonrpc.__main__ `

>>> server.add(1, 2)
3

>>> server.subtract(3,2)
1

# Exceptions
>>> server.add(1, '2')
Traceback (most recent call last):
File "", line 1, in
File "jsonrpc/proxy.py", line 182, in __call__
raise JSONRPCException(resp['error'])
jsonrpc.proxy.JSONRPCException: unsupported operand type(s) for +: 'int' and 'unicode'

>>> server.batch_call( dict(add=( (1,2), {} ), subtract=( (3,2), {} )) )
[(3, None), (1, None)] # the pattern is (result, error)

# batch calls can also be done with an iterable, if you want
# to have more than one call to the same method
>>> server.batch_call( [('add', ((1, 2), {})), ('subtract', ((3, 2), {}))] )
[(3, None), (1, None)]

# Exceptions in batch calls
>>> server.batch_call( dict(add=( (1,2), {} ), subtract=( (3,'2'), {} )) )
[(3, None), (None, {u'message': u"unsupported operand type(s) for -: 'int'
and 'unicode'", u'code': 0, u'data': [u"unsupported operand type(s) for -:
'int' and 'unicode'"]})]

Made for:
http://ncmi.bcm.edu