Skip to main content

python bindings for the binaryen webassembly library

Project description

Latest Version

Python interface to the Binaryen library

This module provides a Python interface to the binaryen webassembly library.

That library has to be installed separately, make sure it is available on your system as a shared library. You may need to add something to your link library search path to let python pick it up.

Requires Python 3.6 or newer. Also works on pypy3 (because it uses cffi). The minor version number of this library tracks the binaryen release number (such as 112)

Software license: MIT


This Python package expects binaryen to be installed in /usr/include/ and /usr/lib/. On some Linux distributions community packages are available which install Binaryen in the correct place, have a search first to see if that's available for your distribution.

For distributions that don't have this, you build from source or download a release from and install it manually.

Manual Installation

Manual installation can be done by extracting the archive, and copying (or symlinking) the files in it to the appropriate location in /usr/.

As an example here is what this might look like in GitHub Actions CI (for Ubuntu 22.04):

    - name: Install Binaryen
      run: |
        tar -xf binaryen-version_109-x86_64-linux.tar.gz
        sudo ln -s $PWD/binaryen-version_109/include/binaryen-c.h /usr/include/binaryen-c.h
        sudo ln -s $PWD/binaryen-version_109/include/wasm-delegations.def /usr/include/wasm-delegations.def
        sudo ln -s $PWD/binaryen-version_109/lib/libbinaryen.a /usr/lib/libbinaryen.a


Running the following code:

import binaryen

module = binaryen.ModuleCreate()
params = binaryen.TypeCreate([binaryen.TypeInt32(), binaryen.TypeInt32()], 2)
results = binaryen.TypeInt32()
x = binaryen.LocalGet(module, 0, binaryen.TypeInt32())
y = binaryen.LocalGet(module, 1, binaryen.TypeInt32())
add = binaryen.Binary(module, binaryen.AddInt32(), x, y)
adder = binaryen.AddFunction(module, b"adder", params, results, binaryen.ffi.NULL, 0, add)

results in the following Webasm Text output:

 (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
 (func $adder (; 0 ;) (param $0 i32) (param $1 i32) (result i32)
   (local.get $0)
   (local.get $1)

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

pybinaryen-1.112.tar.gz (17.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page