Pyodide is a port of CPython to WebAssembly, built with the Emscripten toolchain, that runs a full Python interpreter in the browser (and in Node.js) with access to the browser’s Web APIs. It runs ported NumPy, pandas and scikit-learn in the browser, but does not officially support or recommend PyTorch or TensorFlow. It lives inside a 4GB address space and carries a slowdown its own project puts at roughly 3x to 5x against native Python.
What follows covers the mechanism, which packages actually load, what in-browser inference looks like, why memory errors appear, how the performance compares with native, and how it relates to PyScript.
How Pyodide Runs CPython in the Browser
CPython is written in C, which is exactly the kind of code Emscripten was built to compile into WebAssembly. An Emscripten build produces two files: a .wasm file holding all the compiled C code, and an .mjs file with the lifecycle code that compiles and instantiates the module and implements the system calls, including the file system and the dynamic loader. Each time that runtime is bootstrapped it produces an independent copy with its own separate address space.
Three pieces of plumbing make it feel like Python rather than a raw Wasm module.
- A virtual file system. In the browser, the runtime downloads wheels and unpacks them into an in-memory (MEMFS)
site-packagesdirectory, then preloads the dynamic libraries they contain. - A JavaScript-Python bridge. The runtime defines a mapping between the JavaScript and Python object models, with a calling convention for bidirectional calls, because many basic operations in a JavaScript runtime have no POSIX equivalent. The project describes this foreign function interface as supporting error handling and async/await.
- Patches for Wasm’s strictness. The WebAssembly spec makes a call through a function pointer with the wrong signature trap, and C extensions routinely cast functions to a different signature, so the runtime needs special handling to make such extensions work unmodified.
PEP 776 formalised Emscripten as a Tier 3 platform for Python 3.14, while noting that Emscripten builds will continue to be distributed downstream through Pyodide in the short term. The same PEP points out that Emscripten and WASI are the only supported Python platforms that offer sandboxing, which matters if you want to execute untrusted Python code. For the broader picture of how WebAssembly works for ML inference beyond Python, that explainer goes further than we do here.
Which Packages Work in Pyodide, and Can It Load NumPy, Pandas or Scikit-Learn?
Yes: NumPy, pandas, SciPy, Matplotlib and scikit-learn have all been ported, alongside general-purpose packages with compiled extensions such as regex, PyYAML and cryptography. Any pure Python package with a wheel on PyPI is supported. The catch is everything in between.
After the runtime starts, only the standard library is available, and other packages must be loaded explicitly. There are two routes:
| Route | Language | What it installs | When to use it |
|---|---|---|---|
micropip.install() |
Python | Pure Python wheels from PyPI, plus wasm32/Emscripten binary wheels from the JsDelivr CDN or custom URLs | The default for almost everything |
pyodide.loadPackage() |
JavaScript | Packages built with Pyodide, with less overhead but less functionality | Loading micropip itself, optimising for size, or when PyPI dependency resolution is not needed |
Compiled extensions are the hard boundary. A package whose C, C++ or Rust extensions were never compiled for WebAssembly fails, typically with a “pure Python wheel” error, because a standard PyPI binary wheel targets a native platform rather than emscripten-32. When you load from custom URLs, there is no dependency resolution, whereas packages from the official repository bring their dependencies with them.
The standard library itself has gaps. Modules such as tkinter, curses, termios and venv are removed to reduce download size and because they would not work in the WebAssembly VM. Hash algorithms that depend on OpenSSL are missing, and ssl is a stub whose OpenSSL-dependent methods do not work as expected or raise NotImplementedError.
threading, multiprocessing and sockets can be imported but are not functional, along with anything that depends on them. Packages that use threading or multiprocessing will not work without a patch to disable it. In our judgement, this is the first thing to check when a library you rely on “is available in Pyodide” but misbehaves: a ported package can still contain a code path that assumes a worker pool.
Can You Run Machine-Learning Inference in the Browser with Pyodide?
You can, for classical models such as scikit-learn on small-to-medium data. The PyScript documentation describes the runtime’s bundled NumPy, pandas, Matplotlib and scikit-learn stack as suitable for machine-learning demonstrations running locally with no backend. One practitioner guide reports scikit-learn prediction as effectively instant and training as viable for small-to-medium datasets (around 10k rows or fewer). Treat that as one author’s assessment rather than a benchmark.
The same guide notes that the runtime does not officially support or recommend TensorFlow or PyTorch, because their C++ build chains, threading models and CUDA dependence do not translate to current WebAssembly, and suggests TensorFlow.js or ONNX Runtime Web for deep learning instead. Its suggested workflow: clean and preprocess with pandas in the browser’s Python runtime, convert to a Float32Array, and pass the array to TensorFlow.js for GPU-accelerated inference.
WebLLM, an in-browser LLM engine, uses WebGPU for GPU work and WebAssembly (C++ compiled with Emscripten) for CPU-side tasks such as KV-cache management and tensor manipulation. Its authors report that WebLLM retains up to about 80% of the decoding throughput of MLC-LLM on the same device for 4-bit quantised models. That figure compares WebLLM’s compiled WebGPU kernels with MLC-LLM, not Python running in Pyodide.
One practitioner wired transformers.js into Pyodide through the Transformers.js.py wrapper and reported about 5 seconds per image, “certainly not real-time”, noting that calling from JavaScript avoids the extra WASM-to-JS-to-WASM hop.
Whatever runs the model, keep the Python interpreter off the main thread. Heavy Python computation blocks the browser’s event loop and freezes the UI, so the standard pattern is to run the interpreter inside a Web Worker. WebLLM uses web workers for the same reason.
Choosing an In-Browser Inference Route
| Workload | Reasonable route |
|---|---|
| scikit-learn or NumPy model, small tabular data, Python logic you want to reuse | Pyodide in a Web Worker |
| Deep learning model (vision, audio, transformers) | ONNX Runtime Web or TensorFlow.js, optionally with Pyodide for preprocessing |
| LLM chat or generation in the browser | A WebGPU engine such as WebLLM |
| Fast-loading lightweight Python UI logic, no heavy libraries | PyScript with MicroPython |
Why Pyodide Scripts Hit Memory Errors: The wasm32 4GB Ceiling
Pyodide runs on wasm32, and 32-bit pointers can address at most 4GB, so 4GB is the hard ceiling for everything the Python runtime holds: interpreter, packages, arrays and DataFrames together. When a dataset, or the intermediate copies produced while processing it, pushes past that limit, the browser tab crashes with an out-of-memory error.
Even 4GB is an opt-in for Emscripten builds. The V8 team’s post on the change explains that Chrome and Emscripten raised the usable limit from 2GB to 4GB, but Emscripten only allows 2GB by default; reaching 4GB requires build flags such as -s ALLOW_MEMORY_GROWTH -s MAXIMUM_MEMORY=4GB. The 64-bit alternative, Memory64, exists in the spec work, but SpiderMonkey’s engineers report it runs slower than 32-bit mode by anywhere from 10% to over 100% depending on workload. The reason is structural: on a 64-bit host, browsers reserve a 4GB region for each 32-bit module so out-of-bounds pointers simply trap, which lets them skip bounds checks, an optimisation that cannot work when the Wasm address space is as large as the host’s. Their advice is to use Memory64 only if you genuinely need more than 4GB.
Several memory costs stack up within that limit:
- Pandas object wrapping consumes more memory than native Python, and one guide suggests pandas performs well only for datasets under about 50MB.
- Sending a large dataset to a Web Worker with plain
postMessagemakes a deep copy, doubling memory use for that data. - A
PyProxykeeps its Python object alive until you explicitly destroy it, so long-running single-page apps leak memory if proxies are not released. - More generally, WebAssembly tends to consume more memory than equivalent JavaScript, according to a 2024 survey of Wasm runtimes.
How Pyodide Performance Compares with Native Python
Python under WebAssembly runs several times slower than native, with a larger gap for Python inner loops than for NumPy-backed work. The project’s roadmap states that across benchmarks the port is currently around 3x to 5x slower than native Python. The original 2019 Mozilla Hacks write-up measured a wider spread, 1x to 12x on Firefox and 1x to 16x on Chrome, and observed that code running many inner loops in Python slows by a larger factor than code relying on NumPy for its inner loops.
That distinction is the useful one. C code compiled to WebAssembly typically runs between near-native and 2x to 2.5x slower, the roadmap notes, so vectorised NumPy work inherits a smaller penalty than a pure Python loop, which pays both for interpretation and for running the interpreter itself inside Wasm. One practitioner guide calls NumPy “near-native (1x-2x)” in Pyodide; that is more optimistic than the project’s own figure, and we would plan against the roadmap’s 3x to 5x until your own workload says otherwise.
Published WebAssembly-Versus-Native Figures, Side by Side
| Source | What was measured | Reported gap |
|---|---|---|
| Pyodide roadmap | Python benchmarks in Pyodide vs native Python | ~3x to 5x slower |
| Mozilla Hacks, 2019 | Python in early Pyodide vs native | 1x-12x (Firefox), 1x-16x (Chrome) |
| Jangda et al., USENIX ATC 2019 | SPEC CPU C/C++ compiled to Wasm vs native | Mean 1.45x (Firefox), 1.55x (Chrome); peaks 2.08x and 2.5x |
| Jangda et al., USENIX ATC 2019 | Matrix multiplication kernel, vectorisation disabled | 2x to 3.4x slower |
| Wasm runtime survey, 2024 | Single-threaded Wasm vs pure JavaScript in browsers | 2x to 4x faster than JS |
The runtime also cannot spread work across cores, since threading is non-functional in the WebAssembly VM.
The roadmap gives a first load of a 6.4MB download with 4 to 5 seconds of environment initialisation. Package files are cached by the browser after the first download, yet PEP 776 notes that downloading and installing the packages into the in-memory file system is redone every time the runtime starts. Third-party reports of total download size vary widely with the package set loaded, from around 10MB to around 30MB, so the only figure worth planning against is the one measured for your own bundle. Detailed footprint and cold-start budgeting, and how to profile a Python inference path before committing to a port, are covered separately.
What Is the Difference Between Pyodide and PyScript?
PyScript runs on Python interpreters compiled to WebAssembly, and the full CPython port is one of them. PyScript takes Python interpreters compiled to WebAssembly, either Pyodide or MicroPython, and handles loading the interpreter, managing the environment and bridging to the browser’s JavaScript APIs.
The choice inside PyScript is really a choice between the two interpreters:
| Pyodide | MicroPython | |
|---|---|---|
| What it is | Full CPython compiled to WebAssembly | Lean reimplementation of Python 3 with a subset of the standard library |
| Size and load | Larger, slower initial load | About 170KB, loads almost instantly |
| Packages | PyPI via micropip, prebuilt NumPy, SciPy, pandas | Not aimed at heavy libraries |
| Choose it when | You need the scientific stack or full CPython compatibility | Fast startup matters, on mobile or for lightweight apps |
If the model needs scikit-learn, you are on Pyodide either way, with all of the limits above.
When Running Python Inference in the Browser Is Worth It
Moving a Python model into the browser is a deployment-target decision, and portability work pays when scoped against a measurable trigger: a deployment-target constraint, a performance ceiling or a lock-in cost. For the browser, the legitimate triggers are the ones the WebLLM authors name: the user opens a URL with nothing to install, the work stays on the device, and the browser abstracts away device backends.
When the model is already Python, small and CPU-friendly, Pyodide reaches that target by reusing code rather than rewriting it. Once the model is a neural network, the latency budget is interactive, or the data approaches the 4GB ceiling, the effort shifts to exporting the model to ONNX Runtime Web, TensorFlow.js or a WebGPU-compiled engine, where browser-side LLMs sit within generative AI engineering. Whether that rewrite, or a native C++ port instead, justifies its cost is a separate question, answered in when porting Python inference to C++ or WASM actually pays off.
The question to settle before choosing is which constraint will bind first for your model: memory, single-threaded CPU time, or first-load wait.