Scripts2026年5月30日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Pyodide Overview
直接安装命令
npx -y tokrepo@latest install b83b6852-5c02-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产