Skip to main content

WebAssembly from Python.

Project description

AppVeyor Build status

wasmpy

WebAssembly in Python.

Wasmpy is a lightweight layer that sits between Python and WebAssembly. When attempting to import a WebAssembly file, the file is converted into machine code for native speeds.

Installing

python3 -m pip install wasmpy

Usage

To get started, first import the wasmpy module to register the WebAssembly import hooks.

Then you can just import wasm_or_wat_file to load a WebAssembly module.

Example

|-  my_module
    |-  __init__.py
    |-  wasm_math.wat

File: __init__.py

import wasmpy
from .wasm_math import add

File: wasm_math.wat

(module
    (func (export "add") (param i32 i32) (result i32)
        (i32.add (local.get 0) (local.get 1))
    )
)
>>> import my_module
>>> my_module.add(45, 960)
1005
>>>

Building From Source

On Windows this requires the mingw-w64 as tool to be on PATH.

git clone https://github.com/olivi-r/wasmpy.git
cd wasmpy
python3 setup.py assemble
python3 -m pip install .

Limitations

Wasmpy is still in active development, and only supports x86/x86-64 Windows and Linux machines and lacks some key features:

  • i64.div_s, i64.div_u, i64.rem_s and i64.rem_u instructions on x86
  • memories and memory instructions
  • most control instructions
  • imports
  • tables

Wasmpy is being developed in accordance with the wasm-core-1 recommendation, which means it lacks support for features introduced in WebAssembly 2.0 drafts.

In future all of these limitations will be overcome and wasmpy will offer support for WASI and allow interfacing directly with CPython's c-api similar to standard C/C++ Python extensions.

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

wasmpy-0.2.0.tar.gz (48.6 kB view hashes)

Uploaded Source

Built Distributions

wasmpy-0.2.0-cp36-abi3-win_amd64.whl (56.0 kB view hashes)

Uploaded CPython 3.6+ Windows x86-64

wasmpy-0.2.0-cp36-abi3-win32.whl (49.6 kB view hashes)

Uploaded CPython 3.6+ Windows x86

wasmpy-0.2.0-cp36-abi3-musllinux_1_1_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.6+ musllinux: musl 1.1+ x86-64

wasmpy-0.2.0-cp36-abi3-musllinux_1_1_i686.whl (987.0 kB view hashes)

Uploaded CPython 3.6+ musllinux: musl 1.1+ i686

wasmpy-0.2.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (510.1 kB view hashes)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ x86-64

wasmpy-0.2.0-cp36-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (411.4 kB view hashes)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

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