Skip to main content

A Python wrapper for the WebAssembly Binary Toolkit (WABT)

Project description

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).

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

wabt-0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wabt-0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file wabt-0.1.tar.gz.

File metadata

  • Download URL: wabt-0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for wabt-0.1.tar.gz
Algorithm Hash digest
SHA256 b2bb86dd524df3951bbf1144d4ff15ecae1e2f4badce37ab31d115a3070b6022
MD5 0a9512542306f877d34eb6af76922a79
BLAKE2b-256 3ff30c37fe000deb983042c0c897ae54f5b85ca2fc172982bab658b772c4d014

See more details on using hashes here.

File details

Details for the file wabt-0.1-py3-none-any.whl.

File metadata

  • Download URL: wabt-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for wabt-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 efe84e07dfa9bf5b1a1396e6e98728a8420958305e9f5389693e22d9515342e2
MD5 cd6a1b27bfcd5c64dfeb8ca350b0f41b
BLAKE2b-256 e4a878fc7f2bdeda5391a169c62697538e2a8a196a99f5b0456d8e3219b21bea

See more details on using hashes here.

Supported by

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