Live data from Hacker News

PyScript: Run Python in your HTML

pyscript.net

21–30 of 71 posts

Re: PyScript: Run Python in your HTML

#23
post #5

For some reason, I can't see this linked anywhere on the site, but there is an examples page: https://pyscript.net/examples/ (This was presented today as a pycon keynote talk!)

They don't seem to be working on Android Chrome.

Works fine for me on a Pixel 6XL. It does need to let the pyodide files load, but they get cached, so for me, having previously loaded a demo a month or so ago, it loaded the Todo app almost instantly.

A few brief delays came with the matplotlib examples but nothing too bad (seconds not minutes)

Re: PyScript: Run Python in your HTML

#24
post #5

For some reason, I can't see this linked anywhere on the site, but there is an examples page: https://pyscript.net/examples/ (This was presented today as a pycon keynote talk!)

okay thought it wasn't working because it seems to take a long time for the spinner to go away. but I'm very impressed with the todo.py! This is what frontend should be and in 5 years or so I wouldn't be surprised to see python taking over. If only the initial payload for the python runner was smaller and if only browsers started supporting webassembly/python stack out of the box!!! from datetime import datetime as d…

As a way of interacting with the DOM, this makes me very uncomfortable:

    # add the task element to the page as new node in the list by cloning 
    taskHtml = task_template.clone(task_id, to=task_list)
    taskHtmlContent = taskHtml.select('p')
    taskHtmlContent.element.innerText = task['content']
    taskHtmlCheck = taskHtml.select('input')
    task_list.element.appendChild(taskHtml.element)

We can surely make such things easier in 2022?

Re: PyScript: Run Python in your HTML

#25
post #24

Earlier quoted context omitted.

okay thought it wasn't working because it seems to take a long time for the spinner to go away. but I'm very impressed with the todo.py! This is what frontend should be and in 5 years or so I wouldn't be surprised to see python taking over. If only the initial payload for the python runner was smaller and if only browsers started supporting webassembly/python stack out of the box!!! from datetime import datetime as d…

As a way of interacting with the DOM, this makes me very uncomfortable: # add the task element to the page as new node in the list by cloning taskHtml = task_template.clone(task_id, to=task_list) taskHtmlContent = taskHtml.select('p') taskHtmlContent.element.innerText = task['content'] taskHtmlCheck = taskHtml.select('input') task_list.element.appendChild(taskHtml.element) We can surely make such things easier in 202…

I imagine that if Python were supported out of the box in browsers like JavaScript is, frameworks would emerge for this sort of thing. At this point though, I'm not sure I think it's particularly likely that browsers will support additional languages instead of just preferring people compile to WASM and use some JavaScript over it.

Re: PyScript: Run Python in your HTML

#29
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 feature completeness is important, Pyodide and Coldbrew are probably best.

[0] https://github.com/pyscript/pyscript/blob/main/pyscriptjs/sr...

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

[2] https://github.com/plasticityai/coldbrew

[3] https://github.com/brython-dev/brython

Post reply on HN