cpython/Platforms/WASI
Mazin Sharaf 8a73478fed
gh-145844: Update WASI SDK from 30 to 32 (#145859)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
2026-04-06 16:48:38 -07:00
..
.ruff.toml Refactor Platforms/WASI/__main__.py for lazy importing and future new subcommands (#145404) 2026-03-04 13:27:23 -08:00
__main__.py Refactor Platforms/WASI/__main__.py for lazy importing and future new subcommands (#145404) 2026-03-04 13:27:23 -08:00
_build.py Refactor Platforms/WASI/__main__.py for lazy importing and future new subcommands (#145404) 2026-03-04 13:27:23 -08:00
config.site-wasm32-wasi GH-143941: Move WASI-related files to Platforms/WASI (GH-143942) 2026-01-21 14:31:58 -08:00
config.toml gh-145844: Update WASI SDK from 30 to 32 (#145859) 2026-04-06 16:48:38 -07:00
README.md GH-143941: Move WASI-related files to Platforms/WASI (GH-143942) 2026-01-21 14:31:58 -08:00
wasmtime.toml GH-143941: Move WASI-related files to Platforms/WASI (GH-143942) 2026-01-21 14:31:58 -08:00

Python WASI (wasm32-wasi) build

WASI support is tier 2.

This directory contains configuration and helpers to facilitate cross compilation of CPython to WebAssembly (WASM) using WASI. WASI builds use WASM runtimes such as wasmtime.

NOTE: If you are looking for general information about WebAssembly that is not directly related to CPython, please see https://github.com/psf/webassembly.

Build

See the devguide on how to build and run for WASI.

Detecting WASI builds

Python code

import os, sys

if sys.platform == "wasi":
    # Python on WASI
    ...

if os.name == "posix":
    # WASM platforms identify as POSIX-like.
    # Windows does not provide os.uname().
    machine = os.uname().machine
    if machine.startswith("wasm"):
        # WebAssembly (wasm32, wasm64 potentially in the future)
>>> import os, sys
>>> os.uname()
posix.uname_result(
    sysname='wasi',
    nodename='(none)',
    release='0.0.0',
    version='0.0.0',
    machine='wasm32'
)
>>> os.name
'posix'
>>> sys.platform
'wasi'

C code

WASI SDK defines several built-in macros. You can dump a full list of built-ins with /path/to/wasi-sdk/bin/clang -dM -E - < /dev/null.

  • WebAssembly __wasm__ (also __wasm)
  • wasm32 __wasm32__ (also __wasm32)
  • wasm64 __wasm64__
  • WASI __wasi__