from Hacker News

A possible future of Python in the browser

by milliams on 2/25/25, 9:15 AM with 94 comments

  • by giancarlostoro on 2/25/25, 7:03 PM

    I have mentioned it on HN before, but I strongly believe that bringing Python to the browser, especially via WASM, and going as far as bringing on a templating library, would allow Python to match things like C#'s Blazor, which honestly has been a productivity boost on web projects.

    I'm totally all-in on WASM over JavaScript, unless your back-end is also JS/TS then no objection.

    I could see Django benefitting greatly from being able to run template logic in-browser.

  • by supportengineer on 2/26/25, 12:16 AM

    If my browser supports WebAssembly, I should be able to open my browser, forgo opening any actual web pages, and veer off into WebAssembly-land. From there perhaps there should be a package manager that lets me install packages (like Python, Java, Smalltalk, etc ) and switch to some sort of shell or launcher where I can enter a REPL for the selected language package. From there I could do anything.
  • by svilen_dobrev on 2/25/25, 8:33 PM

    very interesting. So all the declarative stuff, like various type descriptions and preconditions and such, can be precompiled.. (and i am not talking about type-hints/annotations). Maybe some of the meta-programming stuff too.

    i was thinking some weeks ago that it may be time to "fork" python - as language - in a way to preserve the initial simplicity and clarity it did have and is losing faster and faster. But, nevermind. Will have to live with whatever there is.

    edit: looking at the code, some things might be optimized but no idea if these are on critical path (like, that switch-by sq_idx, or 6 lines.append.. ), or whether func-calls are as expensive in Spy as they are in Cpy. But anyway, squeezing few percents is not the point.. if one needs magnitudes.

  • by ripped_britches on 2/25/25, 9:11 PM

    I’m also super excited about wasm creating language democracy. I’m rooting for dart myself.
  • by dimatura on 2/25/25, 9:49 PM

    As someone that mainly codes in Python and only has rudimentary JS skills, I'm intrigued. The generative art pyscript demos mentioned in the blog post are really nice.

    Using decorator calls to "compile" chunks of python code seems like an increasingly popular trend in ML (and presumably other numerically intensive code) - e.g., numba, jax.jit and triton.

  • by laurencerowe on 2/26/25, 8:03 AM

    SPy is a cool experiment which we should applaud, though perhaps it would be helpful to compare to ShedSkin, Nuitka, or maybe Numba along with Cython if the eventual goal is compile everything to Wasm.

    I'd maybe quibble with "running natively on WebAssembly with speed in the same order of magnitude as Rust" given I expect that statement would be just as true if you replaced Rust on WebAssembly with the equivalent JavaScript.

    But ultimately while I understand the motivation - at the beginning of my career before I discovered Python I wanted to write command line scripts in PHP because that was what I knew! - I think it is ultimately a dead end since by breaking from the Python ecosystem you end up having to compete against JavaScript which is not really that far from Python and has an existing library ecosystem to plug into.

  • by nine_k on 2/26/25, 2:33 AM

    Python is a fine language. It has a nice enough JIT compiler by now. Its structure is similar enough to JS to allow easy interop, and easy exposure of browser APIs exactly the way these APIs are exposed to JS.

    But the power of Python currently mostly lies in its being a glue language. Python easily and neatly wraps things like numpy, scipy, polars, pytorch, etc, all implemented in native code. Not being able to use these would be a major limitation. But being able to use these would be a colossal change to the browsers' capabilities, security model, and, well, purpose.

  • by Terretta on 2/26/25, 12:20 AM

  • by __MatrixMan__ on 2/26/25, 5:48 AM

    Maybe Nim isn't python-like enough to count, but it compiles to C or JavaScript, which makes it sort of relevant to pythonishness in the browser.

    Independently of its compilation flexibility, it's nice to work with. For example it was the first language that ever gave me compile error because there were cases that my switch statement didn't account for.

  • by rdedev on 2/26/25, 1:31 AM

    Other projects that tries to achieve the same: RustPython and py2wasm

    So far my issue with pyiodide or other interpreted variants of python in wasm is the huge startup time especially if you need to install dependencies. The above projects i hope eventually reach a point where we can just compile everything

  • by cxr on 2/26/25, 5:00 AM

    Author is right in their dismissive attitude of Pyodide, but their WASM-ward gaze is probably misplaced, too. Once you're talking about acceptability in terms of being "Python-like enough", you should really be considering a Python-like syntax for JS, which would suffice for a bunch of Python programmers (in particular those who only picked it up as a result of ill-considered advocacy by Python proponents who told them that e.g. Python is how science gets done).
  • by JodieBenitez on 2/26/25, 7:37 AM

    I write a lot of Python, and I like it very much. But when it comes to the browser, what I don't like is compilation/build steps (yes, that includes Vue/React/Whatever builds). And that's why even I who don't like javascript very much will still be using it vanilla-style even if a compile-your-python-to-browser-wasm ever takes off.

    That would still be nice to have some of those python libs to the browser though.

  • by DeathArrow on 2/26/25, 7:22 AM

    Why can't regular Python code be compiled straight to WebAssembly?
  • by khimaros on 2/26/25, 10:16 AM

    i'm curious how SPy compares with Mojo, apart from the license. are they trying to solve the same problems?
  • by gunian on 2/26/25, 3:17 AM

    python in browser more of a pipe dream than me escaping slavery lmaooooo
  • by kace91 on 2/26/25, 12:03 AM

    I have a Node background so I might be biased but... Why would you want python in the browser?

    Like, I get the appeal of more languages beyond JavaScript for the frontend, but I'd have guessed this would mostly be attractive to people who like significantly different languages to js, like maybe something compiled and strongly typed.

    Python and Javascript seem to be in the same ballpark of "interpreted scripty language grown larger". I don't think moving to python would give me a different enough language to warrant the cost of switching.

  • by dang on 2/25/25, 8:01 PM

    [stub for offtopicness]