Here we have the documentation for the pyrpc module.

It should be noted that a PyRPC request message looks somewhat like the following:

{'req':'execute', 'data':data}

where data is a string holding a function call to execute (e.g., 'DoBlah(1, 2, 3)'). The function call represented by this string must be of a method which is contained in the specified action_class (more on that below).

The data returned by a PyRPC call is contained in a message of the following form:

{'res':'response', 'data':data}

where data is a string representing a Python object or data structure returned by the method executed.

class SocketPyRPCServer(BasePyRPCServer)

This is the TCP socket version of our PyRPC server. It listens on a specified port and host, handling connections as they come. Note that BasePyRPCServer is not to be called from user code.

While it should work, it has not received the same extensive testing as has mod_pythonPyRPCServer.

SocketPyRPCServer.__init__(action_class, port, host)

Listens for connections on address (host, port). action_class is a class (without an __init__ method) containing methods which can be executed as actions.

class mod_pythonPyRPCServer(BasePyRPCServer)

The mod_python/HTTP version of our PyRPC server, and the more useful version, I believe.


Sets a copy of the HTTP request object passed. Must be called when class is used.

mod_pythonPyRPCServer.handle(action_class, mesg)

This is the method which handles HTTP PyRPC calls. action_class is a class (without an __init__ method) containing methods which are executable by PyRPC calls. mesg is the PyRPC message to handle.

It is recommended to create a mod_python-mapped URL for PyRPC use. To do so, simply copy the following function into the file:

def handler(req, request=None, data=None):
	if request <> None and data <> None:
		rdict = {'req':'%s' % request, 'data':'%s' % data}
		mod_pythonPyRPCServer(req).handle(RPC_methods, rdict)

where RPC_methods is obviously the action class.

To use it, simply call the URL (using XMLHttpRequest() from JavaScript, or otherwise from other languages). A sample request to call a function Blah with arguments 1 and 2 could use a URL as follows:

http://server.fake/handler?request=execute&data=Blah(1, 2)

For more examples, see the tutorial-blog-1.0 demo package.