Pyodide: a Python distribution based on WebAssembly (github.com)

by tosh 56 comments 189 points
Read article View on HN

56 comments

[−] simonw 61d ago
Pyodide is one of the hidden gems of the Python ecosystem. It's SO good at what it does, and it's nearly 8 years old now so it's pretty mature.

I love using Pyodide to build web UIs for trying out new Python libraries. Here's one I built a few weeks ago to exercise my pure-Python SQLite AST parser, for example: https://tools.simonwillison.net/sqlite-ast

It's also pretty easy[1] to get C or Rust libraries that have Python bindings compiled to a WebAssembly wheel that Pyodide can then load.

Here's a bit of a nutty example - the new Monty Python-like sandbox library (written in Rust) compiled to WASM and then loaded in Pyodide in the browser: https://simonw.github.io/research/monty-wasm-pyodide/pyodide...

[1] OK, Claude Code knows how to do it.

[−] VagabundoP 60d ago
The who python web feels underused to be honest.

Maybe if browsers start shipping or downloading WASMs for python and others on request. And storing them for all sites going forward. Similar to how uv does it for for venvs it creates, there are standalone python version blobs.

[−] bnchrch 60d ago
At the same time it feels like the python is overused.

If I could wave a magic wand to reset any programming language adoption at this point I would choose Python over Javascript.

I think Pythons execution model, deep OO behaviour, and extremely weak guarantees have done a lot of damage to the soundness and performance of the technology world.

[−] LtWorf 60d ago
python at least won't cast numbers to strings when adding them.
[−] tracker1 59d ago
JS doesn't either... JS casts numbers to strings when adding them to a string... "2" is not a number, it's a string that contains a number character... "2" + 2 === "22" because you are appending a number to a string, the cast is implicit and not really surprising if you understand what is going on.

Even more so when you consider how falsy values work in practice (data validation becomes really easy), there are a few gotchas, but in general they are pretty easily avoided in practice. JS is really good at dealing with garbage input in ways that don't blow up the world... sometimes that's a bad thing, but in practice it can also be a very good thing. But in the end it's a skill issue regarding understanding far more than a deep flaw. Not that there aren't flaws in JS... I think Date's in particular can be tough to deal with... a string vs a String instance is another.

[−] limagnolia 60d ago
What do you mean by "extremely weak guarantees"?
[−] busfahrer 59d ago
I recently learned that with this you can run juypter notebooks in your browser:

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

Stuff like numpy seems to just work

[−] iamcreasy 60d ago
How do you call those C/Rust libraries compiled from to webassembly from Python/Pyodide?
[−] simonw 60d ago
You have to turn them into WebAssembly wheels, then you can import them as if they were regular Python modules.
[−] joezydeco 60d ago
Could you share the UI repo? This is really interesting stuff.
[−] wiseowise 60d ago
Serious question: why would you use Python on the web? Unless you have some legacy code that you want to reuse. Performance is somehow worse than CPython, C-extensions are missing, dev experience is atrocious.
[−] screamingninja 60d ago
https://marimo.app/

A reactive notebook for Python that runs in browser, powered by Pyodide. I have been using it extensively for teaching Python to non-STEM students that do not need the added friction of navigating the CLI or filesystem hierarchy.

[−] fzumstein 60d ago
Pyodide powers xlwings Lite, a free Excel add-in that you can install from Excel’s add-in store with a single click. It outperforms Microsoft’s official Python in Excel solution in every coceivable way: price, privacy, speed, can install packages, can access the internet, can access local files, doesn’t have a usage quota, can automate Excel and create native UDFs. See https://lite.xlwings.org
[−] QuadmasterXLII 61d ago
It works surprisingly well in terms of writing python for native execution, and then trying to share on the web and having it Just Work TM. Unfortunately, when I want python it's because I want numpy, scipy and friends, and once you bring them on board pyodide load times are long. As an example comparison: a face turning octahedron puzzle in python + pyodide, loads in 10 seconds https://cubes.hgreer.com/fto.html . Meanwhile, a megaminx puzzle in javascript (statically generated by python) loads in 200 ms https://cubes.hgreer.com/ssg/output.html
[−] devsda 61d ago
There's also xeus-cpp which is cpp based on wasm. Xeus-cpp and pyodide are the backends for Jupyterlite [1] kernels in browser.

It's actually a very good way to teach coding in python/c++(11, 17 or even 23), explore language features or your own library within browser and allow students to execute code by hosting just some static html pages and some assets without any backend.

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

[−] ianberdin 60d ago
Yea, I even built online ide based on Pyodide. Insane peace of software. You can try here: playcode.io/python
[−] jasiek 60d ago
I've used it to put together a browser app to program walkie-talkies: https://codeplug.org
[−] mcintyre1994 60d ago
Love all the tools mentioned in the comments, Pyodide is a fun tool. I built https://pyground.vercel.app with it a few years ago, as a quick way to run Python on a CSV/JSON file locally in the browser. For a while Python/Matplotlib was what I was most comfortable writing quick and simple analysis scripts with, and this was my go to for one-off data analysis work. You can drag-drop a file in, then some 'clever' code makes it available as data in the Python script so you don't have to write any parsing code yourself.

Now I'd probably just get Claude Code to write something locally, but there might be some value in a version of pyground that can use an LLM to write the Python code for you (and give it the data shape) but keeps the local execution setup the same.

[−] ndr 60d ago
related self plug: I built https://codeglf.com on Pyodide, a weekly Python code golf site where every submission runs locally in the browser.

WebAssembly's isolation means you get sandboxing for free without any server infrastructure. Of course users could cheat and submit code that doesn't actually pass the tests, but so far everybody has been friendly and I haven't needed to validate results server-side. Hopefully sharing the link here doesn't make that worse!

[−] strujillo 60d ago
It’s impressive how mature Pyodide has become — running Python scientific tools in the browser opens up a lot of possibilities.

I’ve been working on a small (~800-line) Python system that uses sparse regression to discover physical laws from raw data. It was able to estimate the Sun’s rotation (~25.1 days vs 27 days actual) and found a temperature ~ velocity^3.40 relationship in solar wind data.

Having this kind of lightweight stack in the browser could make exploratory science much more accessible.

[−] williamstein 60d ago
I tried to make a version of this using Zig once, but ran out of steam: https://cowasm.org/
[−] ipunchghosts 60d ago
REMUS RLF reader runs pyodide to parse underwater drone mission files in the browser

https://isaacgerg.github.io/remus-rlf-reader/webapp/

[−] yawnxyz 61d ago
no but it works great in conjunction with observable and d3js for pretty interactives!
[−] yjftsjthsd-h 60d ago
That is very cool. Has anyone made a nice beginner's learning environment out of it? Seems like it would solve some of the extra friction that makes it hard to get started.
[−] jacob019 61d ago
Anyone using it with nodejs to make a sandbox for code agents?
[−] Archit3ch 60d ago
Hoping for a Julia version.
[−] stainlu 60d ago
[dead]
[−] AgentMarket 60d ago
[flagged]
[−] poopdick 59d ago
[dead]
[−] ldsjunior 60d ago
[dead]
[−] anarhackist 61d ago
[dead]
[−] shevy-java 60d ago
WebAssembly will reach a breakthrough in the same year as GNU Hurd will dominate, together with the Desktop-Linux-of-the-year.