Skip to main content

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


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)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page