Agriya Khetarpal
Slides to follow along
autograd, and the PyBaMM ecosystem (Python Battery Mathematical Modelling)wasm32-emscripten) via LLVMemcc, as a drop-in replacement for gcc
Python/JavaScript
Foreign function interface
WebAssembly + JavaScript stdlib
{
Glue code
micropip
(CDN)
225+ packages!
(PyPI)
pure Python wheels
and essential low-level libraries
Yes, pygame-ce and SDL2 work, too, since version 0.26! Yay!
Play along!
https://agriyakhetarpal.github.io/sudoku/ – (works better on laptops)
https://diataxis.fr/
Diátaxis, from the Ancient Greek δῐᾰ́τᾰξῐς: dia (across) and taxis (arrangement).
New entrant!
Jupyter running natively in the browser – powered by WASM and Pyodide!
Google Colab, Binder, and JupyterLab (and Jupyter Notebook), and more
Client-side execution – all code runs via your CPU and hardware
Server-side execution – all code runs on a server (unless running locally, of course)
threading or multiprocessing
socket from the stdlib)Words by the Google Chrome team, comics adaptation by Scott McCloud
 
This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.
Words by the Google Chrome team, comics adaptation by Scott McCloud
 
This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.
Quick show of hands: how many of you have used five?
three?
one?
pytest, or other test runnersStart
Check out sources
Set up
Python and Emscripten
pyodide build
Invoke
Run tests
Install Node.js
End
pypa/build
pyodide build builds a wheelpip install build && python -m build
sysconfig data to trick cross-compilationpypa/cibuildwheel gained support for Pyodide builds this year!pyodide-build toolEmscripten
Drop-in replacements for GNU GCC and ld, and wrappers for CMake, Make, and other build tools
{distribution}-{version}-{python tag}-{abi tag}-{platform tag}.whlPure Python wheels are named mypackage-0.1.0-py3-none-any.whl
Compiled wheels get tagged as
mypackage-0.1.0-cp312-cp312-emscripten_3_1_58-wasm32-any.whli.e., reflecting the Emscripten version in the ABI tag. This has now changed to pyodide_20XY_Z to reflect the current year and build number.
They will contain Emscripten-compiled shared objects. Let's see an example from the scipy.odr module (orthogonal distance regression)
manylinux-amd64 wheel
WebAssembly wheel
├── __init__.py
├── __odrpack.cpython-312-x86_64-linux-gnu.so
├── _odrpack.py
├── models.py
└── odrpack.py
├── __init__.py
├── __odrpack.cpython-312-wasm32-emscripten.so
├── _odrpack.py
├── models.py
└── odrpack.py
ELF binaries
WASM binaries
0x7F magic number
\0asm magic number
wasm32-emscripten target are nascent (flang and LFortran)gfortran) and commercial ones (NAG, ifx, ifort, etc.)f2c to convert all the FORTRAN 77 code to C codef2c bugs, or wrapper differences, or sometimes, even bad FORTRAN 77 codecall_indirect (param i32 i32) (result i32)
func $funcname (param $var0 i32 i32 i32) (result i32)
function pointer defined with two inputs
when the symbol asks for three
jupyterlite-sphinx
A Sphinx extension providing a set of utilities to convert doctest-based examples to notebooks
provides a Pyodide kernel for those noteboks
Simply add the .. try_examples:: 
reST stub to your example's docstring:
>>> x = 2 >>> y = 2 >>> x + y 4
and a button in the HTML source is generated for you!
pip install jupyterlite-sphinx jupyterlite-pyodide-kernel
Another kernel, jupyterlite-xeus is available as well, which works with emscripten-forge recipes.
conda-forge)emscripten-forge – like conda-forge, but for wasm32-emscripten as a target
PySheets – a powerful Pythonic spreadsheet UI, running in the browser
PyCafe – a platform for sharing and running Python browser applications
reactive Jupyter notebooks that can be deployed as WASM data apps
PyScript – a framework for Python web applications (uses MicroPython and Pyodide)
Please feel free to say hello!
in/agriyakhetarpal
agriyakhetarpal
agriyakhetarpal
agriyakhetarpal [at] outlook [dot] comContent licensed under the CC-by-SA Attribution-ShareAlike Version 4.0 International License
Special thanks to
Ralf Gommers
Albert Steppi
Melissa Mendonça
Matthias Bussonnier
Robert Hood Chatham
Gyeongjae Choi
Loïc Estève
Emoji by openmoji.org
These slides
Pyodide
@agriyakhetarpal@fosstodon.org