WebAssembly Interpreter by pure Python
Project description
Pywasm: A WebAssembly interpreter written in pure Python.
A WebAssembly interpreter written in pure Python, no third-party libraries are used.
The wasm version currently in use is: WebAssembly Specification, Release 2.0 (Draft 2024-10-29).
Also requires Python version >= 3.12.
Installation
$ pip install pywasm
Some simple examples
-
First we need a wasm module! Grab our
./examples/fib.wasm
file and save a copy in a new directory on your local machine. Note:fib.wasm
was compiled from./examples/fib.c
. -
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('./examples/fib.wasm', {})
r = runtime.invocate(m, 'fib', [10])
print(f'fib(10) = {r[0]}')
A brief description for ./examples
File | Description |
---|---|
./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 |
Test
$ python ./test/test_spec.py
Thanks
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pywasm-1.2.1.tar.gz
.
File metadata
- Download URL: pywasm-1.2.1.tar.gz
- Upload date:
- Size: 924.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ca10ec24d7328bc055dbedcb9e11fec87c100b3daf9ac4e5f05882b13895472 |
|
MD5 | 923f32eeaeb32552473c4873179b5fcc |
|
BLAKE2b-256 | 80499a846070ebb644e81a7de349b130c4eafbc78714061c1374f63fe68dfc1c |
File details
Details for the file pywasm-1.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pywasm-1.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e6391117acbf30db64d2c32dda3dcc9f9d7538b4c3a41b66361685b9538909d |
|
MD5 | e8b45e53fe9374425a41da0ebf31e7c4 |
|
BLAKE2b-256 | 4988acd547e3dcb23f8c2ba59bd7fc67820d574a6c580fab320079b4cd4e1171 |