# Pyodide — Python Runtime for the Browser via WebAssembly
> Run CPython and scientific Python packages directly in the browser with full NumPy, pandas, and scikit-learn support.
## Install
Save as a script file and run:
# Pyodide — Python Runtime for the Browser via WebAssembly
## Quick Use
```html
```
## Introduction
Pyodide is the CPython interpreter compiled to WebAssembly using Emscripten, allowing Python code to run natively in web browsers and Node.js. It ships with over 100 pre-built scientific Python packages and provides seamless interoperability between Python and JavaScript.
## What Pyodide Does
- Runs the full CPython interpreter in the browser via WebAssembly
- Includes pre-compiled packages like NumPy, pandas, Matplotlib, scikit-learn, and SciPy
- Enables bidirectional data exchange between Python objects and JavaScript values
- Installs pure Python packages from PyPI at runtime using micropip
- Provides a foreign function interface so Python can call JavaScript APIs and vice versa
## Architecture Overview
Pyodide compiles CPython and its C extension modules to WebAssembly using Emscripten. The resulting WASM binary runs inside the browser's sandboxed runtime. A JavaScript-to-Python bridge handles type conversion: Python dicts become JS objects, NumPy arrays share memory with TypedArrays via zero-copy transfers. The virtual filesystem emulates POSIX I/O, and a custom package loader fetches pre-built WASM wheels from a CDN or loads pure Python wheels from PyPI using micropip.
## Self-Hosting & Configuration
- Load from the official CDN or self-host the distribution files on your own server
- Use `loadPyodide()` to initialize the runtime; configuration options set the index URL and environment
- Install additional packages at runtime with `await pyodide.loadPackage("package-name")`
- Use micropip for pure Python packages not in the pre-built set
- Configure the virtual filesystem for persistent storage via IndexedDB or in-memory FS
## Key Features
- Full CPython compatibility including C extension modules compiled to WASM
- Over 100 scientific packages pre-built and ready to load
- Zero-copy sharing of array data between Python (NumPy) and JavaScript (TypedArray)
- Works in Web Workers for background computation without blocking the UI
- micropip enables runtime installation of any pure Python package from PyPI
## Comparison with Similar Tools
- **RustPython** — a Rust reimplementation targeting WASM; Pyodide runs the real CPython with full C extension support
- **Brython** — transpiles Python to JavaScript; Pyodide runs actual CPython bytecode and supports C extensions
- **Skulpt** — interprets Python in JS; limited to pure Python with no NumPy/pandas support
- **Emscripten** — the compiler toolchain Pyodide uses; Pyodide adds the Python ecosystem on top
- **JupyterLite** — a browser-based Jupyter built on Pyodide; Pyodide is the underlying runtime
## FAQ
**Q: Can I use pandas and NumPy in the browser?**
A: Yes. Both are pre-compiled to WASM and load in seconds. Most of the scientific Python stack is available.
**Q: How large is the initial download?**
A: The core runtime is about 12 MB. Additional packages add to the total but are loaded on demand and cached.
**Q: Can Python code access the DOM?**
A: Yes. Pyodide provides JavaScript proxy objects that let Python call browser APIs like document.querySelector.
**Q: Is it suitable for production use?**
A: Yes, for appropriate use cases like interactive notebooks, data exploration tools, and educational platforms. Heavy computation should use Web Workers.
## Sources
- https://github.com/pyodide/pyodide
- https://pyodide.org/
---
Source: https://tokrepo.com/en/workflows/asset-b83b6852
Author: Script Depot