PyScript

Jesús Martínez Blanco

Principal Data Scientist

@                    

What is PyScript

  • A Javascript library to run Python in the browser
  • Open Source project from Anaconda
  • Built on Pyodide (Python on WebAssembly)

 

Binary instruction format for the web
(we can run compiled code in the browser)

  • No server needed: client side execution
  • Combines Python and JS easily
  • Interactive apps and notebooks in web pages

PyScript: Pros and Cons

PROS

  • Slower than native Javascript
  • Not all Python packages are supported (no C extensions)
  • Large initial page load (Pyodide is ~8Mb)

CONS

PyScript: How to

Put this in the <head>

<link rel="stylesheet" href="https://pyscript.net/releases/2025.7.2/core.css" />
<script type="module" src="https://pyscript.net/releases/2025.7.2/core.js"></script>
<script type="py" src="py/main.py" config="py/pyscript.toml"></script>

Write a .toml file listing the python libraries used in your script (+ some info)

Make your .py file part of the app

name = "My awesome pyscript app"
description = "Just a simple demo app"
packages = ["pandas", "plotly"]

Path to your Python script

Path to your
toml script

PyScript: How to

Here is an example of Python script as contents of main.py

from pyscript import display
import sys

display(sys.version)

pyscript

By chumo

pyscript

  • 15