Skip to main content

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.

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/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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywasm-2.1.5.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

pywasm-2.1.5-py2.py3-none-any.whl (34.8 kB view details)

Uploaded Python 2Python 3

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

Hashes for pywasm-2.1.5.tar.gz
Algorithm Hash digest
SHA256 162acd572a9ca0aabe13fc8ea7cb87c5853bc96a4f08a66f14ca0d7e24b51f8f
MD5 47d261447f57358d459d17300be2a111
BLAKE2b-256 7a1616d6e07804c68ae7a21fc67830cc3ee373ebdd1f3ddb74f9642bf41a998b

See more details on using hashes here.

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

Hashes for pywasm-2.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b53be435256ec99d54dbdf9d5ab52bac248e687150b4316d8178dc79f163796
MD5 34ebe27cf9adc107c0b717ee07f46177
BLAKE2b-256 bafa028dbe97c088a38c93342f230597340ec2bf31cd28c8a1f9a8c25b4f751b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page