Skip to main content

wabt.py

wabt.py is a Python wrapper for the WebAssembly Binary Toolkit (WABT). It allows you to interact with WABT tools programmatically, making it easy to work with WebAssembly binaries and text formats in Python.

Features

  • Run WABT tools programmatically: Includes support for tools like wat2wasm, wasm2wat, wasm-validate, wasm-decompile, and more.
  • Cross-platform support: Works on Windows, macOS, and Linux.
  • Automatic updates: Automatically downloads and updates the latest WABT binaries.
  • Simple API: Provides a Pythonic interface for interacting with WABT tools.

Installation

You can install wabt via pip:

pip install wabt

Usage

Initialize WABT

To use the library, first initialize the Wabt class. This will ensure the latest WABT binaries are downloaded and ready to use.

from wabt import Wabt

Initialize WABT

wabt = Wabt()

Convert WAT to WASM

Convert a WebAssembly text file (.wat) to a binary file (.wasm).

wabt.wat_to_wasm("example.wat", output="example.wasm")

Convert WASM to WAT

Convert a WebAssembly binary file (.wasm) to a text file (.wat).

wabt.wasm_to_wat("example.wasm", output="example.wat")

Validate a WASM File

Validate a WebAssembly binary file.

output = wabt.wasm_validate("example.wasm")
print(output)

Decompile a WASM File

Decompile a WebAssembly binary file into a human-readable format.

wabt.wasm_decompile("example.wasm", output="example.dcmp")

Run Spectest Interpreter

Run a Spectest JSON file in the interpreter.

wabt.spectest_interp("test.json")

List of Supported Tools

The following WABT tools are supported:

  • wat2wasm: Convert WAT (WebAssembly Text) to WASM (WebAssembly Binary).
  • wasm2wat: Convert WASM to WAT.
  • wasm-validate: Validate a WebAssembly binary file.
  • wasm-decompile: Decompile a WebAssembly binary file.
  • wasm-interp: Run a WebAssembly binary in a stack-based interpreter.
  • wasm-objdump: Print information about the contents of WebAssembly binaries.
  • wasm-stats: Output statistics about a WebAssembly binary.
  • wasm-strip: Remove sections from a WebAssembly binary file.
  • wast2json: Convert a WAST (WebAssembly Spec Test) file to JSON.
  • wat-desugar: Format a WAT file.
  • wasm2c: Convert a WebAssembly binary to C code.

Advanced Usag

Custom Options

Most methods accept additional options to customize the behavior of the WABT tools. For example, you can validate a WASM file with verbose output by passing the --verbose option.

wabt.wasm_validate("example.wasm", options=["--verbose"])

Skip Updates

If you want to skip the automatic update process (e.g., for offline use), you can initialize the Wabt class with the skip_update parameter set to True.

wabt = Wabt(skip_update=True)

Requirements

  • Python 3.6 or higher
  • Internet connection (for downloading WABT binaries)

Acknowledgments

This library is built on top of the WebAssembly Binary Toolkit (WABT).

Release files for wabt 0.1.2

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

Source distribution (sdist)

Source distribution for wabt 0.1.2
File Size Uploaded
wabt-0.1.2.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wabt 0.1.2
File Interpreter ABI Platform
wabt-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / wabt-0.1.2.tar.gz

Download URL wabt-0.1.2.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b448bdd2cab44f8f19f138ab24d6c54e6f5b9f8d5fb71b26dce0f4a3bb7aa712
BLAKE2b-256 checksum
How to use checksums
0900fe06b8ca6e4d6f7369a934ebda3930328044bf08f0fee8f4b20821c1be4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / wabt-0.1.2-py3-none-any.whl

Download URL wabt-0.1.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23b980b3e0d9c3580d5defe2e17b2db82ca9ec1f25c2e8b79e438aa9f8e53d2f
BLAKE2b-256 checksum
How to use checksums
ad80a2925f1136c8f6a7a45d4dc20843908c38ce8698eefa6d6a08c17028eeff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

2 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