Skip to main content

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

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/blake2b_iter.py A benchmarking example using the blake2b hash function
example/blake2b_simd.py Use SIMD instructions to accelerate the blake2b hash function
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_stdout.py Execute a wasi program and capture stdout
example/wasi_zen.py Execute 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

Release files for pywasm 2.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywasm 2.2.3
File Size Uploaded
pywasm-2.2.3.tar.gz 631.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pywasm 2.2.3
File Interpreter ABI Platform
pywasm-2.2.3-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 676.5 kB

Release files / pywasm-2.2.3.tar.gz

Download URL pywasm-2.2.3.tar.gz
Size 631.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bc5c2aaed73d43fdfab0c6c6dc3a05b4c2de176fbbf94dd258f4f26d135f0ff1
BLAKE2b-256 checksum
How to use checksums
2051337c1ebcf5a534153c1d65e90bc0bcbfb3713b6f398d790b6ef4beede7f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / pywasm-2.2.3-py2.py3-none-any.whl

Download URL pywasm-2.2.3-py2.py3-none-any.whl
Size 44.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5bc0d4fa7a4404937b1f0fa7ca4622a70ddbef0491869f5aef7b2a1018f37aa0
BLAKE2b-256 checksum
How to use checksums
73637a6587416281ddcd987b2a19e79406c9ba13b63fd5c7ae34ae35a06f89b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

2.2.3 This release

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

2 release files

1.0.0

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.5

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page