Skip to main content
Pyodide runs Python with packages such as numpy in Node and browsers. Workspace file access follows the same permissions as shell commands, and each command starts with fresh Python state. TypeScript SDK only. Pyodide does not provide isolation for hostile code. Host and network access depend on the environment and configuration; see containment before choosing it for untrusted programs.

Installation

Node
In a browser, install @struktoai/mirage-browser and @struktoai/mirage-core instead: Pyodide loads from its CDN or home, not the pyodide package. The page must be cross-origin isolated or registered with Mirage’s service worker; see worker and browser setup.

Usage

Packages

Pyodide’s packages, such as numpy, load when a program imports them. The first import downloads the package from the Pyodide CDN; Node keeps it beside the installed pyodide package for later runs.
A package from PyPI cannot be installed at run time: micropip.install fails. Put its pure-Python wheel on a mount and list it in sys_path.

Memory

max_memory caps the memory one run may grow to:
A run starts at about 50M. One that passes the cap fails with MemoryError, and the next run starts fresh. Node stops the run when it passes the cap; browsers check the cap when the run ends. Without its own max_memory, a run may grow by what its workspace’s max_memory has left, 96 MB by default, past what the interpreter and its packages take to start.

Python compatibility

Examples assume a writable /data mount. Mount modes and permissions still apply.

open()

Modes and modifiers are listed separately; for example, rb combines r and b. The file is read when it is opened.

File objects

os

File operations

Directory operations

Environment and working directory

os.path

pathlib

sys

time and datetime

The clocks start at the workspace’s system time when it sets one, and files the program writes are stamped from the same clock. time.monotonic() and time.perf_counter() measure elapsed time.

json

glob

shutil

  • shutil.which(): Resolves executable names through Mirage’s command lookup.

subprocess

Processes and signals

socket

Network connections are unavailable in this runtime.

mmap

Unavailable in this runtime.

Notes

Files written outside the mounts stay in memory and are lost when the run ends.