Skip to content

mohanson/pywasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

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

File Description
example/blake2b.py Blake2b hashing algorithm
example/blake2b_direct.py Make the hash result returned as a value, not as an output parameter
example/fibonacci.py Fibonacci, which contains loop and recursion
example/fibonacci_env.py Call python/native function in wasm
example/pi.py Calculate π using the agm algorithm
example/wasi_print.py Execute a wasi program and print poem "The Zen of Python"

Test

$ python test/example.py
$ python test/spec.py
$ python test/wasi.py

Thanks

License

MIT

About

A WebAssembly interpreter written in pure Python

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6