Coder Social home page Coder Social logo

pyjscaller's Introduction

PyJSCaller

Build Status Build Status

Python 调用执行 JavaScript 代码。

PyJSCaller 是 Python 和 JavaScript 之间代理,是为了使 JavaScript 的代码调用更像是在使用 Python 一样。

一个简短的例子:


example.js

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

用法

调用方式一:

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

调用方式二:

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

调用方式三:

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

切换JS运行时引擎:

>>> from jscaller.engine import PhantomJS
>>> PhantomJS.test()
2.1.1
>>> PhantomJS.config(timeout=10)
>>> jscaller.make(PhantomJS)
>>> jscaller.eval('1+1')
2

支持的JS引擎

安装

$ pip install PyJSCaller

许可证

MIT license

更新日志

0.2.0

  • 简化使用流程。
  • 支持 Python 3.x.x。
  • 支持 Python 2.7.x。

0.1.1

  • 完全重构。

0.0.1

  • 上传代码。

pyjscaller's People

Contributors

zsaim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.