A Python wrapper for Binaryen
Project description
Binaryen.py
Binaryen.py is a python wrapper for Binaryen. Use this to create, optimise and interpret WebAssembly binaries in python.
Installation
Install through PyPI.
pip install binaryen.py
Windows, Mac (Intel & ARM) and Linux (manylinux, musllinux) are supported.
Build from source
- (If upgrading binaryen version) Update
BINARYEN_VERSION
inpyproject.toml
and.github/workflows/build.yaml
- Run
bash scripts/build_libbinaryen.sh
- Run
python -m pip install -e .
,cibuildwheel
,python -m pip wheel .
, or whichever supported build command you would prefer
How To Use
import binaryen
from binaryen.type import Int32, TypeNone
# Equivalent python function
def add(x, y):
return x + y
mod = binaryen.Module()
mod.add_function(
b"add",
binaryen.type.create([Int32, Int32]),
Int32,
[Int32],
mod.block(
None,
[
mod.local_set(
2,
mod.binary(
binaryen.operations.AddInt32(),
mod.local_get(0, Int32),
mod.local_get(1, Int32),
),
),
mod.Return(mod.local_get(2, Int32)),
],
TypeNone,
),
)
if not mod.validate():
raise RuntimeError("Invalid module!")
mod.add_function_export(b"add", b"add")
mod.optimize()
mod.print()
Results in the following Wasm
(module
(type $0 (func (param i32 i32) (result i32)))
(export "add" (func $add))
(func $add (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32)
(i32.add
(local.get $0)
(local.get $1)
)
)
)
Reference the Binaryen header file to understand how to use Binaryen. This package makes no significant changes to how Binaryen is used. The majority of the work this module does is interoperating between C and Python and creating more pythonic classes for Modules, Expressions and Functions.
For more examples see examples.
Missing Functions
You can still call any missing functions that haven't been implemented by the wrapper yet by calling them directly. To do this use binaryen.lib.BinaryenFullFunctionName()
and call the full function name as described in the Binaryen header file.
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
Built Distributions
File details
Details for the file binaryen_py-117.1.1.tar.gz
.
File metadata
- Download URL: binaryen_py-117.1.1.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c305180035fceced30d6ca15917e39c10792431afd5cda355b21de8c36f36c |
|
MD5 | 0f51a7ba887551f934c876ede666ed9e |
|
BLAKE2b-256 | ed796a5912686cbe74e81370b3cd0a340895434170814633a88ad68f1b85893c |
File details
Details for the file binaryen.py-117.1.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: binaryen.py-117.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db69999eed55665a71be46e7419955615d26db4b39061943fb0cf475352ee432 |
|
MD5 | 5ec7dcf7900b3aa7a7811a769a3f8803 |
|
BLAKE2b-256 | ba9880abd754a7fe1ec121763546638176024bc5a656f47c202385321d3ef275 |
File details
Details for the file binaryen.py-117.1.1-cp312-cp312-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: binaryen.py-117.1.1-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 8.6 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb88d3ae8da8ce24cba5be6083c2859dbfbcc47838e0112e7c281e63a9cdf1b7 |
|
MD5 | eff9d8158476841d8160eeccb58293c1 |
|
BLAKE2b-256 | ca9346b8f6ccd69514e6722d9633cc384f025916001d3ff7294ca6058aae0160 |
File details
Details for the file binaryen.py-117.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: binaryen.py-117.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 8.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989e89299adb69ea4d80598123a346c01f54885574abb5c18630edb5e7e34bbc |
|
MD5 | 21a2c1c5f2cfda6360ff7029ae369eec |
|
BLAKE2b-256 | a309dee7d638a29fc396a55cfe6793af5e7f76ae7bfd25e5aa883b52d7b86795 |
File details
Details for the file binaryen.py-117.1.1-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: binaryen.py-117.1.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda23c71c461cb5bc299be42d0a2de952eb2a401d8606f6a4ff437d66023f227 |
|
MD5 | cb19995cc0597fdb9f00f9c0641b43d1 |
|
BLAKE2b-256 | 7321a28f72c80dc064564af3ca77df782a1d31b511c91ca6d38de29b5444dded |
File details
Details for the file binaryen.py-117.1.1-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: binaryen.py-117.1.1-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 6.2 MB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138ec3284c41a57cbf59d3f51016602f1f370a1e25a6b14432b2eaaa5738531f |
|
MD5 | 09d8f4b2cd73f0538bd719eab45f64e2 |
|
BLAKE2b-256 | ec563594f94e829f195b7b478f94d8d1f258634d8aec36f85cc80a91efcdab8b |