Wasmer Python API
A complete and mature WebAssembly runtime for Python based on Wasmer.
- Easy to use: The
wasmerAPI mimics the standard WebAssembly API,
wasmerexecutes the WebAssembly modules as fast as possible, close to native speed,
- Safe: All calls to WebAssembly will be fast, but more importantly, completely safe and sandboxed.
The very basic example is the following:
from wasmer import Store, Module, Instance # Create a store, which holds the engine, the compiler etc. store = Store() # Let's assume we don't have WebAssembly bytes at hand. We will # write WebAssembly manually. module = Module( store, """ (module (type (func (param i32 i32) (result i32))) (func (type 0) local.get 0 local.get 1 i32.add) (export "sum" (func 0))) """ ) # Instantiates the module. instance = Instance(module) # Now, let's execute the `sum` function. assert instance.exports.sum(1, 2) == 3
That's it. Now explore the API! Some pointers for the adventurers:
- The basic elements are
- Exports of an instance are represented by the
- Maybe your module needs to import
Table? Well, there is the Python
- It is possible to read and write
Memorydata with the Python buffer protocol with
from .wasmer import * __doc__ = wasmer.__doc__