How to run Python in the browser
summary
Compiles CPython to WebAssembly (using pyodide) and runs it in a worker thread so the UI stays responsive, connects stdout/stderr to xterm.js, and implements blocking stdin by sharing memory with SharedArrayBuffer and Atomics plus postMessage. Result is a real CPython REPL and filesystem (Emscripten in‑memory / optional IndexedDB) that works in the browser; download size is ~7.4 MB (WASM ~3.4 MB) and performance is roughly 2–3× slower than native CPython, with cross‑origin isolation required for shared buffers.
AI-written summary · about
chapters (4)
- 0:00Start
- 19:47Two problems 1. Freezing the UI 2. Blocking on stdin
- 23:03Normally, reading from stdin is a blocking system call
- 32:16Browser support for SharedArrayBuffer/Atomics
related talks
29mWhat can't WebAssembly do?
45mThe marvelous world of Python in Browser: a nice surprise
41mPyodide: A Python distribution for the browser
02h 47mA Pythonista's Introductory Guide to Web Assembly
31mIodide and Pyodide: Bringing Data Science...
31mThe CPU in your browser: WebAssembly demystified
24mPorting Python to WebAssembly
33mIodide and Pyodide: Bringing Data Science Computation to the Web Browser
