Skip to main content

icpp-binaryen

cffi bindings over Binaryen's C API, with the official Binaryen shared library bundled per platform.

Built and maintained by icppWorld for the icpp-pro toolchain of the Internet Computer, and usable by any project that needs Binaryen from Python.

Why

The Internet Computer rejects a wasm module with more than 1000 defined globals (install error IC0505). A wasi-sdk build of a large C++ project blows past this. The fix: remove every export of kind global (an exported global is otherwise kept alive), then run Binaryen's optimizer, which drops the now-dead globals. fix_globals_limit does exactly that.

Install

pip install icpp-binaryen

One wheel per platform (macOS x86_64 / arm64, Linux x86_64) covers every Python version >= 3.11: the bindings use cffi in ABI mode, so there is no compiled extension module. On Windows, use WSL.

Public API — all of it

from icpp_binaryen import fix_globals_limit  # the one high-level entry point
from icpp_binaryen import Module             # load / optimize / emit / write
from icpp_binaryen import ffi, lib           # raw escape hatch
from icpp_binaryen import BINARYEN_VERSION   # int, from the bundled version.txt

fix_globals_limit

from pathlib import Path
from icpp_binaryen import fix_globals_limit

report = fix_globals_limit(Path("build/my_canister.wasm"))
print(report.summary())

Rewrites the wasm in place and keeps a byte-identical backup copy (default <stem>_before_opt.wasm). Returns a GlobalsFixReport with the before/after counts of exports and defined globals.

Documented side effect: the optimize pass strips the wasm name section. The _before_opt backup is what keeps named backtraces possible (e.g. under wasmtime). This is by design — do not delete the backup pair.

Module

from icpp_binaryen import Module

with Module.load("my.wasm") as module:      # or Module.read(wasm_bytes)
    print(module.num_exports, module.num_globals)
    for name in module.global_export_names():
        module.remove_export(name)
    module.optimize(shrink_level=0, optimize_level=0)
    assert module.validate()
    module.write("my_fixed.wasm")           # or wasm_bytes = module.emit()

ffi / lib

The raw ABI-mode cffi handles, for post-processing needs beyond the wrapper. The cdef is a hand-curated subset of binaryen-c.h — see src/icpp_binaryen/_cdef.py for what is available. module.ref hands you the raw BinaryenModuleRef for use with lib directly.

Versioning

<binaryen>.<minor>.<patch> — the major component IS the bundled Binaryen version, asserted at import time. The wasm bytes this package emits are part of its contract: minor/patch releases are byte-identical in fix_globals_limit output; a Binaryen bump is a major release.

Contributing

See README-feature-guide.md (the ceremony-based development process) and README-release-guide.md. Development setup:

conda create --name icpp-binaryen python=3.11
conda activate icpp-binaryen
make install-python
make get-binaryen        # fetch the official Binaryen lib for this platform
make all-tests

Credits & license

Apache-2.0, like Binaryen itself. The cffi-over-libbinaryen approach was inspired by jonathanharg/binaryen.py, which this package replaces for the icpp-pro toolchain.

Metadata

Release files for icpp-binaryen 116.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for icpp-binaryen 116.0.1
File Interpreter ABI Platform
icpp_binaryen-116.0.1-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details
icpp_binaryen-116.0.1-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
icpp_binaryen-116.0.1-py3-none-macosx_10_14_x86_64.whl Python 3 none macOS 10.14+ x86-64 Details

Total release size: 15.4 MB

Release files / icpp_binaryen-116.0.1-py3-none-manylinux_2_35_x86_64.whl

Download URL icpp_binaryen-116.0.1-py3-none-manylinux_2_35_x86_64.whl
Size 6.3 MB
Tags Linux glibc 2.35+ x86-64 Python 3
SHA-256 checksum
How to use checksums
35fe9e8dd512977cd3dbaebf352eda4d6f686d0292d7d73942b5ffd3a1b06b20
BLAKE2b-256 checksum
How to use checksums
cef5eca03b1ae57915f8fe294d28fafc3ee848ec033f7596bacf2edae9f4b037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / icpp_binaryen-116.0.1-py3-none-macosx_11_0_arm64.whl

Download URL icpp_binaryen-116.0.1-py3-none-macosx_11_0_arm64.whl
Size 4.1 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6dd95c15b9671ed923260db22869a646ace69851d390ee6931bb16e28235f1cd
BLAKE2b-256 checksum
How to use checksums
a04cf442ca99d04a46411d605e4506c3347128231c2c0f9b4ff371fd6f3af9dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / icpp_binaryen-116.0.1-py3-none-macosx_10_14_x86_64.whl

Download URL icpp_binaryen-116.0.1-py3-none-macosx_10_14_x86_64.whl
Size 5.0 MB
Tags Python 3 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
4aa6a7cc90bebd4b9b6178155f5ad96de62623dc07de59387a36a4ddb29693dd
BLAKE2b-256 checksum
How to use checksums
881360e8a7f8e8e1ca4439c2588270c5a42a6f001f320ca8347dd8628f62c9a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

116.0.1 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page