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:
[PyV8](http://code.google.com/p/pyv8/) - A python wrapper for Google V8 engine,
[Node.js](http://nodejs.org/)
Apple JavaScriptCore - Included with Mac OS X
[Mozilla SpiderMonkey](http://www.mozilla.org/js/spidermonkey/)
[Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
# 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.2 : Python 2.6.x was supported. 1.0.1 : Forgotten shell=True was added to Popen. 1.0.0 : First release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PyExecJS-1.0.2.zip.
File metadata
- Download URL: PyExecJS-1.0.2.zip
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e60aceb69d1a1bbdc04824ad4cf8ebebb93eaf79de1431b5d7145972a591919
|
|
| MD5 |
6841000f563cdf3e24031acd2142a546
|
|
| BLAKE2b-256 |
a1d02a90630b66d780c07190afade786dd9fae7369c111d909bbbddba2fae196
|