Skip to main content

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

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.1.tar.gz (10.7 kB view details)

Uploaded Source

File details

Details for the file PyJSCaller-0.2.1.tar.gz.

File metadata

  • Download URL: PyJSCaller-0.2.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/3.7.7

File hashes

Hashes for PyJSCaller-0.2.1.tar.gz
Algorithm Hash digest
SHA256 26f4b059ee93f72fbab0d26bb1261723fe599040ef300e43cd9ee2379b8b17da
MD5 51dc9fb1b265f72918c89323d9b5d316
BLAKE2b-256 7588607014d08cbdc74f3c878a8c21d2eef7f5fbe782875d689e41f66922daf5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 file

0.2.0

3 files

0.1.1

1 file

Supported by

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