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 Working Draft, 4 September 2018. 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()

vm = pywasm.load('./examples/fib.wasm')
r = vm.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

$ python ./test/test_spec.py

Tested in the following environments:

  • Python >= 3.6

Thanks

License

WTFPL

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywasm-0.4.8-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pywasm-0.4.8.tar.gz
  • Upload date:
  • Size: 23.0 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-0.4.8.tar.gz
Algorithm Hash digest
SHA256 47c5321d77c60b3de74c5137c122fb9bf0f050efe8f8bc3d00d8c9b42dcf6880
MD5 f11370ca2dae9e57335e7b3cd0d246e0
BLAKE2b-256 e6e19291ba9533f94f1ea9b19eb519ad7a125db2d556350c6ee68d72e533e28f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywasm-0.4.8-py3-none-any.whl
  • Upload date:
  • Size: 23.0 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-0.4.8-py3-none-any.whl
Algorithm Hash digest
SHA256 66a0099dac0606b32d9482314af9d45704522c8d68444265ac4e088effd4a535
MD5 8ddb04533306d4fda1aa97b642142c7a
BLAKE2b-256 72d97beb72ad2ffd591ca96978e80027708c50647ebf28aa35f2f5836e725418

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