3 ms·
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 Py
by simonw 8mo 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 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-demo.html https://simonw.github.io/research/monty-wasm-pyodide/pyodide...
[1] OK, Claude Code knows how to do it.
- iamcreasy 8mo agoHow do you call those C/Rust libraries compiled from to webassembly from Python/Pyodide?
- simonw 8mo agoYou have to turn them into WebAssembly wheels, then you can import them as if they were regular Python modules.
- VagabundoP 8mo agoThe 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 8mo agoAt 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.
- limagnolia 8mo agoWhat do you mean by "extremely weak guarantees"?
- LtWorf 8mo agopython at least won't cast numbers to strings when adding them.
- tracker1 8mo agoJS 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.
- wiseowise 8mo agoSerious 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.
- simonw 8mo agoC extensions aren't missing, the key ones are available in Pyodide already and you can compile others to WASM wheels if you need them. You use Python on the web because there's existing software written in Python that you want to run in a browser.
- b89kim 8mo ago[dead]
- infamia 8mo agoThe web is the only major platform that has a language monoculture to its detriment (i.e., not all problems are Javascript shaped). IMO the web ought to become multilingual (and become JS optional_ to further ensure its continued longevity and agility. Hopefully one day browser vendors will offer multiple runtime downloads (or something similar capability).
- wiseowise 8mo ago> i.e., not all problems are Javascript shaped I’m having trouble coming up with a single Python-shaped problem that can’t be contained within JavaScript-shaped ecosystem.
- pjmlp 8mo agoEmbedded systems, consoles and mobile phones come to mind as well. Even if you can go outside the blessed languages, it isn't without pain and scars.
- infamia 8mo agoAll the embedded systems I've worked in have many languages you can use to compile whatever, burn, and run whatever you like. Consoles run game engines and programs written in all sorts of different languages. They don't care as long as they can execute the binary. Phones can run apps using many different languages (C, C++, Rust, Python, etc.).
- joezydeco 8mo agoCould you share the UI repo? This is really interesting stuff.
- hashtag-til 8mo agoShould be this one https://github.com/simonw/research/blob/main/monty-wasm-pyodide/pyodide-demo.html https://github.com/simonw/research/blob/main/monty-wasm-pyod...
- joezydeco 8mo agoThanks!
- busfahrer 8mo agoI recently learned that with this you can run juypter notebooks in your browser: https://jupyter.org/try-jupyter/lab/ https://jupyter.org/try-jupyter/lab/ Stuff like numpy seems to just work