Live data from Hacker News

PyScript: Run Python in your HTML

pyscript.net

61–70 of 71 posts

Re: PyScript: Run Python in your HTML

#61
post #53

Python is the worst language to script anything inside a markup language that does not need to be structured like Python (HTML). So yeah, a good experiment, but unfortunately it is doomed to fail.

You can just reference your separate python file, you don't actually have to put it all in one html file.

Re: PyScript: Run Python in your HTML

#62
post #52

This uses Pyodide [0] under the hood [1], which is CPython compiled to WebAssembly. In all my tests of it, loading takes a long time ~5 seconds. Coldbrew [2], another distribution of CPython on Wasm, is another option with similar load times. And Brython [3] is a completely different option without long load time: a Python interpreter implemented in JavaScript. If load time is important, Brython is pretty nice. If fe…

That 5 second loading time only happends once though.

Sadly, not true. It seems like even with cache on, it still takes 5 seconds for the JIT to load everything.

Re: PyScript: Run Python in your HTML

#65
I've learned to accept my larger snake overlord. I know a lot of people work very hard on the anaconda project. It is a fork of what I consider to be actually pythonic. I am pretty sure there are a lot of big money actors working in the space to "Embrace, Extinguish, Destroy" what I know to be Python via the Anaconda project. This is really interesting stuff and is the first evidence I've seen other than money and some very specific political stuff that shows me they might do something worth something. Congrats! I will use this! I mourn what's lost, but embrace the future.

Re: PyScript: Run Python in your HTML

#66
post #52

Earlier quoted context omitted.

That 5 second loading time only happends once though.

Sadly, not true. It seems like even with cache on, it still takes 5 seconds for the JIT to load everything.

Agreed, wasm loading is supposed to be cached but in practice it doesn't seem to happen.

Re: PyScript: Run Python in your HTML

#67
post #4

This is awesome and has so much potential! Regarding the size of the download, I know there is ongoing work in the Pyodide project to create a much smaller python runtime that will help tremendously. Also, the script will be cached once you download it once. EDIT: Also, you don't need NPM or anything locally to run these

Adding -Os to the Pyodide compilation flags has proven surprisingly hard: https://github.com/pyodide/pyodide/pull/1882

But some other low hanging fruit include unvendoring the special encodings for Asian languages (hopefully everyone uses utf8), the decimal library, and the xml library which are all quite large and only occasionally used.

Re: PyScript: Run Python in your HTML

#68

Based on the responses, I assume this is a silly question, but why? Why would I want to run Python in HTML? Does Python have some libraries that JS is missing? (I could think of AI/ML libs) The examples [1] seem so slow in my browser (Firefox on an Intel-based MBP) that they are borderline unusable for me (and some of them just straight out don't load within 60 seconds, like the Bokeh, at which point I give up). [1]…

> Why?

This isn't good for most web use cases but there are some major new use cases that it enables.

Pyodide is in Python documentation all over the place, for instance on https://numpy.org/

Python has many libraries that JS is missing. Particularly the scientific computing ecosystem has a lot of very well supported Python packages but fewer JavaScript packages. They also can benefit a lot from connection to a UI.

Two key use cases for this stuff are Python education and scientific computing. Students have a hard time installing Python locally. Generally scientists want to share their results broadly, but they probably did their analysis in Python.

Here's another example of a good use case: https://www.socialfinance.org.uk/blogs/analysing-sensitive-d...

Re: PyScript: Run Python in your HTML

#69

Based on the responses, I assume this is a silly question, but why? Why would I want to run Python in HTML? Does Python have some libraries that JS is missing? (I could think of AI/ML libs) The examples [1] seem so slow in my browser (Firefox on an Intel-based MBP) that they are borderline unusable for me (and some of them just straight out don't load within 60 seconds, like the Bokeh, at which point I give up). [1]…

> Why? This isn't good for most web use cases but there are some major new use cases that it enables. Pyodide is in Python documentation all over the place, for instance on https://numpy.org/ Python has many libraries that JS is missing. Particularly the scientific computing ecosystem has a lot of very well supported Python packages but fewer JavaScript packages. They also can benefit a lot from connection to a UI. T…

To be clear these are all use cases of Pyodide. PyScript only was released two days ago so it's harder to point to real world uses.

Re: PyScript: Run Python in your HTML

#70
post #55

Based on the responses, I assume this is a silly question, but why? Why would I want to run Python in HTML? Does Python have some libraries that JS is missing? (I could think of AI/ML libs) The examples [1] seem so slow in my browser (Firefox on an Intel-based MBP) that they are borderline unusable for me (and some of them just straight out don't load within 60 seconds, like the Bokeh, at which point I give up). [1]…

If you already have a lot of domain logic in Python for your backend, that would make it easier to write a frontend living in the same codebase. (For example, imagine a framework for autogenerating forms for your Django models; this already exists server-side, but native client-side Python would give you more options. And if your framework owns both the client and server, it could autogenerate the API so you don’t ev…

No post body was provided.
Post reply on HN