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
- Host: GitHub
- URL: https://github.com/fiddlerwoaroof/jsonrpc
- Owner: fiddlerwoaroof
- Created: 2021-04-07T02:30:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-07T02:59:42.000Z (over 5 years ago)
- Last Synced: 2025-07-14T05:17:00.256Z (about 1 year ago)
- Language: Python
- Size: 851 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
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