Skip to main content

Interactions between WebAssembly and Python

Project description

WasmPy

Interacting with WebAssembly code from python.

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

This project is intended to be used in conjunction with wasmpy-build, although it does support regular WebAssembly files too.

Installing

Install the latest version:

$ python -m pip install wasmpy

Or build and install from source:

$ git clone https://github.com/olivi-r/wasmpy.git
$ cd wasmpy
$ python setup.py install

Usage

WasmPy defines import hooks to make the loading of WebAssembly binary files much easier! Just import the WasmPy library then you are good to go!

Example:

If you have the following project setup:

|- my_wasm_file.wasm
|- main.py

Then in main.py the following code will load the WebAssembly file:

import wasmpy
import my_wasm_file

The hook also allows importing the files from submodules, eg:

|- main.py
|- my_module
|  |- my_wasm_file.wasm

Then

import wasmpy
from my_module import my_wasm_file

Functions can be called with the call function from the imported module:

import wasmpy
import wasm_math

wasm_math.call("add")(...)

This is due to WebAssembly supporting exported names that may not be valid Python names, such as add two numbers

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.1.0.tar.gz (13.8 kB view hashes)

Uploaded Source

Built Distributions

wasmpy-0.1.0-cp311-cp311-win_amd64.whl (27.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

wasmpy-0.1.0-cp310-cp310-win_amd64.whl (27.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

wasmpy-0.1.0-cp39-cp39-win_amd64.whl (27.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

wasmpy-0.1.0-cp38-cp38-win_amd64.whl (27.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

wasmpy-0.1.0-cp37-cp37m-win_amd64.whl (27.8 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

wasmpy-0.1.0-cp36-cp36m-win_amd64.whl (40.0 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

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