Readit News logoReadit News
protoduction · 5 years ago
If you want to play with Pyodide in a web notebook you can try Starboard [1][2].

A sibling comment introduces JupyterLite and Brython, which are Jupyter-but-in-the-browser, whereas with Starboard I'm trying to create what Jupyter would have been if it were designed for the browser first.

As it's all static and in-browser, you can embed a notebook (or multiple) in a blog post, for instance to power interactive examples. The bundle size is a lot smaller than JupyerLite for the initial load - it's more geared towards fitting into existing websites than being a complete IDE like JupyterLab.

[1] https://github.com/gzuidhof/starboard-notebook

[2] https://starboard.gg

KMnO4 · 5 years ago
I’m concerned with the performance. It’s up to 16x slower than native Python, which we already know is 100x(?) slower than native code.

So roughly 1600x more clock cycles are consumed than is necessary.

I’m already jaded with the extreme bloat of JS frameworks as it is (how many times does my computer need to ramp up fans because of your React blog?). This could potentially be an order of magnitude worse.

protoduction · 5 years ago
I think the main usecase for Python in the browser using Pyodide is to enable scientific computing and visualization in the browser, and also as a way to ship small Python applications to those that don't have Python installed (e.g. drag and drop a CSV file which gets processed with pandas). Lastly it's useful to power interactive coding environments without needing to spawn a pod per user (and fighting off people using them to mine bitcoin).

Building a website or SPA entirely backed by Python seems like the wrong use of this technology. The same goes for crunching large amounts of data.

musingsole · 5 years ago
The quality of an answer is often orders of magnitude more important than the speed at which it's generated. Speed is important, but it is always secondary.

You wouldn't pull this in for a snappy, reactive UI driven by Python. You pull this in so that you can re-use a server-side module to perform some activity that isn't critical and so not worth re-writing in JavaScript. In another 5 years (assuming Python is still of interest and that this solution worked), it will have been refined and optimized where maybe you do reach for it by default.

brrrrrm · 5 years ago
Genuine question: What are the quality improvements offered by Python? Is it mostly access to the scientific community's Numpy/Scipy/Matplotlib? The language's semantics?
azakai · 5 years ago
16x? FTA:

> performance since the 2019 announcement has improved greatly: "Performance ranges between near native to up to 3 to 5 times slower, depending on the benchmark."

rthz · 5 years ago
Concrete Python applications wouldn't be 100x faster if re-coded in some low level language.

In most places where performance matter Python packages would be using either C extension, Cython or numba to get near native performance. Pyodide is able to build those packages (except for numba). So overall it's currently 3 to 5 slower than native Python (which uses C extensions). See detailed benchmarks in https://hacks.mozilla.org/2021/04/pyodide-spin-out-and-0-17-...

randomfool · 5 years ago
Try it in JupyterLab using JupyterLite- https://jupyterlite.readthedocs.io/en/latest/_static/lab/ind...

(choose the pyolite option for Pyodide)

This project is actually quite impressive, I believe they've even gotten some pip install paths working??

mjburgess · 5 years ago
I'm having trouble getting anything plotted using this -- either via plotly or matplotlib (they don't appear to have seaborn available).

Have you (any one else) succeeded?

Not being able to display plots seems a major limitation.

nicolaskruchten · 5 years ago
The next version of plotly should be more compatible with Pyodide :)
charleover · 5 years ago
This works for me in Chrome 90 on Windows

  import matplotlib.pyplot as plt
  plt.plot([1,2,3,4,5], [1,4,3,2,5])
  plt.show()

