
Show HN: Nice-looking Python bindings to V8 - tbodt
https://github.com/tbodt/v8py
======
andersriutta
This allows for calling synchronous JS functions from Python but not async JS
functions, right? PyExecJS [0] also doesn't work with async JS, but Js2Py [1]
might.

[0]
[https://github.com/doloopwhile/PyExecJS/issues/20](https://github.com/doloopwhile/PyExecJS/issues/20)
[1]
[https://github.com/PiotrDabkowski/Js2Py/blob/05e77f0d4ffe91e...](https://github.com/PiotrDabkowski/Js2Py/blob/05e77f0d4ffe91ef418a93860e666962cfd193b8/tests/includes/timer.js)

~~~
unusximmortalis
"Write Python APIs, then call them from JavaScript using the V8 engine"

~~~
andersriutta
The author says it works both ways [0] (e.g., this test [1]), but I don't see
a test with Python calling async JS.

[0]
[https://news.ycombinator.com/item?id=14596163](https://news.ycombinator.com/item?id=14596163)
[1]
[https://github.com/tbodt/v8py/blob/3c727584df684540ce30f2572...](https://github.com/tbodt/v8py/blob/3c727584df684540ce30f257201cb648f2c41e7a/tests/test_convert.py)

------
d33
Nice! I hadn't tested it yet, but I remember trying to run V8 in Python and it
was a real mess - I think that even building it was problematic. I might use
this project one day. Did you compare your bindings to alternatives?

~~~
unusximmortalis
If I get it correctly this is V8Py meaning it allows javascript (V8) to call
Python scripts, not the other way around.

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

~~~
Twirrim
That's what I took that phrase to mean, but if you look at the example in the
read me, it appears to be the other way around. Writing python, defining a
method, then wrapping that method in a V8 context and running it from within
python.

~~~
tbodt
It's both!

------
gkya
Can anybody tell what's going on with the v8py/kappa.{cpp,h} files?

~~~
RandomInteger4
"// Meme header file. Every project should have one of these. Kappa Kappa
Kappa"

~~~
jszymborski
I'm a fan of humour in comments, easter-eggs, etc... but for no good reason,
this bothers me.

~~~
nerdponx
It's forced humor, and a misapplied un-funny version of mildly funny nerd
humor at that. It gives me the same kind of chills that I get from people who
wear "I <3 bacon" type t-shirts.

~~~
dguaraglia
In Spanish we have an expression for the way you feel: "vergüenza ajena",
which loosely translates to "feeling the embarrassment someone else should
feel for their actions." It's pretty nifty, if not very catchy :P

~~~
roywiggins
Apparently it's "fremdscham" in German.

~~~
dguaraglia
See, that's catchier! Now we are talking.

------
startupdiscuss
I might be missing something, but can you show an example of calling the API
from javascript?

You seem to be writing it in python and then calling it from within python in
the example.

~~~
tbodt
context.eval runs JavaScript, which in the example is calling the Python API.
expose adds an object into the global JavaScript space.

------
binora
Silly question. Can I use this to interact with a machine learning model
written in python from javascript on react native ? It'd be great if someone
could point out the feasibility/limitations

~~~
tbodt
No, it's for running javascript from a python program and allowing that
javascript to call python code.

------
elmigranto
Wouldn't it be more performant and less awkward to compile python to JS? Or is
it for importing JS code into your python program? Well, why don't compile JS
to Python then?

~~~
marmaduke
If JS code expects to be JITed then transpiled in Python would be quite slow.
Transpiling Python to JS is difficult and loses access to various ecosystems
e.g. scientific Python.

Having the two runtimes coupled seems to be the ideal way to run both
languages in the same process.

------
droidist2
Interesting. Could this be used to use SciPy stuff from JavaScript?

------
jdc0589
there are a LOT of Sublime Text plugins that depend on this.

EDIT: nevermind. i'm dyslexic

~~~
tbodt
are you thinking of pyv8?

~~~
jdc0589
damn, yep. good call.

