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.0.tar.gz
(10.6 kB
view hashes)
Built Distributions
PyJSCaller-0.2.0-py3.7.egg
(25.4 kB
view hashes)
PyJSCaller-0.2.0-py3-none-any.whl
(12.5 kB
view hashes)
Close
Hashes for PyJSCaller-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edbfd859ec335a6e3a9ffbce178945439f9e0d872ca18b1a110f399685fc70e8 |
|
MD5 | c2a01f5a7bb09a63470e00d6dd2d937e |
|
BLAKE2b-256 | f650bde7302070379df13298f37cd11144817114713f221c20ea8906d05d3ae8 |