Skip to main content

Run JavaScript code from Python

Project description

PyExecJS (EOL)

End of life

This library is no longer maintananced. Bugs are not be fixed (even if they are trivial or essential).

We suggest to use other library or to make a fork.

Run JavaScript code from Python.

PyExecJS is a porting of ExecJS from Ruby. PyExecJS automatically picks the best runtime available to evaluate your JavaScript program.

A short example:

>>> import execjs
>>> execjs.eval("'red yellow blue'.split(' ')")
['red', 'yellow', 'blue']
>>> ctx = execjs.compile("""
...     function add(x, y) {
...         return x + y;
...     }
... """)
>>>"add", 1, 2)

Supported runtimes

First-class support (runtime class is provided and tested)

Second-class support (runtime class is privided but not tested)


$ pip install PyExecJS


$ easy_install PyExecJS


If EXECJS_RUNTIME environment variable is specified, PyExecJS pick the JavaScript runtime as a default:

>>> execjs.get().name # this value is depends on your environment.
>>> os.environ["EXECJS_RUNTIME"] = "Node"
>>> execjs.get().name
'Node.js (V8)'

You can choose JavaScript runtime by execjs.get():

>>> default = execjs.get() # the automatically picked runtime
>>> default.eval("1 + 2")
>>> import execjs.runtime_names
>>> jscript = execjs.get(execjs.runtime_names.JScript)
>>> jscript.eval("1 + 2")
>>> import execjs.runtime_names
>>> node = execjs.get(execjs.runtime_names.Node)
>>> node.eval("1 + 2")

The pros of PyExecJS is that you do not need take care of JavaScript environment. Especially, it works in Windows environment without installing extra libraries.

One of cons of PyExecJS is performance. PyExecJS communicate JavaScript runtime by text and it is slow. The other cons is that it does not fully support runtime specific features.

PyV8 might be better choice for some use case.


Copyright (c) 2016 Omoto Kenji. Copyright (c) 2011 Sam Stephenson and Josh Peek. (As a author of ExecJS)

Released under the MIT license. See LICENSE for details.



  • Eased version requirement for six.


  • Fixed arguments of module-level functions.

  • Fixed bug of execution with pipe.

  • Fixed wrong excption is raised.


  • Fixed required libraries.

  • Fixed order of output of --print-available-runtimes.

  • Execute some JavaScript runtime with pipe/stdin (without temporary file).


  • Fixed --print-available-runtimes fails in Python 2.7.


  • Added cwd argument.


  • Supported Python 3.5

  • Supported Nashorn(Java 8 JavaScript engine) as runtime

  • Dropped support for Python 2.6 and 3.2


  • Supported Python 3.4

  • Supported SlimerJS as runtime

  • Supported PhantomJS as runtime

  • Fixed JScript runtime on Windows 8


  • Supported Python 3.3

  • Fixed file handle leaking

  • Fixed issue with passenger-nginx-4.0


  • Removed “import execjs” (it prevent execution of by Python 2.6)


  • Javascript sources were embeded in ‘which’ command were reimplemented by pure python.


  • Python 2.6.x was supported.


  • Forgotten shell=True was added to Popen.


  • First release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyExecJS-1.5.1.tar.gz (13.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page