All Projects → bytecodealliance → wasmtime-py

bytecodealliance / wasmtime-py

Licence: Apache-2.0 license
Python WebAssembly runtime powered by Wasmtime

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to wasmtime-py

wasi-experimental-http
Experimental outbound HTTP support for WebAssembly and WASI
Stars: ✭ 107 (-43.98%)
Mutual labels:  wasmtime
wasmtime-dotnet
.NET embedding of Wasmtime https://bytecodealliance.github.io/wasmtime-dotnet/
Stars: ✭ 270 (+41.36%)
Mutual labels:  wasmtime
dotnet-opa-wasm
Call Open Policy Agent (OPA) policies in WASM (Web Assembly) from .NET Core
Stars: ✭ 36 (-81.15%)
Mutual labels:  wasmtime
Lunatic
Lunatic is an Erlang-inspired runtime for WebAssembly
Stars: ✭ 2,074 (+985.86%)
Mutual labels:  wasmtime
Wasmtime
Standalone JIT-style runtime for WebAssembly, using Cranelift
Stars: ✭ 6,413 (+3257.59%)
Mutual labels:  wasmtime

wasmtime-py

Python embedding of Wasmtime

A Bytecode Alliance project

CI status Latest Version Latest Version Documentation Code Coverage

Installation

To install wasmtime-py, run this command in your terminal:

$ pip install wasmtime

The package currently supports 64-bit builds of Python 3.6+ on x86_64 Windows, macOS, and Linux

Usage

In this example, we compile and instantiate a WebAssembly module and use it from Python:

from wasmtime import Store, Module, Instance, Func, FuncType

store = Store()
module = Module(store.engine, """
  (module
    (func $hello (import "" "hello"))
    (func (export "run") (call $hello))
  )
""")

def say_hello():
    print("Hello from Python!")
hello = Func(store, FuncType([], []), say_hello)

instance = Instance(store, module, [hello])
run = instance.exports(store)["run"]
run(store)

Be sure to check out the examples directory, which has other usage patterns as well as the full API documentation of the wasmtime-py package.

If your WebAssembly module works this way, then you can also import the WebAssembly module directly into Python without explicitly compiling and instantiating it yourself:

# Import the custom loader for `*.wasm` files
import wasmtime.loader

# Assuming `your_wasm_file.wasm` is in the python load path...
import your_wasm_file

# Now you're compiled and instantiated and ready to go!
print(your_wasm_file.run())

Contributing

See CONTRIBUTING.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].