Run JavaScript code from Python
Project description
PyJSCaller
Run JavaScript code from Python.
PyJSCaller is a agent between Python and JavaScript making JavaScript involved in a more Python-like language.
a short example:
example.js
function add(a, b){
return a + b;
}
Supported JSEngine
Installation
$ pip install PyJSCaller
Example
Usage1
>>> import jscaller
>>> jscaller.eval("'Hello World!'.toUpperCase()")
'HELLO WORLD!'
Usage2
>>> ctx = jscaller.compile('example.js', timeout=3)
>>> ctx.call('add', 1, 1)
2
Usage3
>>> with jscaller.session('example.js') as sess:
... add, math = sess.get('add', 'Math')
... res1 = add(2, 3)
... res2 = math.PI + math.E
... sess.call(res1, res2)
...
>>> res1.get_value()
5
>>> res2.get_value()
5.859874482048838
Change JSEngine
>>> from jscaller.engine import PhantomJS
>>> PhantomJS.test()
2.1.1
>>> PhantomJS.config(timeout=10)
>>> jscaller.make(PhantomJS)
>>> jscaller.eval('1+1')
2
License
MIT license
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
PyJSCaller-0.2.1.tar.gz
(10.7 kB
view hashes)