37 comments

[ 0.20 ms ] story [ 56.1 ms ] thread
OK this looks promising:

  brew install wasmer
  wasmer run python/python@=0.2.0
Running that gave me a Python 3.12 shell apparently running entirely in a WebAssembly sandbox!

I've been trying to find a robust, reliable and easy way to run a Python process in WebAssembly (outside of a browser) for a few years.

I tried to understand what is "Wasmer Edge" but couldn't. They say on the front page "Make any app serverless. The cheapest, fastest and most scalable way to deploy is on the edge." and it seems like I can upload the source code of any app and they will convert it for me? Unlikely so.

Also it says "Pay CDN-like costs for your cloud applications – that’s Wasmer Edge." and I don't understand why I need to pay for the cloud if the app is serverless. That's exactly the point of serverless app that you don't need to pay for the servers because, well, the name implies that there is no server.

Does your solution support interop between modules written in different languages? I would love to be able to pass POD objects between Python and JS inside the same runtime.
I actually want browsers to support other languages natively.

Brendan Eich ( the creator of JavaScript) was kind enough chime in that it would be impossible for variety of reasons.

Obviously he knows more about this than me, but I think Google could put Dart in there if they really wanted.

WebAssembly is pretty close though.

Wondering how this compares to e.g. Jep for Java/Python interoperability (https://github.com/ninia/jep).

Would be way more exciting if it could _compile_ Python to Wasm (or does it?).

wait why is this the first time I saw something like this!

I remember when I was in 6th grade wanting to make some minecraft mods but didn't want to learn java for it and wanted something like python.

I also remember a video that did something like that but it was highly limited or smth iirc.

Could this be used to create a minecraft plugin in python?

Edit: Damn, there is this pyspigot thing which seems really fascinating..

https://pyspigot-docs.magicmq.dev/#getting-started

Tbh, nowadays I would prefer writing minecraft mods in kotlin but the pyspigot code is also definitely really interesting!

How does WASM replace/implement language specific features like goroutines or Python's asyncio loop, or the specifics of each language's GC?
FFI support (like they have) is essential for any alternative Python to be worthwhile because so much of what makes Python useful today is numpy and keras and things like that.

That said, there is a need for accelerating branchy pure-python workloads too, I did a lot of work with rdflib where PyPy made all the difference and we also need runtimes that can accelerate those workloads.

Are dependencies easier to install or does it work only for packages that have pure wheel support?
Hmm, I tried it out.

> wasmer app create --template=static-website

gets you from empty folder to initialized template and deployed static website in like 10 seconds when logged in.

Pretty nice.

Would it be possible to make it work on iOS or android? I always missed better support of python on mobiles. In the past used PythonKit rapid prototype and interop with Swift but had limited set of modules. Wish to use this in react native for interop between js and python
JuputerLite also does this. Uses local storage and Pyodide kernel (python on wasm). It has a special version of pip, and wasm versions of a lot of libraries which usually use native code (numpy etc). Super impressive.

https://jupyter.org/try-jupyter/lab/

Nice, but every time I look into WASM I have to wonder if containers and/or lite weight VMs wouldn’t be simpler and have less restrictions. We seem to have forgotten about microkernels and custom runtimes (like the various Erlang ones) as well…

Still, that close to native Python is an interesting place to be.

WASM runs in the browser which is why it receives so much consideration (rightfully so).
VMs are much more complex that running a wasm process.
Are we at the point where I can store arbitrary scripts in a sql database and execute them with arguments, safely in a python sandbox from a host language that may or may not be python, and return the value(s) to the caller?

I'd love to implement customer supplied transformation scripts for exports of data but I need this python to be fully sandboxed and only operate on the data I give it.

> where I can store arbitrary [python] scripts in a sql database and execute them with arguments

Please no :sob:

To be clear "fast" means "almost as fast as native Python", not "actually fast". Impressive achievement anyway.
I'm not sure I understand correctly: is it a new serverless offering competing with the likes of vercel and fly.io, but with a different technology and pricing strategy? And the wasm container means that I can deploy my streamlit of FastAPI ETL apps without the Docker overhead or slowness of streamlit cloud?
Would the app have outbound network access to do some Python scheduling stuff that involves pulling from another endpoint?

Eg something like this flask-based app? (Yes the code is shit, I’m just a sysadmin learning Python with some AI support at that time).

https://github.com/jgbrwn/my-upc/blob/main/app.py

Also, if wasmer supports Starlette, I assume it would support FastHTML (web framework that uses Starlette under the hood) ?

How would i use numpy from javascript using this?
this rocks, using python as an embedded scripting language is Easy and Cool but also Dangerous and Evil, feel like this could make it less dangerous.
> Now, you can run any kind of Python API server, powered by fastapi, django, flask, or starlette, connected to a MySQL database automatically when needed

I assume this is targeting the standalone WebAssembly use case, we're not...running MySQL in browsers right?

How are you going to sandbox WebAsm when it's not even defined?
I am so excited about python edge supported by wasm because I used python on cloudflare worker but there are so many limitations just simple pure python code supported.
Isn't it just Python built with Emscripten?
Very cool!

I’ve been looking at using lua for something like this: basically, users will be able to program robots in my lab (biotech) to do things, and I need a scripting language I can easily embed and control the runtime of in the larger system.

Lua is theoretically better in… almost every way, except everyone in bio uses python. So it could allow more easy modification of LLM generated scripts (not worried about the libraries because I mostly want to limit them: the scripts are mainly to just run robots, and you can have them webhook out if you need complicated stuff)

My question would be: would running a python sandbox vs a lua sandbox actually be appreciably better? Not sure yet, but will have to investigate with this new package (since it has Go bindings!)

Curious given you looked at both why you considered Lua to be better. I'd like to use Lua to teach freshmen and I need some arguments as to why it's better than Python.