libraries/pywasm

A WebAssembly interpreter written in pure Python

WebAssembly

518

181 commits

updated Sep 18, 2026

See the code

README

Pywasm: A WebAssembly interpreter written in pure Python.

A WebAssembly interpreter written in pure Python, no third-party libraries are used.

img

The wasm version currently in use is: WebAssembly Specification, Release 2.0 (Draft 2025-04-25).

The wasi version currently in use is: WASI Preview 1.

Also requires Python version >= 3.12.

Installation

$ pip install pywasm

Some simple examples

  1. First we need a wasm module! Grab our example/fibonacci/bin/fibonacci.wasm file and save a copy in a new directory on your local machine.

  2. Now, instantiate WebAssembly modules directly from underlying sources. This is achieved using the Runtime.instance_from_file method.

import pywasm
pywasm.log.lvl = 1

runtime = pywasm.core.Runtime()
m = runtime.instance_from_file('example/fibonacci/bin/fibonacci.wasm')
r = runtime.invocate(m, 'fibonacci', [10])
print(f'fibonacci(10) = {r[0]}')

A brief description for example

FileDescription
example/blake2b.pyBlake2b hashing algorithm
example/blake2b_direct.pyMake the hash result returned as a value, not as an output parameter
example/blake2b_iter.pyA benchmarking example using the blake2b hash function
example/blake2b_simd.pyUse SIMD instructions to accelerate the blake2b hash function
example/fibonacci.pyFibonacci, which contains loop and recursion
example/fibonacci_env.pyCall python/native function in wasm
example/pi.pyCalculate π using the agm algorithm
example/wasi_httpbin.pyExecute a wasi program and http get from http://httpbin.org
example/wasi_ll.pyExecute a wasi program and list information about a directory
example/wasi_stdout.pyExecute a wasi program and capture stdout
example/wasi_zen.pyExecute a wasi program and print poem "The Zen of Python"

Test

$ python script/build_wabt.py # Download wabt tools at res/wabt.
$ python script/build_spec.py # Download spec tests at res/spec.
$ python script/build_wasi.py # Download wasi tests at res/wasi-testsuite.

$ python test/example.py      # Test example.
$ python test/main.py         # Test main.
$ python test/spec.py         # Test spec.
$ python test/wasi.py         # Test wasi.

Performance

Pywasm is an interpreter implemented using pure python and its standard library, capable of running on any python platform. Due to the inherent characteristics of python, you should not have overly high expectations for pywasm's performance.

However, pywasm's design makes it jit-friendly. Compared to cpython, pywasm's performance on pypy can improve by approximately 10 times, significantly surpassing the average 3-fold improvement.

Thanks

License

MIT

webassembly

libraries/pywasm

A WebAssembly interpreter written in pure Python

WebAssembly

518

181 commits

updated Sep 18, 2026

See the code

README

Pywasm: A WebAssembly interpreter written in pure Python.

A WebAssembly interpreter written in pure Python, no third-party libraries are used.

img

The wasm version currently in use is: WebAssembly Specification, Release 2.0 (Draft 2025-04-25).

The wasi version currently in use is: WASI Preview 1.

Also requires Python version >= 3.12.

Installation

$ pip install pywasm

Some simple examples

  1. First we need a wasm module! Grab our example/fibonacci/bin/fibonacci.wasm file and save a copy in a new directory on your local machine.

  2. Now, instantiate WebAssembly modules directly from underlying sources. This is achieved using the Runtime.instance_from_file method.

import pywasm
pywasm.log.lvl = 1

runtime = pywasm.core.Runtime()
m = runtime.instance_from_file('example/fibonacci/bin/fibonacci.wasm')
r = runtime.invocate(m, 'fibonacci', [10])
print(f'fibonacci(10) = {r[0]}')

A brief description for example

FileDescription
example/blake2b.pyBlake2b hashing algorithm
example/blake2b_direct.pyMake the hash result returned as a value, not as an output parameter
example/blake2b_iter.pyA benchmarking example using the blake2b hash function
example/blake2b_simd.pyUse SIMD instructions to accelerate the blake2b hash function
example/fibonacci.pyFibonacci, which contains loop and recursion
example/fibonacci_env.pyCall python/native function in wasm
example/pi.pyCalculate π using the agm algorithm
example/wasi_httpbin.pyExecute a wasi program and http get from http://httpbin.org
example/wasi_ll.pyExecute a wasi program and list information about a directory
example/wasi_stdout.pyExecute a wasi program and capture stdout
example/wasi_zen.pyExecute a wasi program and print poem "The Zen of Python"

Test

$ python script/build_wabt.py # Download wabt tools at res/wabt.
$ python script/build_spec.py # Download spec tests at res/spec.
$ python script/build_wasi.py # Download wasi tests at res/wasi-testsuite.

$ python test/example.py      # Test example.
$ python test/main.py         # Test main.
$ python test/spec.py         # Test spec.
$ python test/wasi.py         # Test wasi.

Performance

Pywasm is an interpreter implemented using pure python and its standard library, capable of running on any python platform. Due to the inherent characteristics of python, you should not have overly high expectations for pywasm's performance.

However, pywasm's design makes it jit-friendly. Compared to cpython, pywasm's performance on pypy can improve by approximately 10 times, significantly surpassing the average 3-fold improvement.

Thanks

License

MIT

webassembly

Project health

PyPI

Latest release

2.2.3 · May 13, 2026

Releases this year

2

Significant stargazers

John Nunley

334 followers · starred Aug 2023

Linwei

7,255 followers · starred Jun 2026

Simon Shi

289 followers · starred Oct 2022

Shane F. Carr

293 followers · starred Jul 2019