Run Python code using Pyodide (CPython compiled to WebAssembly)

Synopsis

python3 -c <code> [args...]

python3 <script.py> [args...]

echo "code" | python3

Description

Executes Python 3.12 code in the browser using Pyodide, a full CPython interpreter compiled to WebAssembly. Before execution, the virtual filesystem contents (current working directory, /tmp, and the script's directory) are synced into Pyodide's Emscripten filesystem so Python's os and file I/O modules can access them. After execution, any files created or modified by Python are synced back to the VFS.

Standard Python libraries bundled with Pyodide are available. The command is also available as python (alias).

Options

-c <code> Execute the given Python code inline

-V, --version Print the Python version (Python 3.12 (Pyodide))

-h, --help Show usage information

Examples

$ python3 -c "print('hello world')"

Execute inline Python code.

$ python3 script.py arg1 arg2

Run a Python script from the virtual filesystem with arguments available via sys.argv.

$ echo "import math; print(math.pi)" | python3

Pipe Python code through stdin.

$ python3 -c "import os; print(os.listdir('.'))"

List files in the current directory using Python's os module.

Notes

Pyodide runs CPython 3.12 compiled to WebAssembly, so most pure-Python packages work. C-extension packages must be pre-built for Emscripten to be importable. The Pyodide runtime is loaded lazily on first use from a CDN, so the first invocation may take a moment.

The filesystem sync is bidirectional: VFS contents are copied into Pyodide before execution, and any changes Python makes are written back afterward. The working directory inside Pyodide matches the shell's current directory. Interactive REPL mode is not supported — provide code via -c, a script path, or stdin.

See Also

node, commands