Technical Overview

How Pyroom runs Python in the browser — runtime, architecture, supported APIs, and available packages.

Python Runtime

Python Version
3.11.3
CPython — full language spec
Execution Engine
Pyodide 0.29.3
CPython compiled to WebAssembly

Pyroom uses Pyodide — a port of CPython to WebAssembly — to run Python entirely in the browser. No server executes your code. Everything runs locally in your browser tab via a Web Worker.

The Python standard library is fully available: math, random, datetime, json, re, collections, itertools, functools, io, sys, os.path, dataclasses, typing, enum, pathlib, and more.

  • Threading (threading, multiprocessing) is not supported — WebAssembly runs single-threaded
  • Real filesystem access is not available — os.listdir, file open/write are sandboxed
  • Raw network sockets (socket) are not available in the browser

Architecture

Pyroom uses a two-thread model to keep the UI responsive while Python executes. The Python runtime runs inside a Web Worker (separate thread), communicating with the main UI thread via messages and SharedArrayBuffer for synchronous calls (required for Tkinter and Turtle rendering).

Browser tab
Monaco Editor  |  Preview Panel  |  Console
↕ postMessage / SharedArrayBuffer
Web Worker
Pyodide (Python 3.11 / WASM)  |  tkinter_shim  |  plugin_shim
↓ compiled from CPython
Runtime
WebAssembly (.wasm)  +  Python standard library (.zip)

On iOS/iPadOS, SharedArrayBuffer is unavailable, so Pyroom falls back to running Python on the main thread. Tkinter and Turtle still work but the UI may be less responsive during execution.

Cross-Origin Isolation headers (COOP + COEP) are required for SharedArrayBuffer access. Pyroom configures these on its server deployment.

AI Assistant Stack (Experimental)

Note: AI Assistant is experimental. Output quality, speed, and model availability can vary by device tier, browser, and memory limits.
Inference Runtime
transformers.js + ONNX
Runs in browser with WebAssembly backend
Translation Models
ONNX translation pipelines
Language-specific translation models with browser caching and compatibility fallbacks

Pyroom AI Assistant runs directly in the browser using @huggingface/transformers pipelines. Models are loaded from Pyroom-managed model paths (local/CDN) and cached in the browser for repeat usage.

  • Explanation layer: browser-hosted text-generation pipeline for code and error explanations
  • Translation layer: ONNX translation pipelines for selected output languages
  • Execution mode: Translation pipeline runs on wasm; dtype fallbacks are used to improve compatibility on constrained devices
  • Offline-capable flow: after model assets are loaded and cached, explanation/translation can continue in offline-friendly scenarios
  • Safety fallbacks: when model loading is not possible, Pyroom falls back to heuristic explanations so the assistant remains usable

Custom Tkinter Implementation

Note: Pyroom does not use the real tkinter module. It ships a custom Python-level shim that maps Tkinter API calls to browser DOM operations.

The standard tkinter is built on top of Tcl/Tk — a desktop GUI toolkit that cannot run in a browser. Pyroom implements a tkinter compatibility layer consisting of two parts:

  • Python shim — a tkinter module written in Python that intercepts widget creation and method calls, forwarding them via tkinter_shim JS bridge
  • JS renderer — a TypeScript module on the main thread that translates widget operations into real DOM elements rendered inside the Preview panel

Supported Tkinter API:

  • Tk(), mainloop(), title(), geometry()
  • Button, Label, Entry, Frame, Text, Canvas
  • Listbox, Scrollbar, Scale, Checkbutton, Radiobutton
  • Menu, menu.add_command(), menu.add_cascade(), menu.add_separator()
  • messagebox.showinfo(), showwarning(), showerror(), askyesno(), askokcancel()
  • filedialog.askopenfilename(), filedialog.asksaveasfilename() (browser prompt-based)
  • .pack(), .grid(row, column, columnspan, rowspan), .place(x, y, width, height)
  • .config() / .configure(), .cget(), .bind(), .focus_set()
  • StringVar, IntVar, BooleanVar, .get() / .set()
  • after(ms, callback), after_cancel()

Known limitations compared to desktop Tkinter:

  • Advanced widget styling, custom fonts, and bitmap images have limited support
  • messagebox uses browser alert/confirm dialogs
  • filedialog uses browser prompt — no real file picker
  • Canvas arc, image, and bitmap items are not implemented
  • Toplevel (secondary windows) is not supported

Turtle Graphics

Similar to Tkinter, Pyroom replaces the standard turtle module with a custom implementation that renders drawing commands onto an SVG canvas in the Preview panel.

  • All standard movement commands: forward(), backward(), left(), right(), goto(), setx(), sety()
  • Pen control: penup(), pendown(), pencolor(), pensize(), speed()
  • Fill operations: begin_fill(), end_fill(), fillcolor()
  • Drawing helpers: circle(), dot(), write(), clear(), reset()
  • Screen: bgcolor(), title(), screensize()

Available Packages

Pyodide bundles a large set of scientific, data, and utility packages that can be imported directly. Packages are loaded on-demand when your code first imports them, or you can pre-load them via Libs settings in the playground.

Full list: pyodide.org → Packages in Pyodide

Scientific & Math

numpyscipysympympmathstatsmodelsautograduncertaintiesiminuitnlopt

Data & DataFrames

pandaspyarrowxarrayfastparquetxlrdpython-calamine

Visualization

matplotlibbokehaltairPillowimageiowordcloudsvgwrite

Machine Learning

scikit-learnlightgbmxgboostriver

Networking & HTTP

requestshttpxaiohttppyodide-http

Parsing & Text

beautifulsoup4lxmlnltkregexpyparsing

Graphs & Networks

networkxigraphrustworkx

Serialization

pyyamlmsgpackorjsonujsonprotobufcryptography

Installing unlisted packages

Packages not bundled with Pyodide can be installed at runtime using micropip (pure-Python packages from PyPI):

import micropip
await micropip.install("package-name")

Editor

Pyroom uses Monaco Editor — the same editor that powers VS Code — for code editing. It provides:

  • Python syntax highlighting
  • Autocomplete and IntelliSense for Python built-ins
  • Undo / redo history
  • Configurable font size and theme (dark / light / auto)

Accessibility & Font Support

Pyroom supports reading-focused font presets on the website and in the playground UI. Available options include default UI font, Lexend, OpenDyslexic, and a Large text mode.

  • Font selection is available from the top navigation bar and applies immediately without page reload.
  • Settings are persisted in localStorage and synced with the shared accessibility profile key (pyroom:accessibility-profile).
  • Website typography uses CSS variables so font family and base size can be switched globally while keeping navigation controls compact and stable.
  • Local bundled font assets are shipped for Lexend and OpenDyslexic to avoid dependency on third-party font CDNs for accessibility presets.