WebAssembly Interpreter by pure Python
pywasm: A WebAssembly interpreter written in pure Python.
A WebAssembly interpreter written in pure Python.
The wasm version currently in use is: WebAssembly Core Specification, W3C Recommendation, 5 December 2019. Just like Firefox or Chrome does.
$ pip3 install pywasm
Some simple examples
First we need a wasm module! Grab our
./examples/fib.wasmfile and save a copy in a new directory on your local machine. Note:
fib.wasmwas compiled from
Now, compile and instantiate WebAssembly modules directly from underlying sources. This is achieved using the
import pywasm # pywasm.on_debug() runtime = pywasm.load('./examples/fib.wasm') r = runtime.exec('fib', ) print(r) # 55
A brief description for
|./examples/add.wasm||Export i32.add function|
|./examples/env.wasm||Call python/native function in wasm|
|./examples/fib.wasm||Fibonacci, which contains loop and recursion|
|./examples/str.wasm||Export a function which returns string|
|./examples/sum.wasm||Equal difference series summation|
Of course there are some more complicated examples!
- Zstandard decompression algorithm: https://github.com/dholth/zstdpy
- Run AssemblyScript on pywasm: https://github.com/mohanson/pywasm_assemblyscript
$ python3 ./test/test_spec.py
Tested in the following environments:
- Python >= 3.6
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.