SourceForge.net Logo

python-spidermonkey

I abandoned this module at birth; now Atul Varma has begun to work on it. If you're interested in this module, visit his python-spidermonkey project page.

Python/JavaScript bridge module, making use of Mozilla's spidermonkey JavaScript implementation. Allows implementation of JavaScript classes, objects and functions in Python, and evaluation and calling of JavaScript scripts and functions respectively. Borrows heavily from Claes Jacobssen's Javascript Perl module, in turn based on Mozilla's 'PerlConnect' Perl binding.

Example of a few of the features:

from spidermonkey import Runtime
rt = Runtime()
cx = rt.new_context()

class foo:
    def hello(self):
        print "Hello, JavaScript world!"

cx.bind_class(foo, bind_constructor=True)
f = cx.eval_script("""var f = new foo();
f.hello();
f; // script return value
""")
print f  # script return value
f.hello()

def repeat(x): return x*2
cx.bind_callable("repeat", repeat)

print cx.eval_script("""
var r = ["foo", {"bar": 2.3, "spam": [1,2,3]}];
repeat(r);
""")

Python 2.3 and spidermonkey 1.5 are required (earlier versions may work, but are untested). Currently Pyrex is required to build it (probably this won't stay a requirement - I will just include the C file that results from the Pyrex compilation).

Thanks to Brendan Eich for help with several spidermonkey issues (and for all his Mozilla work), and to Erwin on the freenode #c IRC channel for gdb tips &c.

Download

For installation instructions, see the INSTALL file included in the distribution.

Development release. This is the first alpha release: there are known bugs, and interfaces may change.

Note: the name has changed (from spidermonkey to python-spidermonkey, to avoid any confusion of wrapper and wrapee), but the code is identical (except for a few comment / doc tweaks, maybe).

See also

PyXPCOM (see also here).

PyKDE (see also KJS).

FAQs

I prefer questions and comments to be sent to the mailing list rather than direct to me.

John J. Lee, Jun 2008.