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.2-cp36-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea81651624b881d157279c7740943cda007cc8644901940944d6ba2fa8ed645d |
|
MD5 | ed73505017d8a24ffaf7c807d4fdfe84 |
|
BLAKE2b-256 | 4a38c75c801515aeb74d860f6fafb5c73d0349aab8716051cff2dcda75d648e8 |
Hashes for wasmpy-0.1.2-cp36-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6f247450eccb97f3a50c56e81f6784fbbd4906db430adbd4b269623b383788c |
|
MD5 | ed23a35958ce5f0427e0cfa8d3e6431f |
|
BLAKE2b-256 | 6d4a80c46cbd10efa92b7b98c4346fd731cbc42a0edba368b39a8a4a5ac2618d |