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;
...     }
... """)
>>> ctx.call("add", 1, 2)
3

Supported runtimes

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

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

Installation

$ pip install PyExecJS

or

$ easy_install PyExecJS

Details

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")
3
>>> import execjs.runtime_names
>>> jscript = execjs.get(execjs.runtime_names.JScript)
>>> jscript.eval("1 + 2")
3
>>> import execjs.runtime_names
>>> node = execjs.get(execjs.runtime_names.Node)
>>> node.eval("1 + 2")
3

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.

License

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.

Changelog

1.5.0

  • Eased version requirement for six.

1.4.1

  • Fixed arguments of module-level functions.

  • Fixed bug of execution with pipe.

  • Fixed wrong excption is raised.

1.4.0

  • Fixed required libraries.

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

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

1.3.1

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

1.3.0

  • Added cwd argument.

1.2.0

  • Supported Python 3.5

  • Supported Nashorn(Java 8 JavaScript engine) as runtime

  • Dropped support for Python 2.6 and 3.2

1.1.0

  • Supported Python 3.4

  • Supported SlimerJS as runtime

  • Supported PhantomJS as runtime

  • Fixed JScript runtime on Windows 8

1.0.5

  • Supported Python 3.3

  • Fixed file handle leaking

  • Fixed issue with passenger-nginx-4.0

1.0.4

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

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 Distribution

PyExecJS2-1.6.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

PyExecJS2-1.6.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file PyExecJS2-1.6.1.tar.gz.

File metadata

  • Download URL: PyExecJS2-1.6.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.7

File hashes

Hashes for PyExecJS2-1.6.1.tar.gz
Algorithm Hash digest
SHA256 bf8edafa419ff988e61e30ac9946eb3a7c066a1ec07d0c5b0b82b56f16b99050
MD5 1ae2fd7cae8c1c8ced2802ce82afc02b
BLAKE2b-256 4806afa6c5154d1789f1dd349cdd00299671e6e0050741f6dd605b1fbc76d6b8

See more details on using hashes here.

File details

Details for the file PyExecJS2-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: PyExecJS2-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.7

File hashes

Hashes for PyExecJS2-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d46616ca522a228ebc3c5eb3744232abdf78b2abaa0db5ede0d96219a3af778
MD5 596d8925db318f254e334413d4d8b5ec
BLAKE2b-256 f4ad9a94f4a5faf4aa8098ac0efee65dd269a028c894f6e0277a6d81e61c8f74

See more details on using hashes here.

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