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_VERSIONinpyproject.tomland.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.
Metadata
Release files for binaryen.py 117.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| binaryen_py-117.1.1.tar.gz | 25.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| binaryen.py-117.1.1-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| binaryen.py-117.1.1-cp312-cp312-musllinux_1_1_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux musl 1.1+ x86-64 | Details |
| binaryen.py-117.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ x86-64 | Details |
| binaryen.py-117.1.1-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| binaryen.py-117.1.1-cp312-cp312-macosx_10_9_x86_64.whl | CPython 3.12 | CPython 3.12 | macOS 10.9+ x86-64 | Details |
Total release size: 31.2 MB
Release files / binaryen_py-117.1.1.tar.gz
| Download URL | binaryen_py-117.1.1.tar.gz |
|---|---|
| Size | 25.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27c305180035fceced30d6ca15917e39c10792431afd5cda355b21de8c36f36c
|
|
BLAKE2b-256 checksum How to use checksums |
ed796a5912686cbe74e81370b3cd0a340895434170814633a88ad68f1b85893c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / binaryen.py-117.1.1-cp312-cp312-win_amd64.whl
| Download URL | binaryen.py-117.1.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
db69999eed55665a71be46e7419955615d26db4b39061943fb0cf475352ee432
|
|
BLAKE2b-256 checksum How to use checksums |
ba9880abd754a7fe1ec121763546638176024bc5a656f47c202385321d3ef275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / binaryen.py-117.1.1-cp312-cp312-musllinux_1_1_x86_64.whl
| Download URL | binaryen.py-117.1.1-cp312-cp312-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 8.6 MB |
| Tags | CPython 3.12 Linux musl 1.1+ x86-64 |
|
SHA-256 checksum How to use checksums |
fb88d3ae8da8ce24cba5be6083c2859dbfbcc47838e0112e7c281e63a9cdf1b7
|
|
BLAKE2b-256 checksum How to use checksums |
ca9346b8f6ccd69514e6722d9633cc384f025916001d3ff7294ca6058aae0160
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / binaryen.py-117.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | binaryen.py-117.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 8.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
989e89299adb69ea4d80598123a346c01f54885574abb5c18630edb5e7e34bbc
|
|
BLAKE2b-256 checksum How to use checksums |
a309dee7d638a29fc396a55cfe6793af5e7f76ae7bfd25e5aa883b52d7b86795
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / binaryen.py-117.1.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | binaryen.py-117.1.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
cda23c71c461cb5bc299be42d0a2de952eb2a401d8606f6a4ff437d66023f227
|
|
BLAKE2b-256 checksum How to use checksums |
7321a28f72c80dc064564af3ca77df782a1d31b511c91ca6d38de29b5444dded
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|
Release files / binaryen.py-117.1.1-cp312-cp312-macosx_10_9_x86_64.whl
| Download URL | binaryen.py-117.1.1-cp312-cp312-macosx_10_9_x86_64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.12 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
138ec3284c41a57cbf59d3f51016602f1f370a1e25a6b14432b2eaaa5738531f
|
|
BLAKE2b-256 checksum How to use checksums |
ec563594f94e829f195b7b478f94d8d1f258634d8aec36f85cc80a91efcdab8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.1
|