Skip to main content

Run JavaScript code from Python

Project description

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, then returns the result to you as a Python object.

A short example:

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

Of course, you can pick particular JavaScript runtime by get() function:

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

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)'

PyExecJS supports these runtimes:

# Installation

$ pip install PyExecJS

or

$ easy_install PyExecJS

# License

Copyright (c) 2012 Omoto Kenji. Copyright (c) 2011 Sam Stephenson and Josh Peek.

Released under the MIT license. See LICENSE for details.

#Changes 1.0.3 : Javascript sources were embeded in __init__.py. ‘which’ command were reimplemented by pure python. 1.0.2 : Python 2.6.x was supported. 1.0.1 : Forgotten shell=True was added to Popen. 1.0.0 : 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 Distributions

PyExecJS-1.0.3.zip (12.7 kB view details)

Uploaded Source

PyExecJS-1.0.3.tar.gz (8.6 kB view details)

Uploaded Source

File details

Details for the file PyExecJS-1.0.3.zip.

File metadata

  • Download URL: PyExecJS-1.0.3.zip
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyExecJS-1.0.3.zip
Algorithm Hash digest
SHA256 7eeb0515a8b18a56dbf765d96c53ab1a4cd31b80fc368aa927ec0e1dd8b16b2b
MD5 ab7a4a1bb6f8a09229a92e7bf39f250a
BLAKE2b-256 74a7aff0f38dfcb5ddb3cd676a8ed0ccf46f6425edc953700a780ca971c4a037

See more details on using hashes here.

File details

Details for the file PyExecJS-1.0.3.tar.gz.

File metadata

  • Download URL: PyExecJS-1.0.3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PyExecJS-1.0.3.tar.gz
Algorithm Hash digest
SHA256 ced69a725acc5fb22ede0abd178fa4d9a465142b39f1c6c665519b6076dd9e00
MD5 f3e0ed3bd3df2918d5203fb26d3c2af2
BLAKE2b-256 24ecf27c21c598e85e63a3cf5039dcd485a85c6ce80a41d85fb37b8afafc0890

See more details on using hashes here.

Supported by

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