Live data from Hacker News

PyScript: Run Python in your HTML

pyscript.net

11–20 of 71 posts

Re: PyScript: Run Python in your HTML

#11
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!)

The js and css files should be hosted on a CDN otherwise people copying/pasting these demos might chew up pyscript.net resources.

Or at least add the js and css files to the zip file.

Which curiously wasnt included.

Re: PyScript: Run Python in your HTML

#13
post #3

I really really like this, but 4 MB zipped is a bit of a hard sell :/ I've had a need to deploy small ad-hoc HTML tools at work, though, and my Python is much better than my JS, so maybe it's worth it.

Local intranet / work tools would actually be a good use case for this as the load is small (tens, hundreds, maybe thousands of employees at absolute most) and mostly the same repeat users so browser caching would make it snappy for them on future visits.

A public marketing page where it's the random internet of totally new/anonymous users who want to instantly find out info about your product would be the worst use case for this IMHO.

Re: PyScript: Run Python in your HTML

#16
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 dt
    from utils import add_class, remove_class
    from js import console

    tasks = []

    # define the task template that will be use to render new templates to the page
    task_template = Element("task-template").select('.task', from_content=True)
    task_list = Element("list-tasks-container")
    new_task_content = Element("new-task-content")

    def add_task(*ags, **kws):
    # create task
    task_id = f"task-{len(tasks)}"
    task = {"id": task_id, "content": new_task_content.element.value, "done": False, "created_at": dt.now()}

    tasks.append(task)
    
    # 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)
    
    def check_task(evt=None):
        task['done'] = not task['done']
        if task['done']:
        add_class(taskHtmlContent, "line-through")
        else:
        remove_class(taskHtmlContent, "line-through")

    new_task_content.clear()
    taskHtmlCheck.element.onclick = check_task

    def add_task_event(e):
    if (e.key == "Enter"):
        add_task()

Re: PyScript: Run Python in your HTML

#19
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…

I tried the clock example and it worked, but I needed to wait maybe 30 seconds after page load..

Re: PyScript: Run Python in your HTML

#20
post #3

I really really like this, but 4 MB zipped is a bit of a hard sell :/ I've had a need to deploy small ad-hoc HTML tools at work, though, and my Python is much better than my JS, so maybe it's worth it.

For one of the examples, I saw it coming down with pyscript.js - 1.1 MB, pyodide.asm data + wasm of 16 MB, and each python package as a separate wheel download (cool!), matplotlib of 6MB :)
Post reply on HN