PyScript ๐Ÿ๐Ÿ“œ

Question:

You want to share this Python app with Grandma.


 print("Hello, world!")
          

How?

๐Ÿ˜ฌ๐Ÿ˜ฒ๐Ÿค”๐Ÿ˜ฑ

PyScript is...

...A platform for Python

in the browser.

Antonio's PyBunny ๐Ÿฐ

https://tinyurl.com/h66e32nk


arrr.py

The Black PERL ๐Ÿดโ€โ˜ ๏ธ ๐Ÿฆœโ˜ ๏ธ

https://tinyurl.com/46h66bn9

Runtimes

  • Pyodide
  • MicroPython
  • Lua
  • Ruby
  • ???

import js  # globalThis
          

from pyscript import window
          

from pyscript import document 
          
<button id="click-me">Click me! ๐Ÿญ</button>
          
from js import document


def handler(e):
    """
    It's just Python! Access the DOM!
    """
    output = document.createElement("span")
    output.innerHTML = "๐Ÿ–ฑ๏ธ"
    document.body.appendChild(output)


button = document.querySelector("button#click-me")
button.addEventListener("click", handler)

Clicky Mouse-o-Matic ๐Ÿ

https://tinyurl.com/yc4hjz33

<p><button micropython-click="camera_click">
  Start Camera ๐ŸŽฅ
</button></p>
<video id="video" width="600" height="400" autoplay />
          
import js


async def camera_click(e):
    media = js.Object.new()
    media.audio = False
    media.video = True
    stream = await js.navigator.mediaDevices.getUserMedia(
        media
    )
    video = js.document.querySelector("#video")
    video.srcObject = stream

Lights ๐Ÿ’ก Cameras ๐ŸŽฅ Action ๐Ÿ˜„

https://tinyurl.com/4dtpmrcw

Egg roller (needs LEGO robots) ๐Ÿฅš

https://tinyurl.com/4cc4bd2x

Main thread ๐Ÿงต

from xworker import XWorker

for i in range(12):
    sync = XWorker(
      "pompom.py", config="turtle.toml", type="micropython"
    )

Worker code (1) ๐Ÿข

turtle.speed(8)
turtle.pensize(12)

for i in range(100):
    turtle.penup()
    turtle.setpos(0, 0)
    turtle.left(random.randint(1, 360))
    turtle.pendown()
    turtle.color(random.choice(colours))
    turtle.forward(random.randint(20, 90))

Worker code (2) ๐Ÿ’ฌ

turtle.Screen().show_scene()
result = turtle.svg()

from xworker import xworker

document = xworker.window.document
container = document.createElement("span")
document.body.appendChild(container)
container.innerHTML = result

Turtles on workers ๐Ÿข๐Ÿข๐Ÿข๐Ÿ’ฅ๐Ÿ˜ฑ

https://tinyurl.com/5n8zjj9p

(Chrome only - may melt your laptop.)

Final thoughts

  • PyScript is a platform.
  • It runs everywhere a browser runs.
  • Write code and frameworks on PyScript.
  • It's open source... come play!
  • For the 99% (not just coders).

Your task:

Questions..?

TL;DR:

๐Ÿ‘‰pyscript.com๐Ÿ‘ˆ - IDE ๐Ÿ’ป

pyscript.net - docs ๐Ÿ“–

discord.gg/HxvBtukrg2 - chat ๐Ÿ’ฌ

Image credits

Photo by Dulcey Lima on Unsplash

Photo by Becca Tapert on Unsplash

Photo by Christian Wiediger on Unsplash

Photo by Valery Sysoev on Unsplash

Photo by Mathew Schwartz on Unsplash

Photo by Lia Trevarthen on Unsplash

Photo by Eric Wang on Unsplash