bottle_jsonrpc.py
implements JSON-RPC for Bottle in a pretty straight forward way.
import bottle_jsonrpc
jsonrpc = bottle_jsonrpc.register('/rpc')
@jsonrpc
def add(a, b):
return a + b
Alternatively you can pass an object to register()
:
class Methods(object):
def add(a, b):
return a + b
bottle_jsonrpc.register('/rpc', Methods())
All public methods (callable attributes that don't start with _
) will be exported as JSON-RPC methods.
You can also manipulate the method dictionary directly:
def add(a, b):
return a + b
jsonrpc = bottle_jsonrpc.register('/rpc')
jsonrpc.methods['add'] = add
Returns a NameSpace
object that can also be used as a decorator.
- path
Path that the client will send requests to. This will be mounted in bottle with
@post(path)
.- obj=None
All public methods (callable attributes) of the object will be exported as JSON-RPC methods.
- app=None
App to use. Defaults to
bottle.default_app()
.
- path, app
The values passed as arguments.
- methods
A dictionary of methods for lookup where name is the JSON-RPC methods name and value is a callable object (typically a function or method).
- add_object(obj)
Exports all public methods (callable attributes) of the object as JSON-RPC methods.
Should be considered experimental.
Error reporting (back to the JavaScript client) is not very good.
Released under the terms of the MIT license.
Ole Martin Bjorndalen - ombdalen@gmail.com