Metadata-Version: 2.1
Name: PyJSCaller
Version: 0.2.0
Summary: Run JavaScript code from Python
Home-page: https://github.com/ZSAIm/PyJSCaller
Author: ZSAIm
Author-email: zzsaim@163.com
License: MIT License
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: JavaScript

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


.. code::

	function add(a, b){
		return a + b;
	}

Supported JSEngine
====================

* `NodeJS <https://nodejs.org/>`_ - defalut
* `PhantomJS <https://phantomjs.org/>`_


Installation
===============

    $ pip install PyJSCaller


Example
=========

Usage1
~~~~~~~

.. code::

    >>> import jscaller
    >>> jscaller.eval("'Hello World!'.toUpperCase()")
    'HELLO WORLD!'

Usage2
~~~~~~~

.. code::

    >>> ctx = jscaller.compile('example.js', timeout=3)
    >>> ctx.call('add', 1, 1)
    2

Usage3
~~~~~~~

.. code::

    >>> 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
~~~~~~~~~~~~~~~~~~

.. code::

    >>> 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