rthz · 5 years ago
Yes, installing pure Python packages that have wheels from PyPi works. Assuming they don't use functionality that's not supported by the WebAssembly VM such as multiprocessing, threading (for now), and sockets.
BiteCode_dev · 5 years ago
gourneau · 5 years ago
Wow amazing, thanks for sharing.
timothycrosley · 5 years ago
I use this for the isort in browser demo: https://pycqa.github.io/isort/docs/quick_start/0.-try/ it was really awesome to be able to directly use a Python package without any wrangling or modification as is usually required with other Python on the browser solutions.
TechBro8615 · 5 years ago
Has anyone gotten this to run in a wasm runtime on the server? At some point I saw that wasmer had a fork adding server support, but it was out of date. Main challenge seems to be assumptions about running in the browser?

My motivation is that I’d like to run sandboxed Python scripts on the server, in a wasm runtime embedded in C.

rthz · 5 years ago
Work on Node.js support is in progress in Pyodide. And as you mentioned there is also the Wasmer build that could be updated.
TechBro8615 · 5 years ago
How does Node play into this? Can I embed a v8 engine in my C program and use pyodide, or do I need to bring Node along too? Does the compatibility layer depend on any Node-specific concepts like the event loop or garbage collector? (I think maybe V8 does its own GC? This just shows how thin my experience is with this topic.)
qbasic_forever · 5 years ago
Why not just use an OCI container and runtime (docker, containerd, crun, etc) or even systemd-nspawn?
TechBro8615 · 5 years ago
Because it’d be cool if it didn’t require OS level sandboxing.

AFAIU sandboxed embedded Python has been a bit of a Holy Grail for a long time. So if wasm gives an easy answer for it, that would be sweet!

vogon_laureate · 5 years ago
Neat: "The 0.17 release has a number of interesting features. Support for Python asyncio has been added, so that Python coroutines can run in the browser event loop; a JavaScript Promise can be awaited in Python and vice versa with Python awaitables. Error handling has also been upgraded so that exceptions generated by Python can be caught in JavaScript; that can be done in the other direction, as well."
jokoon · 5 years ago
I tried brython once and wrotesome video/image gallery with it, I was quite happy, but it ended up being quite slow.

I'm super excited about pyodide, although:

* I can't find a discord or IRC channel to ask questions, I guess the project is still young. Last time I've seen this project, it looked like a scientific software suite, which came with a lot of stuff I don't need.

* I wish there was more examples or samples, especially with events and the DOM.

* I've glanced at the doc and howtos, and it seems it requires a server, which I don't understand. Brython seems much more straightforward.

* I've read that memory leaks can happen in multiple places

* This example seems like misleading advertisement, in my view, at least for now:

    from js import document
    x = document.getElementById("myElement")
(Or I might need to read up more doc to understand how to get to that point)

rthz · 5 years ago
A chat channel is mentioned in the readme: https://gitter.im/pyodide/community

Yes, we are working on adding more examples.

Well you need to be able to serve static files. So if you are building locally you need to start a webserver, otherwise you can use the JsDelivr CDN.

Memory leaks can happen if you translate objects between Python and JS. So of it is unavoidable because it's difficult to know when to destroy Python objects from JS vice versa, but lots of work on it has been done in the 0.17 release with more to come in 0.18

Why do you find the example misleading?

jokoon · 5 years ago
> Well you need to be able to serve static files. So if you are building locally you need to start a webserver, otherwise you can use the JsDelivr CDN.

I don't understand, can't I just use offline, static files ?

I would still expect to use my own webserver, unrelated to pyodine, like flask or whatever.

> Yes, we are working on adding more examples.

Glad to hear this :) !

> Why do you find the example misleading?

I haven't really seen that example in the doc or elsewhere, and I don't understand the steps required to make such example work offline or without a webserver.

EDIT:

Another cool thing of brython is that could "inline" a python script inside a html file, such as:

    <script type="script/python">
or

    <script src="thing.py"></script>

swuecho · 5 years ago
BiteCode_dev · 5 years ago
They have different goals, nobody expect people to write a website ui with pyodine.

(although, python is my fav lang, and I wouldnt use brython either, 700ko to pay upfront before writing any code is too much)