I basically want to be able to:

  • Write a few functions in python (with the minimum amount of extra meta data)
  • Turn these functions into a web service (with the minimum of effort / boiler plate)
  • Automatically generate some javascript functions / objects for rpc (this should prevent me from doing as many stupid things as possible like mistyping method names, forgetting the names of methods, passing the wrong number of arguments)



def hello_world():
    return "Hello world"


<!-- This file is automatically generated (either dynamically or statically) -->
<script src=""> </script> 
$('#button').click(function () {
     hello_world(function (data){ $('#label').text(data)))

A bit of research has shown me some approaches that come close to this:

  • Automatic generation of json-rpc services from functions with a little boiler plate code in python and then using jquery and json to do the calls (still easy to make mistakes with method names - still need to be aware of urls when calling, very irritating to write these calls yourself in the firebug shell)

  • Using a library like soaplib to generate wsdl from python (by adding copious type information). And then somehow convert this into javascript (not sure if there is even a library to do this)

But are there any approaches closer to what I want?

No correct solution


Yes there is, there is Pyjamas. Some people bill this as the "GWT for Python"

It looks like using a javascript XML RPC client (there is jquery plugin for this) together with an XML RPC server is a good way to go.

The jquery plugin will introspect your rpc service and will populate method names make it impossible to mis type the name of a method call without getting early warning. It will not however test the number of arguments that you pass, or their type.

There doesn't seem to be the same support for introspection on json rpc (or rather there doesn't seem to be a consistent standard). This approach can also be used with django.

I've put together some example code and uploaded it here (I hope that linking to one's blog posts isn't considered terrible form - a brief search of the internet didn't seem to suggest it was)...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow