Documentation for pulsar 0.9.2. For development docs, go here.
Asynchronous WSGI Remote Procedure Calls middleware. It implements a JSON-RPC server and client. Check out the json-rpc tutorial if you want to get started quickly with a working example.
To quickly setup a server:
class MyRpc(rpc.JSONRPC):
def rpc_ping(self, request):
return 'pong'
class Wsgi(wsgi.LazyWsgi):
def handler(self, environ=None):
app = wsgi.Router('/',
post=MyRpc(),
response_content_types=['application/json'])
return wsgi.wsgiHandler([app])
if __name__ == '__main__':
wsgi.WsgiServer(Wsgi()).start()
MyRpc
handles the requestsRouter
which handle only post
requests with content type application/json
.pulsar.apps.rpc.handlers.
RpcHandler
(subhandlers=None, title=None, documentation=None)[source]¶Base class for classes to handle remote procedure calls.
serve_as
= 'rpc'¶Prefix for class methods providing remote services. Default: rpc
.
separator
= '.'¶HTTP method allowed by this handler.
parent
¶The parent RpcHandler
or None
if this
is the root handler.
root
¶The root RpcHandler
or self
if this
is the root handler.
putSubHandler
(prefix, handler)[source]¶Add a sub RpcHandler
with prefix prefix
.
Parameters: |
|
---|
getSubHandler
(prefix)[source]¶Get a sub RpcHandler
at prefix
.
pulsar.apps.rpc.handlers.
rpc_method
(func, doc=None, format='json', request_handler=None)[source]¶A decorator which exposes a function func
as an rpc function.
Parameters: |
|
---|
pulsar.apps.rpc.jsonrpc.
JSONRPC
(subhandlers=None, title=None, documentation=None)[source]¶An RpcHandler
for JSON-RPC services.
Design to comply with the JSON-RPC 2.0 Specification.
JSON-RPC is a lightweight remote procedure call protocol designed to be simple. A remote method is invoked by sending a request to a remote service, the request is a single object serialised using JSON.
pulsar.apps.rpc.jsonrpc.
JsonProxy
(url, version=None, data=None, full_response=False, http=None, timeout=None, **kw)[source]¶A python Proxy class for JSONRPC
Servers.
Parameters: |
|
---|
Lets say your RPC server is running at http://domain.name.com/
:
>>> a = JsonProxy('http://domain.name.com/')
>>> a.add(3,4)
7
>>> a.ping()
'pong'
pulsar.apps.rpc.mixins.
PulsarServerCommands
(subhandlers=None, title=None, documentation=None)[source]¶Useful commands to add to your JSONRPC
handler.
It exposes the following functions:
rpc_server_info
(*args, **kwargs)[source]¶Return a dictionary of information regarding the server and workers.
It invokes the extra_server_info()
for adding custom
information.
rpc_functions_list
(request)[source]¶List of (method name, method document) pair of all method exposed
by this JSONRPC
handler.
extra_server_info
(request, info)[source]¶An internal method.
Used by the rpc_server_info()
method to add additional
information to the info dictionary.