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 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
-
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. -
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_httpbin.py | Execute a wasi program and http get from http://httpbin.org |
example/wasi_ll.py | Execute a wasi program and list information about a directory |
example/wasi_zen.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
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-2.1.5.tar.gz
.
File metadata
- Download URL: pywasm-2.1.5.tar.gz
- Upload date:
- Size: 4.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
162acd572a9ca0aabe13fc8ea7cb87c5853bc96a4f08a66f14ca0d7e24b51f8f
|
|
MD5 |
47d261447f57358d459d17300be2a111
|
|
BLAKE2b-256 |
7a1616d6e07804c68ae7a21fc67830cc3ee373ebdd1f3ddb74f9642bf41a998b
|
File details
Details for the file pywasm-2.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: pywasm-2.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 34.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
1b53be435256ec99d54dbdf9d5ab52bac248e687150b4316d8178dc79f163796
|
|
MD5 |
34ebe27cf9adc107c0b717ee07f46177
|
|
BLAKE2b-256 |
bafa028dbe97c088a38c93342f230597340ec2bf31cd28c8a1f9a8c25b4f751b
|