Skip to main content

WebAssembly Interpreter by pure Python

Project description

pywasm: A WebAssembly interpreter written in pure Python.

Build Status

A WebAssembly interpreter written in pure Python.

The wasm version currently in use is: WebAssembly Core Specification, W3C Recommendation, 5 December 2019. Just like Firefox or Chrome does.

Installation

$ pip3 install pywasm

Some simple examples

  1. 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 by WasmFiddle.

  2. Now, compile and instantiate WebAssembly modules directly from underlying sources. This is achieved using the pywasm.load method.

import pywasm
# pywasm.on_debug()

runtime = pywasm.load('./examples/fib.wasm')
r = runtime.exec('fib', [10])
print(r) # 55

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

Of course there are some more complicated examples!

Test

$ python3 ./test/test_spec.py

Tested in the following environments:

  • Python >= 3.6

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-1.0.3.tar.gz (28.9 kB view details)

Uploaded Source

File details

Details for the file pywasm-1.0.3.tar.gz.

File metadata

  • Download URL: pywasm-1.0.3.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.4

File hashes

Hashes for pywasm-1.0.3.tar.gz
Algorithm Hash digest
SHA256 379f6343c301330b587b04a185e5edf8d99d378a8800ddff9b3b828b15b47d31
MD5 76ba982d610b2a364521a3a87184f541
BLAKE2b-256 0b2bbb187d998172343b447f18ceafe75304ff3849f8eab670adfe6c93957271

See more details on using hashes here.

Supported by

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