9 ms·
Extending web applications with WebAssembly and Python
- angelmm 3y agoYou can find all the code from this article on GitHub [0]. - [0] https://github.com/vmware-labs/webassembly-language-runtimes/tree/c6cf6e11ffaef1624108dfc9581911ed11f3f42d/python/examples/bindings/se2-bindings https://github.com/vmware-labs/webassembly-language-runtimes...
- ridruejo 3y agoOne of the aspects I find tremendously exciting about Wasm is not just the portability, security, performance, etc. but the fact that you can do this with your language of choice. Lowering the barrier to adoption without hindering some of the advanced use cases tends to work well to get developers onboard ...
- zcw100 3y agoIt's not quite as open as the language of your choice. There are a handful of popular languages available, Rust, C, C++ and a number of fringe languages like Zig, AssemblyScript, etc. You can run something like Python but it's a bit misleading because you're compiling the entire runtime to WebAssembly similar to how CheerpJ runs Java or Blazor runs .NET
- ridruejo 3y agoHow is it misleading? It is the whole point that you can compile CPython or PHP interpreters to target this as another target platform like x86 or ARM
- umvi 3y agoPython performance on wasm is going to be abysmal because you're essentially running a VM inside a VM. Other languages like rust can compile directly to wasm. Until Python can do the same it will be a second or third class citizen in wasm. Put another way, you could make one of those tier charts for WASM tooling, and if rust is in S tier, python is like C or D tier.
- pookeh 3y agoRust is not an interpreted language like Python. Your comment would make sense if Python code could be compiled into x86 or ARM assembly in the first place.
- selcuka 3y ago> Your comment would make sense if Python code could be compiled into x86 or ARM assembly in the first place. It can actually be compiled (or transpiled) into C code [1] with few limitations, so I can't see why not. It still requires libpython but it should be better than porting the whole interpreter to webassembly. [1] https://github.com/Nuitka/Nuitka https://github.com/Nuitka/Nuitka
- ridruejo 3y agoYou are not running a VM inside a VM. You are compiling to another target and modern Wasm runtimes allow AOT and JIT so performance is close to native while preserving all the other goodness of Wasm (sandbox, portability to 'weird' environments like browsers and IoT, etc)
- pininja 3y agoIs there a project to package up static python modules to run in-browser using one of their web assembly runtimes?
- robby_w_g 3y agoI think Pyodide is what you want. https://pyodide.org/en/stable/ https://pyodide.org/en/stable/
- baudaux 3y agoSounds great, I will put it in my new operating system running in the browser https://extendedmachine.com https://extendedmachine.com.
- robby_w_g 3y agoNot sure if you’re just trying to advertise your project, but I wouldn’t use Pyodide in that case. I’d personally rather use the tool linked in the OP article for something like an OS in the browser
- baudaux 3y agoIn fact it seems that WASI build environment is not supporting asynchronous syscalls. I think it will be needed for integrating Python apps in a web browser
- ereslibre 3y agoThe webassembly-language-runtimes is focused on providing WASI-based language interpreters, what would require a WASI polyfill at the browser level (https://wasi.dev/polyfill/ https://wasi.dev/polyfill/) and (https://github.com/bjorn3/browser_wasi_shim https://github.com/bjorn3/browser_wasi_shim). Pyodide is certainly another option, but is emscripten based, not based in webassembly-language-runtimes or WASI.
- samsquire 3y agoThis is awesome. Thanks for doing this. Took me a while to understand that exports are available for the wasm module to call and imports are what the wasm module can see to call.
- krishadi 3y agoThis is exciting! Does that mean that I can load a sqllite db or a duckdb onto the browser through wasm and then connect it with the python env?
- angelmm 3y agoThe Python builds from the WebAssembly language runtimes [0] project target the WebAssembly System Interfaces (WASI) [1]. It allows the Python interpreter to interact with resources like the filesystem. Many server-side Wasm runtimes supports WASI out of the box. For the browser, you need to provide a polyfill to emulate these resources like the one provided by the WASI team [2]. Regarding SQLite, these builds include libsqlite so you should be able to use it :) - [0] https://github.com/vmware-labs/webassembly-language-runtimes https://github.com/vmware-labs/webassembly-language-runtimes - [1] https://wasi.dev/ https://wasi.dev/ - [2] https://wasi.dev/polyfill/ https://wasi.dev/polyfill/
- tcper 3y agoThis py wasm runtime is not sound. Many .whl modules include binarys, obviously it will not runable. This narrow the usage.
- angelmm 3y agoThis is a work in progress effort. I saw different people working on this direction, so you can use Python libraries that includes native extensions in Wasm.
- Sytten 3y agoThis is exactly what I needed. Context is I am trying to incorporate different scripting language in our rust app so I tried RustPython and QuickJS. Its been a pain so far and it adds a lot of time to our compilation so I love the idea of being able to load a wasm python but I was missing this script to host communication part.
- angelmm 3y agoThis is great! We are constantly providing new features to the pre-built binaries we publish in this project. Happy to read it helps you :)
- ativzzz 3y agoIt's fun to see the lengths people go to avoid writing javascript