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

If you're not sure about the file name format, learn more about wheel file names.

PyJSCaller-0.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

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

Hashes for PyJSCaller-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 662a2b49e8ed7a79087c36dbd510b7d18fac2bd6f64e68d09282a03c3c13c885
MD5 b51ed75c6c330f8a8b7a93342de21a08
BLAKE2b-256 a20138b0856815195a1f98701d883f0c6fbe93e8aaf2acaba5162652145d4a07

See more details on using hashes here.

Supported by

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