WebAssembly in Python.
Project description
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.
Usage with Python modules
|- my_module
|- __init__.py
|- wasm_math.wat
# __init__.py
import wasmpy
from .wasm_math import add
;; 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
>>>
Invalid function names
Functions exported from WebAssembly can also be accessed from the module by using their name as a key.
For exported names that aren't valid Python identifiers or which start with a _
, this is the only valid way of accessing these functions.
;; wasm_math.wat
(module
(func (export "add one") (param i32) (result i32)
(i32.add (local.get 0) (i32.const 1))
)
)
>>> import wasmpy
>>> import wasm_math
>>> wasm_math["add one"](11)
12
>>>
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:
- most memory instructions
- most control instructions
- imports
- tables
Goals
-
Current target:
- Reach compatability with the MVP
-
Future Goals
- Native support for more architectures, particularly those supported by manylinux
- Interfacing with the Python C API from WebAssembly (in conjunction with the Wasmpy sister project wasmpy-build) to allow compiled extension modules that are platform independent
- Compatibility with Pyodide
- Python implementation support for Jython, PyPy etc.
- Support for WebAssembly proposals
- Support for WASI snapshots, as well as support for supersets such as WASIX
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.2.2-cp36-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c08dda45751215edfd7eef6775178946b48d0b33d78fb07fa279aeb5a24d9226 |
|
MD5 | a32242aadab9d5a728eef40e0f7babfa |
|
BLAKE2b-256 | c3b59c3dbaa7e222a0b034f9cd853c750df54233138a86ee2838f8c52b675387 |
Hashes for wasmpy-0.2.2-cp36-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2da149ef715d7f8dbdaa1cb87f31f1f3d1ceb05ea588cafe128191f776048a54 |
|
MD5 | 4590578582563224250215f4eb5492b7 |
|
BLAKE2b-256 | 4710aab72c16aaeae50c75ea04acf0715b47db9d78454d844ece7a35055e302a |
Hashes for wasmpy-0.2.2-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef8ad4c02214586ee8a6381ce1819310e523857a3cd25f789a09454d9b34fcde |
|
MD5 | e5f767ba05459b248c43f2a398d391a6 |
|
BLAKE2b-256 | e6e5bf5c1270cff0483ffefbfcc5444f95d721d3d31ecabe816fc1a4702e3372 |
Hashes for wasmpy-0.2.2-cp36-abi3-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d20bd52ea7aed7dc5416ace9604486bc72c5dbeff3ab94baa06ad7e2600be5d |
|
MD5 | b02e2462aa4b83a5bf99fe821e028cad |
|
BLAKE2b-256 | b2b31c2abe2948a6807725d7b0ee7e043324bd264e2a3422bfef4bed3d779532 |
Hashes for wasmpy-0.2.2-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e557f0f73d7ce04bd2059b16ce3f29e9a3d532c0d01c23f7eff383767706e2 |
|
MD5 | 5e062ecc0a711633f9e830435f4fd333 |
|
BLAKE2b-256 | 44ff5b364a25338f613a0d6f2f6e34ed6439d9ae41b09c227f141728b80e3a7d |
Hashes for wasmpy-0.2.2-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85b0d2cf9aa0636503b2d08f9f30bd042ca11867166dd3098001e0362e547cf6 |
|
MD5 | 52e39b6b6d3472a97242e8bfaabd6996 |
|
BLAKE2b-256 | e8d042aea3ffd1a8f1d9a78bff5741c02994af2b95e5aa7e3846b3a7e2a23e85 |