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;
}
Usage
>>> import jscaller
>>> jscaller.eval("'Hello World!'.toUpperCase()")
'HELLO WORLD!'
>>> with jscaller.Session('example.js', timeout=3) as sess:
... add = sess.get('add')
... retval = add(add(1, 2), 2)
... sess.call(retval)
>>> retval.getValue()
5
Supported JSEngine
Installation
$ pip install PyJSCaller
More Examples
Another short example
>>> from jscaller.collect import new, String
>>> with jscaller.Session() as sess:
... string = new(String("Hello JavaScript!"))
... string.replace('JavaScript', 'Python')
... sess.call(string)
>>> string.getValue()
"Hello Python!"
Using jscaller.make() to equip other JSEngine:
>>> from jscaller.engine import NodeJS, PhantomJS
>>> PhantomJS.environ(shell=True, timeout=5)
>>> jscaller.make(PhantomJS)
>>> jscaller.eval('1+1*2/4')
1.5
You can use PhantomJS.test() to check if engine worked correctly.
>>> PhantomJS.test() # return the version number of PhantomJS
2.1.1
License
MIT license
Changelog
0.1.1
Rebuilt all.
Linux was supported.
Python 3.7.x was supported.
Python 2.7.x was supported.
0.0.1
Uploaded code.
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
PyJSCaller-0.1.1-py3-none-any.whl
(10.9 kB
view hashes)
Close
Hashes for PyJSCaller-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 662a2b49e8ed7a79087c36dbd510b7d18fac2bd6f64e68d09282a03c3c13c885 |
|
MD5 | b51ed75c6c330f8a8b7a93342de21a08 |
|
BLAKE2b-256 | a20138b0856815195a1f98701d883f0c6fbe93e8aaf2acaba5162652145d4a07 |