Classically trained former professional orchestral
Teacher (mostly UK inner-city teenagers), but also
kindergarten to adult education seniors (and everything
Writer (The Guardian, several O'Reilly titles, and other
magazine related stuff).
Academic background in Philosophy.
Principal engineer on the PyScript team at Anaconda.
Explain bunnies and Anaconda's relationship to PyScript.
What we'll cover about PyScript:
How exactly does it work?
What exactly do you get?
What exactly can you do?
So, what is PyScript?
A platform for Python in the
Sits on top of Python interpreters
compiled to web assembly (e.g. Pyodide, MicroPython
Different interpreters have
different strengths and weaknesses.
PyScript makes it simple and easy to
create and use frameworks or your own application code on
top of the platform.
You want to share this Python app with Grandma.
Grandma is clearly a proxy for someone non-technical. Let's
just consider all the skeletons in Python's cupboard for
getting our work to end users.
Install Python and then pip install blah... not a good
Shout out to BeeWare trying to work within the walled gardens
of native apps.
...A platform for Python
in the browser.
On your desktop
On your mobile or tablet
...and any other appliance with a built-in browser!
Emscripten allows you to port existing C/C++ code to WASM on
a web platform.
It's like the libc / POSIX / win32 layer, that abstracts
away the browser to provide common concepts like a
So how do you create an environment in which to run
Except, packaging with PyScript is
mostly like Python:
packages with C extensions need to be compiled to
you have to install all the packages each time you
navigate to a URL.
sometimes, the browser isn't friendly to popular packages
Work is ongoing to solve these puzzles.
from pyscript import window
from pyscript import document
<button id="click-me">Click me! 🐭</button>
from js import document
It's just Python! Access the DOM!
output = document.createElement("span")
output.innerHTML = "🖱️"
button = document.querySelector("button#click-me")
Clicky Mouse-o-Matic 🐁
full access to the browser's APIs.
Start Camera 🎥
<video id="video" width="600" height="400" autoplay />
async def camera_click(e):
media = js.Object.new()
media.audio = False
media.video = True
stream = await js.navigator.mediaDevices.getUserMedia(
video = js.document.querySelector("#video")
video.srcObject = stream
Lights 💡 Cameras 🎥 Action 😄
This example is based upon some work by a buddy of mine,
Professor Chris Rogers of Tufts University.
This is PyScript interacting with a Lego Spike Prime device
that is itself running MicroPython.
The PyScript app uses the browser's USB serial API to connect
to MicroPython running on the Lego device.
The device itself, is an Easter Egg roller, for decorating
Egg roller (needs LEGO robots) 🥚
Tufts' Prof.Ethan recently demoed a version of this at the
Talking of things that spin! There's more..!
Ever seen this on a web page?
We're blocking the UI because browsers usually use a single
It's the same with PyScript.
Please don't block the main thread!
There's a Xworker proxy between the MAIN thread and the
Transparent message passing done in a way that will
pause the worker (allowing synchronous Python code) while
the MAIN thread remains unblocked.
Achieved via a web standard for sharing memory between
workers and the main thread, called Atomics.
What does that look like in Python?
Main thread 🧵
from xworker import XWorker
for i in range(12):
sync = XWorker(
"pompom.py", config="turtle.toml", type="micropython"
Worker code (1) 🐢
for i in range(100):
Worker code (2) 💬
result = turtle.svg()
from xworker import xworker
document = xworker.window.document
container = document.createElement("span")
container.innerHTML = result
This is a video of the code we just examined.
I don't want my laptop to melt.
You get the idea...
Turtles on workers 🐢🐢🐢💥😱
(Chrome only - may melt your laptop.)
It's very early days and we're only just scratching the
surface of PyScript's potential, both for the Python world and
the world of the browser.
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).