I Use This!
Analyzed 4 days ago. based on code collected 4 days ago.

Project Summary

Python-SpidermonkeyThis Python module allows for the implementation of Javascript? classes, objects and functions in Python, as well as the evaluation and calling of Javascript scripts and functions. It borrows heavily from Claes Jacobssen's Javascript Perl module, which in turn is based on Mozilla's PerlConnect Perl binding.

This code was originally written by John J. Lee in 2003. After being unmaintained for a number of years, it was subsequently picked up by Atul Varma in 2008.

TutorialThe first thing you'll want to do is create a Runtime instance, which encapsulates a JSRuntime object from Spidermonkey. From the JSAPI User Guide:

A JSRuntime, or runtime, is the space in which the Javascript variables, objects, scripts, and contexts used by your application are allocated. Every JSContext and every object in an application lives within a JSRuntime. They cannot travel to other runtimes or be shared across runtimes. Most applications only need one runtime.

Creating the Runtime instance is straightforward:

>>> from spidermonkey import Runtime
>>> rt = Runtime()You'll then want to use the Runtime to create a Contextinstance, which encapsulates a JSContext object from Spidermonkey. From the JSAPI User Guide:

A JSContext, or context, is like a little machine that can do many things involving Javascript code and objects. It can compile and execute scripts, get and set object properties, call Javascript functions, convert Javascript data from one type to another, create objects, and so on.

In Firefox, for instance, a different context is used for each webpage you view. A separate context is even created for each physical browser window, because much of Firefox's functionality is actually written in Javascript. Contexts can have their own security policies associated with them, and objects can be shared between multiple contexts.

Creating a context in Python-Spidermonkey is done like so:

>>> cx = rt.new_context()Now that you've got a context, you can do lots of things, like evaluating arbitrary Javascript expressions and using their results in Python code:

>>> cx.eval_script("1 + 2") + 3
6We can create classes in Python and access them in Javascript, too:

>>> class Foo:
... def hello(self):
... print "Hello, Javascript world!"
>>> cx.bind_class(Foo, bind_constructor=True)
>>> cx.eval_script("var f = new Foo(); f.hello();")
Hello, Javascript world!We can also get back objects from Javascript and use them:

>>> f = cx.eval_script("f;")
>>> f.hello()
Hello, Javascript world!LimitationsThe module currently has a number of features that still need to be implemented. For instance, it's not yet possible to call a function defined in Javascript:

>>> cx.eval_script("function foo(x) { return x + 1; }; foo;")
{'prototype': {}}Errors in Javascript code also don't produce particularly helpful tracebacks:

>>> cx.eval_script("3 + undefinedVariable")
Traceback (most recent call last):
JSError: can't evaluate Javascript scriptInstallationNote that at present, installation has only been tested on OS X and 64-bit Ubuntu Linux; support for Windows is forthcoming.

At present, you'll need a C compiler on your system to install this extension, as well as the Pyrex package.

Check out the Python-Spidermonkey module from the SVN repository. From the root of your checkout, run: python setup.py buildDon't worry about the compiler warnings. Then, with appropriate permissions, run:
python setup.py installTestingThe module has a test suite. Just run:

python test.pyNote that one of the tests currently prints out a Javascript error message. This isn't a test failure (though it is a bug).

AcknowledgementsThanks 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.


javascript python

In a Nutshell, python-spidermonkey...

GNU General Public License v2.0 or later

Commercial Use



Place Warranty



Hold Liable


Distribute Original

Disclose Source

Include Copyright

State Changes

Include License

These details are provided for information only. No information here is legal advice and should not be used as such.

Project Security

Vulnerabilities per Version ( last 10 releases )

There are no reported vulnerabilities

Project Vulnerability Report

Security Confidence Index

Poor security track-record
Favorable security track-record

Vulnerability Exposure Index

Many reported vulnerabilities
Few reported vulnerabilities

Did You Know...

  • ...
    use of OSS increased in 65% of companies in 2016
  • ...
    by exploring contributors within projects, you can view details on every commit they have made to that project
  • ...
    nearly 1 in 3 companies have no process for identifying, tracking, or remediating known open source vulnerabilities
  • ...
    data presented on the Open Hub is available through our API
About Project Security


2 Other

30 Day Summary

Jan 3 2023 — Feb 2 2023

12 Month Summary

Feb 2 2022 — Feb 2 2023


Be the first to rate this project
Click to add your rating
Review this Project!