Ask HN: Pros and cons of creating a Webassembly to Python bytecode lib?

15 points by sametmax ↗ HN
A lot of noise is made about webassembly these days, and I love it. Unfortunaly, I don't think it mean we will see Python on the browser any time soon, as downloading the heavy Python runtime just for that seems overkill. Except may be if we ship microPython.

However, we could leverage it for a usage of Python in electron apps and in Node.js without RPC.

But I'm more excited about getting ride of the "compiled extensions" hell in Python.

Indeed, despite all the efforts of the community, creating the wheel standard, providing tooling, etc. installing non pure-Python libs are still a pain for new commers, albeit a lesser one. And creating wheel for a compiled extension is still much more complicated than it should be.

My skills in low level dev being very poor, I'm asking the crowd here:

- would it be possible to create a pure Python lib to translate WASM into an importable pyc file?

- what would be the result performance wise?

- would it be worth it?

My educated guess would be that you would loose performances, because you would have to translate low level data structures to high level ones. But still it would let the package manager do the following:

- try to use the compiled dist, such as a wheel. Failing that...

- try to compile the WASM code to a binary. Failing that...

- turn the code into bytecode and use the library, just in a slower way.

It would allow to write a Rust/C Python extension garantied to be easily installable on a development machine for a beginer, but can be easily turned into something fast for production.

If WASM gets popular, it also means being able to use libs from Go, D, Haskell, etc in a pretty straigforward way.

3 comments

[ 0.23 ms ] story [ 13.5 ms ] thread
I'm a bit sad there is not any answer to this but I guess this is a complicated topic.

Maybe I should bring that to the Python-idea mailing list instead.

> would it be worth it?

Nobody can tell at this point in time.. Nevertheless, regarding Python in the browser, there's Brython [0] which works, although I don't know how's using it in production..

[0] https://brython.info/

Brython is impressive. It renders quite well a lot of Python features. Even things like yield from, sets, generator.send(), dict.fromkeys, multiple inheritance and 0b1100101.

But there are several problems with brython:

- it can't render some obscure Python features. It's very hard to do a complete Python implementation. E.g: metaclass will fail.

- debugging is terrible.

- 120ko gziped to pay upfront, just to write code. No virtual dom or routing.

Interesting concept none of the less. In electron it can be interesting.