Python bindings for Wasm3, a fast WebAssembly interpreter and the most universal WASM runtime.
Main repository: Wasm3 project
Requires CPython 3.11+. Wheels are cp311-abi3, so one wheel per platform covers 3.11 and newer.
pip install pywasm3
pip install "pywasm3 @ git+https://github.com/wasm3/pywasm3" # bleeding edge
pip install . # local copyWith uv:
uv add pywasm3
uv add "pywasm3 @ git+https://github.com/wasm3/pywasm3" # bleeding edge
uv run --with pywasm3 python my_script.py # without a projectimport wasm3
WAT = """
(module
(func $fib (export "fib") (param $n i64) (result i64)
(if (i64.lt_u (local.get $n) (i64.const 2))
(then (return (local.get $n))))
(return (i64.add (call $fib (i64.sub (local.get $n) (i64.const 2)))
(call $fib (i64.sub (local.get $n) (i64.const 1))))))
)
"""
env = wasm3.Environment()
rt = env.new_runtime(2048)
mod = env.parse_module(WAT) # or a binary module, as bytes
rt.load(mod)
wasm_fib = rt.find_function("fib")
result = wasm_fib(24)
print(result) # 46368Every script in examples/ carries its dependencies inline (PEP 723), so
uv run sets up an environment for it on the fly — nothing to install first:
uv run examples/00-fibonacci.py # wasm3 vs. pure Python fib(24)
uv run examples/01-coremark.py # CoreMark benchmark
uv run examples/02-metered.py # gas metering
uv run examples/03-asyncified.py # asyncified module driven by asyncio
uv run examples/04-suspend-resume.py # pause, snapshot, Ctrl+C, resume in a new process
uv run examples/pygame-doomfire.py # one of the pygame demosThe scripts resolve pywasm3 from this checkout, so they build the extension you have
locally. Add --no-sources to run them against the released package instead:
uv run --no-sources examples/00-fibonacci.py- Text format - the bundled
wat2wasm/wasm2wat - Suspend, resume and snapshots - pause a call, save it, pick it up in another process
- Exceptions - Wasm exceptions in and out of the guest, and Python ones through it
- Development - building from source, tests, releases
This project is released under The MIT License (MIT)