js调用python接口_V8Py 使用V8引擎从JavaScript中调用Python API

V8Py

Write Python APIs, then call them from JavaScript using the V8 engine.

>>> from v8py import Context

>>> context = Context()

>>> def print_hello():

... print 'Hello, world!'

>>> context.expose(print_hello)

>>> context.eval('print_hello()')

Hello, world!

>>> class Greeter(object):

... def greet(self, thing):

... print 'Welcome, {}!'.format(thing)

>>> context.expose(Greeter)

>>> context.eval('g = new Greeter()')

>>> context.eval('g.greet("V8Py")')

Welcome, V8Py!

That kind of thing.

Almost everything you'd expect to work just works, including:

Functions

Classes (including old style classes, because I can)

Inheritance (from the last base class, other base classes are treated as mixins)

Data descriptors

Static methods and class methods

Exceptions (they even subclass from Error!)

Support

Linux, Mac is supported for both python2 and python3. Windows is also supported, but for python3 only.

Installation

$ pip install v8py

Heads up: it'll be stuck at "Running setup.py install for v8py" for literally hours. It's downloading and building V8, which is a really big program. If you want to contribute scripts for Travis CI to build and upload wheels for Mac/Linux, please do so.

Misc

There is no documentation of any of this yet. No docstrings. The best place to look to find out how to use it is the tests.

I'm writing this so I can create a really lightweight special-purpose webdriver (no visual rendering, no asynchronous XHRs), and I need some way of implementing the DOM in Python. So there will definitely be enough functionality for that.

If you'd like to use it for something else, by all means go ahead, but you may find something that doesn't quite "just work", or works kind of strangely, or just stuff I forgot to test. If you find anything, please submit an issue. Or, even better, send a pull request.

Last but not least, don't forget to

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5361792532305468616e6b732d212d3145414544422e737667

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值