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 (the assemble
step requires having NASM on path):
$ git clone https://github.com/olivi-r/wasmpy.git
$ cd wasmpy
$ python setup.py assemble
$ 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for wasmpy-0.1.1-cp36-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a2a80f5350be1f316a0175d551865d4ae53127b69713a4e8b9e7234892129e4 |
|
MD5 | 4c248cbb0a9c26261752c8a474bb1713 |
|
BLAKE2b-256 | b13ff08dcec360e9fe55e28ca911e76d7f8dbee848978b0594c37d76d18a9b55 |
Hashes for wasmpy-0.1.1-cp36-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b3e030e69155603e2817edc10beb16a53dab30401ac17b8bebe6a658e062b20 |
|
MD5 | d542a7b89ce20d630201fc55adcdab69 |
|
BLAKE2b-256 | 4160e90a5a832381ac0a236d1d24edfa0b3e1932e6c241643b8cbddbb1f3ada6 |