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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PyJSCaller-0.1.1-py3-none-any.whl.
File metadata
- Download URL: PyJSCaller-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
662a2b49e8ed7a79087c36dbd510b7d18fac2bd6f64e68d09282a03c3c13c885
|
|
| MD5 |
b51ed75c6c330f8a8b7a93342de21a08
|
|
| BLAKE2b-256 |
a20138b0856815195a1f98701d883f0c6fbe93e8aaf2acaba5162652145d4a07
|