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
File details
Details for the file wasmpy-0.2.3.tar.gz
.
File metadata
- Download URL: wasmpy-0.2.3.tar.gz
- Upload date:
- Size: 52.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f65c625fc4a88fab978ac6f6915bd6495c3c86cb95c3f32c615ee3189ce7f1a |
|
MD5 | e4e73e31d63ffdd35669c643a48fd338 |
|
BLAKE2b-256 | 24eb563e5b04176ce2d778976d6f660153bdae348a501bfa0dd1d24078a76d3e |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-win_amd64.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-win_amd64.whl
- Upload date:
- Size: 55.4 kB
- Tags: CPython 3.6+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 993c540f45405f40e1d3dfe18b991596bb1e9b44d88817980c0b5f476bce66a7 |
|
MD5 | c71fc90b8a8a7e2a8ec8cc9f9c1c8e8f |
|
BLAKE2b-256 | 50b97af764e3a745bfacd85da3890bb830ebc381507fb96980c0945b0eb0d4bc |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-win32.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-win32.whl
- Upload date:
- Size: 50.0 kB
- Tags: CPython 3.6+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e3a2016c13b768fe75a09acc26647ebac07b6cdcbc68b32166d0a61c47eee4 |
|
MD5 | 173eb94707ac48e47a5b7d674ac79421 |
|
BLAKE2b-256 | aa2693df4307a9fe135f91db35caecc7dde6f318808f4a39e1064a22c65aca34 |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.6+, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c05a6f5c2439efc3679f7d105cf4ee36307604fbadfae1a244156eeca9f33ad9 |
|
MD5 | 728d53b787429981abc28a4ffa773fa5 |
|
BLAKE2b-256 | a11efc3ab6422e8d189263c0949737b64c92d7106abd84e0b13ad7f6d6ca97aa |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-musllinux_1_1_i686.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-musllinux_1_1_i686.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.6+, musllinux: musl 1.1+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddf1c9e1b01ea657e7363879e9525a9619057b91407e94fded29ab28e6c7ce9b |
|
MD5 | b841196077e48ca4558ca38ff96bef2a |
|
BLAKE2b-256 | cd59fe75e2da146f59822da1f58a0b8a3abfdbfba86eeadd06b09a85720b5a6d |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 556.1 kB
- Tags: CPython 3.6+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5525fe0c5f2b7a54549b6c125790025ad8255aa09b4d3d1c6724f39b28115bd7 |
|
MD5 | 4a8b22df3d7452180762404f36cccf77 |
|
BLAKE2b-256 | 21332c2a40a25e1e969cdbecc7ae9bdefefbcd4eaadc746ad461298502d72bac |
File details
Details for the file wasmpy-0.2.3-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: wasmpy-0.2.3-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 460.4 kB
- Tags: CPython 3.6+, manylinux: glibc 2.12+ i686, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1cecc37f2b31c356bf17c20a48e1fe0f1b48ade089f8c5372353c8fb6dbd3b1 |
|
MD5 | e5ac6923da62f016c77d6625d983bdf1 |
|
BLAKE2b-256 | 3fe0df6b460f661c84da2b5993a7d40985024bab6efafc7689c078dc13c5e54f |