Skip to main content

Python extension to run WebAssembly binaries

Project description

Wasmer logo Wasmer Python, the Singlepass compiler PyPI version Wasmer Python Documentation Wasmer PyPI downloads Wasmer Slack Channel

wasmer is a complete and mature WebAssembly runtime for Python. wasmer_compiler_singlepass provides the Singlepass compiler to wasmer, so that wasmer is able to compile WebAssembly module.

Other compilers exist:

  • wasmer_compiler_cranelift,
  • wasmer_compiler_llvm.

To get a more complete view, please see the documentation of the wasmer package itself.

Install

This package must be used with the wasmer package, thus:

$ pip install wasmer
$ pip install wasmer_compiler_singlepass

Usage

Any engines in wasmer.engine can take the wasmer_compiler_singlepass.Compiler class as argument:

from wasmer import engine, Store, Module, Instance
from wasmer_compiler_singlepass import Compiler

# Let's use the Singlepass compiler with the JIT engine…
store = Store(engine.JIT(Compiler))

# … or with the native engine!
store = Store(engine.Native(Compiler))

# And now, compile the module.
module = Module(store, open('my_program.wasm', 'rb').read())

# Now it's compiled, let's instantiate it.
instance = Instance(module)

# And get fun, for example by calling the `sum` exported function!
print(instance.exports.sum(1, 2))

Documentation

Browse the documentation at https://wasmerio.github.io/wasmer-python/api/wasmer_compiler_singlepass/.

Alternatively, run just build compiler-singlepass followed by just doc to generate the documentation inside docs/api/wasmer_compiler_singlepass.html.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Built Distributions

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page