Live data from Hacker News

Brython: an implementation of Python 3 running in the browser

github.com

11–20 of 76 posts

Re: Brython: an implementation of Python 3 running in the browser

#11

See also https://starboard.gg/ https://github.com/pyodide/pyodide They offer pure client-side Jupyter notebooks. Wasm compiled, no cloud servers needed.

Starboard is completely different from Brython, although it is cool. As for pyodide, it still involves proper working knowledge and literal implemetation of JS - Brython just needs you to know the bare basics, the rest is just pure Python

Re: Brython: an implementation of Python 3 running in the browser

#13

See also https://starboard.gg/ https://github.com/pyodide/pyodide They offer pure client-side Jupyter notebooks. Wasm compiled, no cloud servers needed.

JupyterLite[1] can also be added to this list.

[1] https://github.com/jupyterlite/jupyterlite

Re: Brython: an implementation of Python 3 running in the browser

#14
post #4

It's a great project! I use it to power the Python interpreter for an in-browser backend of an app I'm working on. I wrote a bit more about my experience using it (and a guide for others) here: https://datastation.multiprocess.io/blog/2021-06-16-language... . My biggest gripe is that so far I haven't been able to get good stacktraces out of it on errors. It also wraps all objects in custom Brython types that you have…

Yeah. Like I said, it could really do with more contributors who can work on these issues and add keep adding features. rayluo who is a major contributor (developed brip to support using regular PyPi packages with brython), for example, works at Microsoft, and most probably does this in his spare time. More people like this can help bring Brython up even more, so there's a majority coverage for what JS can do, with B…

Fantastic there is brip, I like to check in on Brython from time to time, and the lack of something like Brip was one reason I haven't been able to use it more.

I guess being able to take the C parts of extensions and have them compiled with emscripten would be a logical step further.

Re: Brython: an implementation of Python 3 running in the browser

#17

This project will transpile python code to JavaScript code instead of something WASM-based, like pyodide [0]. What are there the performance and usability consequences of each approach (py to js vs. py to wasm)? [0] https://github.com/pyodide/pyodide

(Disclosure: I'm a maintainer of https://skulpt.org, another Python-in-the-browser runtime, as well as a Python web framework/dev environment that uses it, https://anvil.works)

The short answer is that basically all the current Python-in-the-browser implementations (and there are a few!) predate widespread support of WASM. But even once WASM is a thing, you get a choice between:

1. Compile a full Python environment to WASM (via Emscripten), and load it in the browser. This is what Pyodide does - it lets you use a boatload of existing libraries, but you have to download and bytecode-compile the world to do it. On my machine Pyodide takes 10+ seconds to load. (PyPy.js, which predated WASM, was even worse!) The upside is that you can run more or less anything from the existing ecosystem. This tradeoff is great for Pyodide's use case (notebooks in the browser) - long load times are OK, but you really want those numerical libraries.

2. Ship a lightweight, JS-based runtime. This is what Brython and Skulpt do. You'll pay in performance (compilation overhead, interpretation, and the overhead of preserving Python rather than JS semantics for things like attribute lookup), but your payload will be much smaller (Skulpt is ~250kb on the wire), and you'll be interactive much faster. We chose Skulpt for the client side of our full-stack Python-in-the browser platform, Anvil (https://anvil.works). Unfortunately, you'll be amazed how many Python libraries don't work in this environment. Most "normal" Python code is pretty straightforward, but dig into any big library and you'll find a native dependency really fast. (Skulpt's original 'datetime' implementation was ported from PyPy, and even that depended on native code. In PyPy, the interpreter written in nearly pure Python!) In something like Anvil, this is no biggie, because you can call server-side code with one function call, but it could be a nasty surprise in a traditional app.

3. Compile "not quite Python" to JS (this is what Transcrypt does). This more or less transliterates Python code to the nearest Javascript equivalent. This produces really compact, JIT-friendly JS code, but it will bite you the moment you rely on Python semantics that aren't there in JS. Worse, you're now neither fish nor fowl: If you have a question, you can't consult StackOverflow for Javascript answers, but half the Python answers won't work for you.

(To my knowledge, nobody has yet attempted the "WASM + lightweight runtime" approach. We've occasionally discussed it, but it would be hard to retrofit to an existing project, because you'd want to move a-lot-but-not-all of the runtime into WASM to avoid being hammered by the JS-WASM bridge, and building a Python runtime from scratch is a heavy lift...all for a performance boost you might just get from generating faster JS.)

Before the pandemic, a colleague of mine wrote an in-depth comparison of six popular Python-in-the-browser implementations, with sample code and a discussion of their trade-offs, with a lot more detail than I can fit into this comment: https://anvil.works/blog/python-in-the-browser-talk

Re: Brython: an implementation of Python 3 running in the browser

#18
I found the following article and associated presentation to be a great overview of the options for this kind of thing: https://anvil.works/blog/python-in-the-browser-talk

Transcrypt's (https://github.com/QQuick/Transcrypt) approach made the most sense for me. The project seems to be a heroic effort by one guy.

Re: Brython: an implementation of Python 3 running in the browser

#19

I'm hoping web assembly eventually completely replaces javascript. It would be amazing if we could theoretically compile any language down to be browser compatible.

This is something that I wanted to hear more from people invested in frontend.

I work exclusively as a DevOps/DataOps/Backend engineer and have little contact with stuff running in the browser. I did, however, work with AngularJS back in the day, and although the framework itself didn't lend itself to nicely to productivity and simplicity, I believe that what I found most confusing was how unergonomic the browser environment itself was, from not dealing with a filesystem (and thus having to resort to tricks like transpiling and bundling) to the rather terse API, not having for instance a SQLite natively and not being able to enable something like this without bringing copious amounts of megabytes of extra javascript deps...

Is the browser environment becoming more dev-friendly with the adoption of WebAssembly? I ask that because, in my opinion, if the browser itself doesn't evolve, it doesn't matter which language we use, interacting with it will still be a hassle. All in all, it feels like the browser advanced a lot in technology for optimization and resource management, but not so much in becoming more user-friendly to the developer.

Re: Brython: an implementation of Python 3 running in the browser

#20

I'm hoping web assembly eventually completely replaces javascript. It would be amazing if we could theoretically compile any language down to be browser compatible.

That’s already pretty much the case. Python has been though it’s not fast and the stack size limit is problematic. https://github.com/pyodide/pyodide

Pyodide is used in https://jupyterlite.readthedocs.io/

Maybe things will improve with web assembly GC, though it will require work to port GC languages to it.

Post reply on HN