Python code insideDocumentation Index
Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
Use this file to discover all available pages before exploring further.
ws.execute('python3 ...') can open(), os.listdir(), pathlib.Path() etc. against any registered Mirage mount. The shim routes those calls through Mirage’s mount layer (RAM, S3, Linear, GDocs, Slack, anything you’ve registered).
What works
- Read a file
- Write a file
- List a directory
- pathlib & glob
- Native libs
- Cross-mount
What doesn’t work
| Case | Why | Workaround |
|---|---|---|
C extensions calling fopen directly, sqlite3.connect('/ram/db.sqlite'), h5py.File('/ram/x.h5') | They bypass Python’s open() and the shim never sees them | Use a local copy, or stream bytes via stdin |
| External edits show up live, someone else edits the GDoc while you’re reading | Once a path is in MEMFS the shim doesn’t re-fetch it | Currently no API; must unmount + addMount |
| Huge mounts, preloading a 100GB S3 bucket | Every byte lives in MEMFS until close | Mount a narrower prefix |
| Concurrent writers, two Python processes write the same path | Last close() wins, no conflict detection | Out of scope for v1 |
| Browser-only resources from Node, OPFS | OPFS isn’t a thing in Node | Run in a browser-side Mirage |
How it works (one paragraph)
Pyodide’s in-memory FS (MEMFS) is the sync facade. AtaddMount, Mirage walks the prefix and copies files into MEMFS. Python reads hit MEMFS directly, fast, no network. On a miss (path not yet in MEMFS but the prefix is registered), the shim catches the error, calls back through the bridge via JSPI to fetch it, populates MEMFS, and retries. Writes are intercepted on close() and flushed back through Mirage’s write op.
Quick start (TypeScript)
examples/typescript/python/vfs.ts.
Python packages (PIL, numpy, pandas, …)
Pyodide ships CPython, but third-party packages aren’t loaded until you import them. Mirage scans the code you run forimport statements and auto-fetches matching packages on demand, so from PIL import Image, import numpy as np, import pandas as pd all just work the first time. Subsequent calls hit Pyodide’s package cache.
If you need to opt out (e.g., to keep workspace startup lean):
Resource compatibility
| Resource | Status |
|---|---|
| RAM, OPFS (browser), Disk | ✅ |
| S3, R2, GCS, OCI, Supabase | ✅ (narrow the prefix to keep the working set small) |
| Linear, GDocs, GSheets, GSlides, GDrive | ✅ |
| GitHub, Redis | ✅ |
| Gmail (including synthesized date dirs) | ✅ (lazy-fetched on first access) |
| Slack | ⚠️ preloads channel histories; large workspaces may be slow |
Runtime requirements
The shim uses JSPI to bridge sync Python calls to async JS.- Chrome / Edge 137+ (May 2025): works out of the box
- Firefox: behind
javascript.options.wasm_js_promise_integration - Node 24+: pass
--experimental-wasm-jspi(vitest config already does this) - Cloudflare Workers: Python Workers with JSPI runtime
Without JSPI, reads of preloaded files still work but writes throw
RuntimeError: Cannot stack switch on close().Errors you might see
| Symptom | What it means |
|---|---|
FileNotFoundError [Errno 44] | Path isn’t in MEMFS and lazy fetch failed too. Check the preceding console.warn: mirage lazy: ... for the real reason (auth, network, bad path). |
console.warn: mirage lazy: list <path> failed | The lazy backfill called _mirage_bridge.list and got rejected. Followed by FileNotFoundError. |
RuntimeError: Cannot stack switch | JSPI not enabled. Pass the Node flag or upgrade browser. |
console.warn: mirage preload: skipping <path> | A single entry failed during initial preload, others continued. Usually harmless (synthetic listing entries). |
See also
python: broaderpython3builtin behavior (env, argv, stdin, exit codes)examples/typescript/python/vfs.ts: runnable demo across RAM, S3, GDocs, Linear