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

Uploaded Source

Built Distribution

pywasm-1.0.1-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pywasm-1.0.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.1

File hashes

Hashes for pywasm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a94cbcafe88a4416343323eec2c4e1b6e1732b94431dd7a2a631957727c986f3
MD5 7025eca3cdb1d40dfb5f857f29c47bee
BLAKE2b-256 e320712ed04eac39e16b07a543d1d07ed8be54f8f3dd30cd1905cdcde331250d

See more details on using hashes here.

File details

Details for the file pywasm-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pywasm-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.1

File hashes

Hashes for pywasm-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7efd2e805bbf13773d43b8e9f85fa493b03d0413a36c8e3ba2d621317f99e7b2
MD5 d0d888134664d61e62110627499ebc6d
BLAKE2b-256 230ac6cdb30c8ab16f19a489c38abcef81b15e89c4f8172b4e93b0d7a414b557

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