wasm-compatibility by marimo-team/skills
npx skills add https://github.com/marimo-team/skills --skill wasm-compatibility检查 marimo 笔记本是否能在 WebAssembly (WASM) 环境中运行——包括 marimo 游乐场、社区云或导出的 WASM HTML。
读取目标笔记本文件。如果用户未指定,请询问要检查哪个笔记本。
从以下两个来源收集笔记本依赖的每个包:
PEP 723 元数据——顶部的 # /// script 代码块:
# /// script
导入语句——扫描所有单元格中的 import foo 和 from foo import bar。使用下表将导入名称映射到其 PyPI 发行版名称:
| 导入名称 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 发行版名称 |
|---|
sklearn | scikit-learn |
skimage | scikit-image |
cv2 | opencv-python |
PIL | Pillow |
bs4 | beautifulsoup4 |
yaml | pyyaml |
dateutil | python-dateutil |
attr / attrs | attrs |
gi | PyGObject |
serial | pyserial |
usb | pyusb |
wx | wxPython |
对于大多数其他包,导入名称与发行版名称一致。
对于每个依赖项,确定其是否能在 WASM 中运行:
它是否在 Python 标准库中? 大多数标准库模块可用,但以下模块不可用:
multiprocessing —— 浏览器沙盒不支持进程生成subprocess —— 同上threading —— 模拟实现,无真正并行性(警告,非硬性失败)sqlite3 —— 改用 apsw(Pyodide 中可用)pdb —— 不支持tkinter —— 浏览器中无 GUI 工具包readline —— 浏览器中无终端它是否是 Pyodide 内置包? 完整列表请参阅 pyodide-packages.md。这些包开箱即用。
它是否是纯 Python 包? 仅包含 .py 文件(无编译的 C/Rust 扩展)的包可以通过 micropip 在运行时安装并正常工作。检查方法:在 PyPI 上查找 py3-none-any.whl 轮子文件(例如访问 https://pypi.org/project/<package>/#files)。如果只有平台特定的轮子文件(例如 cp312-cp312-manylinux),则该包包含原生扩展,可能无法工作。
可用的常见纯 Python 包(不在 Pyodide 内置包中,但可通过 micropip 安装):
* `plotly`、`seaborn`、`humanize`、`pendulum`、`arrow`、`tabulate`
* `dataclasses-json`、`marshmallow`、`cattrs`、`pydantic`(内置)
* `httpx`(内置)、`tenacity`、`backoff`、`wrapt`(内置)
4. 它是否包含未为 Pyodide 构建的 C/原生扩展? 这些将无法工作。常见问题包:
* `torch` / `pytorch`
* `tensorflow`
* `jax` / `jaxlib`
* `psycopg2`(建议使用纯 Python 模式的 `psycopg`)
* `mysqlclient`(建议使用 `pymysql`)
* `uvloop`
* `grpcio`
* `psutil`
扫描笔记本代码中无法在 WASM 中工作的模式:
| 模式 | 失败原因 | 建议 |
|---|---|---|
subprocess.run(...)、os.system(...)、os.popen(...) | 浏览器中无法生成进程 | 移除或在非 WASM 检查后使用 |
multiprocessing.Pool(...)、ProcessPoolExecutor | 无法进行进程分叉 | 使用单线程方法 |
threading.Thread(...)、ThreadPoolExecutor | 模拟线程,无真正并行性 | 仅警告——可工作但无加速效果;对于 I/O 操作使用 asyncio |
open("/absolute/path/...")、硬编码的本地文件路径 | 无真实文件系统;仅内存文件系统 | 通过 URL(httpx、urllib)获取数据或嵌入到笔记本中 |
sqlite3.connect(...) | 标准库 sqlite3 不可用 | 使用 apsw 或 duckdb |
pdb.set_trace()、breakpoint() | WASM 中无调试器 | 移除断点 |
读取环境变量(os.environ[...]、os.getenv(...)) | 浏览器中环境变量不可用 | 使用 mo.ui.text 进行用户输入或硬编码默认值 |
期望真实文件的 Path.home()、Path.cwd() | 仅虚拟文件系统 | 使用 URL 或嵌入数据 |
| 大型数据集加载(>100 MB) | 总内存上限为 2 GB | 使用较小样本或远程 API |
WASM 笔记本应在 PEP 723 的 # /// script 代码块中列出所有依赖项,以便在笔记本启动时自动安装。检查以下问题:
# /// script 代码块,发出警告建议添加。列出依赖项可确保在 WASM 中启动笔记本时自动安装——否则用户可能会看到导入错误。输出清晰、可操作的报告,包含以下部分:
兼容性:通过 / 失败 / 警告
使用以下判定:
包报告 —— 包含以下列的表格:包、状态(正常 / 警告 / 失败)、备注
示例:
| 包 | 状态 | 备注 |
|---|---|---|
| marimo | 正常 | WASM 运行时中可用 |
| numpy | 正常 | Pyodide 内置 |
| pandas | 正常 | Pyodide 内置 |
| torch | 失败 | 无 WASM 构建——需要原生 C++/CUDA 扩展 |
| my-niche-lib | 警告 | 不在 Pyodide 中;请验证其为纯 Python |
代码问题 —— 列出发现的每个有问题的代码模式,包含单元格或行号以及修复建议。
建议 —— 如果笔记本失败,提供具体修复建议:
micropip 可以在运行时从 PyPI 安装任何纯 Python 轮子文件每周安装次数
343
代码仓库
GitHub 星标数
77
首次出现
2026年2月27日
安全审计
已安装于
claude-code278
codex205
opencode189
gemini-cli177
github-copilot175
kimi-cli174
Check whether a marimo notebook can run in a WebAssembly (WASM) environment — the marimo playground, community cloud, or exported WASM HTML.
Read the target notebook file. If the user doesn't specify one, ask which notebook to check.
Collect every package the notebook depends on from both sources:
PEP 723 metadata — the # /// script block at the top:
# /// script
Import statements — scan all cells for import foo and from foo import bar. Map import names to their PyPI distribution name using this table:
| Import name | Distribution name |
|---|---|
sklearn | scikit-learn |
skimage | scikit-image |
cv2 | opencv-python |
PIL | Pillow |
For most other packages, the import name matches the distribution name.
For each dependency, determine if it can run in WASM:
Is it in the Python standard library? Most stdlib modules work, but these do not :
multiprocessing — browser sandbox has no process spawningsubprocess — same reasonthreading — emulated, no real parallelism (WARN, not a hard fail)sqlite3 — use apsw instead (available in Pyodide)pdb — not supportedtkinter — no GUI toolkit in browserreadline — no terminal in browserIs it a Pyodide built-in package? See for the full list. These work out of the box.
Common pure-Python packages that work (not in Pyodide built-ins but installable via micropip):
* `plotly`, `seaborn`, `humanize`, `pendulum`, `arrow`, `tabulate`
* `dataclasses-json`, `marshmallow`, `cattrs`, `pydantic` (built-in)
* `httpx` (built-in), `tenacity`, `backoff`, `wrapt` (built-in)
4. Does it have C/native extensions not built for Pyodide? These will not work. Common culprits:
* `torch` / `pytorch`
* `tensorflow`
* `jax` / `jaxlib`
* `psycopg2` (suggest `psycopg` with pure-Python mode)
* `mysqlclient` (suggest `pymysql`)
* `uvloop`
* `grpcio`
* `psutil`
Scan the notebook code for patterns that won't work in WASM:
| Pattern | Why it fails | Suggestion |
|---|---|---|
subprocess.run(...), os.system(...), os.popen(...) | No process spawning in browser | Remove or gate behind a non-WASM check |
multiprocessing.Pool(...), ProcessPoolExecutor | No process forking | Use single-threaded approach |
threading.Thread(...), ThreadPoolExecutor |
WASM notebooks should list all dependencies in the PEP 723 # /// script block so they are automatically installed when the notebook starts. Check for these issues:
# /// script block, emit a WARN recommending one. Listing dependencies ensures they are auto-installed when the notebook starts in WASM — without it, users may see import errors.Output a clear, actionable report with these sections:
Compatibility: PASS / FAIL / WARN
Use these verdicts:
Package Report — table with columns: Package, Status (OK / WARN / FAIL), Notes
Example:
| Package | Status | Notes |
|---|---|---|
| marimo | OK | Available in WASM runtime |
| numpy | OK | Pyodide built-in |
| pandas | OK | Pyodide built-in |
| torch | FAIL | No WASM build — requires native C++/CUDA extensions |
| my-niche-lib | WARN | Not in Pyodide; verify it is pure-Python |
Code Issues — list each problematic code pattern found, with the cell or line and a suggested fix.
Recommendations — if the notebook fails, suggest concrete fixes:
micropip can install any pure-Python wheel from PyPI at runtimeWeekly Installs
343
Repository
GitHub Stars
77
First Seen
Feb 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
claude-code278
codex205
opencode189
gemini-cli177
github-copilot175
kimi-cli174
xdrop 文件传输脚本:Bun 环境下安全上传下载工具,支持加密分享
20,700 周安装
bs4 |
beautifulsoup4 |
yaml | pyyaml |
dateutil | python-dateutil |
attr / attrs | attrs |
gi | PyGObject |
serial | pyserial |
usb | pyusb |
wx | wxPython |
Is it a pure-Python package? Packages with only .py files (no compiled C/Rust extensions) can be installed at runtime via micropip and will work. To check: look for a py3-none-any.whl wheel on PyPI (e.g. visit https://pypi.org/project/<package>/#files). If the only wheels are platform-specific (e.g. cp312-cp312-manylinux), the package has native extensions and likely won't work.
| Emulated threads, no real parallelism |
WARN only — works but no speedup; use asyncio for I/O |
open("/absolute/path/..."), hard-coded local file paths | No real filesystem; only in-memory fs | Fetch data via URL (httpx, urllib) or embed in notebook |
sqlite3.connect(...) | stdlib sqlite3 unavailable | Use apsw or duckdb |
pdb.set_trace(), breakpoint() | No debugger in WASM | Remove breakpoints |
Reading env vars (os.environ[...], os.getenv(...)) | Environment variables not available in browser | Use mo.ui.text for user input or hardcode defaults |
Path.home(), Path.cwd() with real file expectations | Virtual filesystem only | Use URLs or embedded data |
| Large dataset loads (>100 MB) | 2 GB total memory cap | Use smaller samples or remote APIs |