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 Specification, Release 2.0 (Draft 2024-11-12).

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

Uploaded Source

Built Distribution

pywasm-2.0.0-py2.py3-none-any.whl (22.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for pywasm-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f9ae3804325bb7ac72e3df2e881fa249c22dd6146680f78b7e5b6f3105cf4299
MD5 530dcb2ee6a1554b1edc489e8b230573
BLAKE2b-256 7fd5f3b9a30ddb96227be095fa52a627dfcc47740bdb32331e9f7a031fca7467

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywasm-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.1 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-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 52db150d3ee466a62de553c3f5776748179a2abd22286e2303185b5a5ecb73ed
MD5 44bf80d482c3b87bc08d35adc2d33eae
BLAKE2b-256 486f79db73ad56145a1c8402bb8f80c2a147599081e3386e57a166fe9b5ac0b6

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