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

Uploaded Source

Built Distribution

pywasm-1.1.0-py2.py3-none-any.whl (19.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: pywasm-1.1.0.tar.gz
  • Upload date:
  • Size: 522.4 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.0.tar.gz
Algorithm Hash digest
SHA256 7aecbfab433a9e6bcb66f6a615c9524dbe31cce77c55c156ef3856aa05bb6ca0
MD5 235b6713d97a7421d80007ef6ccd91f1
BLAKE2b-256 fbaf1746910c9287f19da3ec01d1df87a3233e5f15a334349697ee12bdfa4ffe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pywasm-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.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-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8224730a662da5e9e694c45960b65a8ab42414aaf325064887a19de40ecd19c4
MD5 06ddde993bc192b7820bdf7a4de1d9be
BLAKE2b-256 541cdad4eaf307a4c7d0aa9c74aaa3ff10599848cd97dd7ffdf379f164f791d9

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