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.

The wasm version currently in use is: WebAssembly Core Specification, W3C Recommendation, 5 December 2019.

Also requires Python version >= 3.12.

Installation

$ pip 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.

  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('./examples/fib.wasm', {})
r = runtime.invocate(m, 'fib', [10])
print(f'fib(10) = {r[0]}')

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

Test

$ python ./test/test_spec.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-1.1.1.tar.gz (545.7 kB view details)

Uploaded Source

Built Distribution

pywasm-1.1.1-py2.py3-none-any.whl (19.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: pywasm-1.1.1.tar.gz
  • Upload date:
  • Size: 545.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pywasm-1.1.1.tar.gz
Algorithm Hash digest
SHA256 961f1c785c9fef6fe13f586c8c4b2446af7caf7ec3bcdc5023573bc8331b4751
MD5 8f7dbd104b7fff58561beaf9e962b4fa
BLAKE2b-256 f5cdaa4fe5d869f9bde527464b49d0c295d689226ca8294cf98f07cc9ddc22e9

See more details on using hashes here.

File details

Details for the file pywasm-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pywasm-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pywasm-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 52b10b7b7970afc426e4be5d67512ecfa99e8d12d6c70772e7fdb586815cf9c6
MD5 0cfc60cf62acc375c34ffaf6f3c6ba65
BLAKE2b-256 2f3731556a835ce256502aaf3fd97d8d066432fda1c42865444181dabde968c8

See more details on using hashes here.

Supported by

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