

Running your JS code in Python - sheetjs
http://blog.sheetjs.com/post/71326534924/running-your-js-code-in-python

======
kanzure
> I suspect it would be possible to build up a wrapper that emulates the
> entire NodeJS javascript API in PyV8

[http://pyv8.googlecode.com/svn/trunk/demos/node.py](http://pyv8.googlecode.com/svn/trunk/demos/node.py)

But I think node itself can be used with pyv8 since they are both v8. There
may be some issues with the event loops but that's not an extremely hard
problem. IIRC, node-webkit (or appjs?) hacked up the node event loop with the
event loop from chromium.

Another neat pyv8 trick is this (incomplete..) commonjs implementation:

[https://github.com/flier/pyv8/blob/master/demos/commonjs/com...](https://github.com/flier/pyv8/blob/master/demos/commonjs/commonjs.py)

.. so you can import node (or other commonjs) modules into python.

Although this isn't pyv8, it's possible to get python/javascript bindings for
the webkit js environment (shared variables/functions/objects):

[https://gist.github.com/kanzure/6581415](https://gist.github.com/kanzure/6581415)

I am eager to figure out how to do a similar trick with blink or servo.

------
pmiller2
As an aside, if you want to handle XLS files from Python, you should use the
xlrd, xlwt, and xlutils modules (available at [http://python-
excel.org](http://python-excel.org) ).

~~~
sheetjs
The reason I brought [https://github.com/SheetJS/js-
xls](https://github.com/SheetJS/js-xls) to python is precisely because xlrd
couldn't handle many of my XLS files

------
edward
You don't need to escape slashes if you use a regexp string like this: r'no
need to escape slash\n'.

~~~
swinglock
It's called a "raw string" rather than "regexp string", though that is the
common use for it.

~~~
bobbyi_settv
The other common use is Windows paths since traditionally backslashes are used
as the delimiter. (Obviously hardcoded paths in code aren't generally a great
idea, but that's another story.)

------
artlogic
I've been working with PyV8 for nearly 3 years, and while it's an impressive
achievement, I've had to start using a custom version to maintain stability.
One of the major issues with PyV8 currently is that is builds against V8's
master branch, as opposed to a known stable version. This means it breaks from
time to time due to the speed of V8 development. There are also not releases
of PyV8 per se. It's been v1.0 for quite awhile now, despite a year or more
worth of fixes since the bump from v0.9 to v1.0.

I would LOVE to see tighter integration of Python and JavaScript, but if you
are planning on using PyV8 in any production code (as I am), I would think
very carefully about it.

~~~
malexw
I've been trying to integrate PyV8 into our production environment and have
been experiencing a lot of trouble with it as well. There are two main issues
that are killing it for us - the first is the challenge of building it, as you
mention. There's also a difficult-to-reproduce segfault issue that crops up
sometimes when V8's GC runs.

Is your custom version published online anywhere? It would be great to build
off the stability work you already seem to have done.

~~~
artlogic
I've noticed the GC problem that you mention as well. To me it seems very much
that when objects travel between V8 and Python is when problems begin to crop
up. Sadly, I have yet to be able to fix this. I believe this issue captures it
most concisely:
[https://code.google.com/p/pyv8/issues/detail?id=193](https://code.google.com/p/pyv8/issues/detail?id=193)

I'll have to see about publishing my work publicly, as I don't explicitly own
it. My biggest piece of advice is to always build from the latest branched
version of v8, rather than the trunk. Right now, that would be 3.23. The
branched version tends to be a bit more stable than the trunk. Sadly, since
the PyV8 maintainer works from the trunk, I've often had to build a few revs
back to get things to compile if there was a major structural v8 change.

If you'd be willing to share the details of your build environment, I can see
if my work is even applicable and go about getting the permission to publish
what I've done.

BTW, I want to be clear that in no way am I disparaging the PyV8 maintainer.
He's been very responsive and helped fix some problems that would have taken
me weeks to fix on my own. The project simply isn't focused on stability at
the moment.

------
dave1010uk
There is also a PHP extension to use the V8 engine:

[http://www.php.net/manual/en/book.v8js.php](http://www.php.net/manual/en/book.v8js.php)

------
niix
Awesome. I think the last part of your blog post is worth doing some research
on, could be successful.

------
pplante
fun yak shaving exercise. is there a practical reason why you might want to do
this?

~~~
philsnow
I wrote a chess playing service to teach myself app engine a while back, and I
wanted to verify valid moves on the client before sending them to the server,
as well as verify them on server.

I didn't want to write that logic in both javascript (for client) and python /
go (for server) and create a suite of tests to attempt to verify that the
server and client logic was equivalent.

I looked around for ways to either run (minimal _) python functions in
javascript or else run (minimal_ ) javascript functions in python, but at the
time didn't come up with anything workable (within the constraints of using
GAE).

* no classes, objects, function attributes, prototypes, etc etc necessary, just chess move validity checking

------
notastartup
This could be the beginning of something great for Python. Imagine if all the
node.js modules became available on the Python. I'd love to use Python over
Javascript.

