Skip to main content

A WebAssembly runtime powered by Wasmtime

Project description

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.9+ on Windows, macOS, and Linux, for x86_64 and arm64 architectures.

Versioning

wasmtime-py follows the Wasmtime versioning scheme, with a new major version being released every month. As with Wasmtime itself, new major versions of wasmtime-py can contain changes that break code written against the previous major version.

Since every installed Python package needs to agree on a single version of wasmtime-py, to use the upper bound on the major version in the dependency requirement should be bumped reguarly, ideally as soon as a new wasmtime-py version is released. To automate this process it is possible to use the whitequark/track-pypi-dependency-version script. YoWASP/runtime is an example of a project that automatically publishes releases on PyPI once a new version of wasmtime-py is released if it passes the testsuite.

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

Components

The wasmtime package has initial support for running WebAssembly components in Python with high-level bindings. WebAssembly components are defined by the component model and are a flagship feature under development for Wasmtime and its bindings. Components enable communication between the host and WebAssembly guests with richer types than the numerical primitives supported by core WebAssembly. For example with a component Python can pass a string to wasm and back.

Components are represented as *.wasm binaries in the same manner as core WebAssembly modules. With a component binary you can generate Python bindings with:

$ python -m wasmtime.bindgen the-component.wasm --out-dir the-bindings

An example of using this can be done with the wasm-tools repository. For example with this core wasm module at demo.wat:

(module
  (import "python" "print" (func $print (param i32 i32)))
  (memory (export "memory") 1)

  (func (export "run")
    i32.const 100   ;; base pointer of string
    i32.const 13    ;; length of string
    call $print)

  (data (i32.const 100) "Hello, world!")
)

and with this *.wit interface at demo.wit:

package my:demo;

world demo {
  import python: interface {
    print: func(s: string);
  }

  export run: func();
}

And this demo.py script

from demo import Root, RootImports, imports
from wasmtime import Store

class Host(imports.Python):
    def print(self, s: str):
        print(s)

def main():
    store = Store()
    demo = Root(store, RootImports(Host()))
    demo.run(store)

if __name__ == '__main__':
    main()
$ wasm-tools component embed demo.wit demo.wat -o demo.wasm
$ wasm-tools component new demo.wasm -o demo.component.wasm
$ python -m wasmtime.bindgen demo.component.wasm --out-dir demo
$ python demo.py
Hello, world!

The generated package demo has all of the requisite exports/imports into the component bound. The demo package is additionally annotated with types to assist with type-checking and self-documentation as much as possible.

Contributing

See CONTRIBUTING.md.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

wasmtime-38.0.0.tar.gz (147.3 kB view details)

Uploaded Source

Built Distributions

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

wasmtime-38.0.0-py3-none-win_arm64.whl (6.3 MB view details)

Uploaded Python 3Windows ARM64

wasmtime-38.0.0-py3-none-win_amd64.whl (7.2 MB view details)

Uploaded Python 3Windows x86-64

wasmtime-38.0.0-py3-none-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

wasmtime-38.0.0-py3-none-manylinux2014_aarch64.whl (7.7 MB view details)

Uploaded Python 3

wasmtime-38.0.0-py3-none-manylinux1_x86_64.whl (8.7 MB view details)

Uploaded Python 3

wasmtime-38.0.0-py3-none-macosx_11_0_arm64.whl (7.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

wasmtime-38.0.0-py3-none-macosx_10_13_x86_64.whl (8.3 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

wasmtime-38.0.0-py3-none-any.whl (7.2 MB view details)

Uploaded Python 3

wasmtime-38.0.0-py3-none-android_26_x86_64.whl (8.6 MB view details)

Uploaded Android API level 26+ x86-64Python 3

wasmtime-38.0.0-py3-none-android_26_arm64_v8a.whl (7.8 MB view details)

Uploaded Android API level 26+ ARM64 v8aPython 3

File details

Details for the file wasmtime-38.0.0.tar.gz.

File metadata

  • Download URL: wasmtime-38.0.0.tar.gz
  • Upload date:
  • Size: 147.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wasmtime-38.0.0.tar.gz
Algorithm Hash digest
SHA256 75d38a075571756543266df782979fc2204cafd1fb7f3ebbb901e05df916dd34
MD5 54c16abbafe3def08f6b013c2f85a966
BLAKE2b-256 78793d055ce7a0a237941d1910f32a1b6692dee4021d0cb709a97d2feb3f1ef3

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: wasmtime-38.0.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wasmtime-38.0.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 79fd37228ded91e84ee6748894ef4686bd6232e635e150e6a70beabd99c67868
MD5 95f957426a18f3b473d6108e66bbae2e
BLAKE2b-256 a185fbba5850c65ab91312a68871dec4e36abbb7ad717f3df6c790bff330b054

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: wasmtime-38.0.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wasmtime-38.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c0f7ac800575e592e74ce7d111e04ad7b3dbbff421bfac00c94432300ee39bfe
MD5 f91d243c86f00a696da5b91d444c05d1
BLAKE2b-256 66996da689c6534b16b2e6959321533f0000228854e5f4211eb00bfa7b6bcebc

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3864469deb899eda7f32193d8cc8922d6b320cc016d08e601236dbfd77b096fe
MD5 cf3edaf45e11db68f7b962fba8ec6e25
BLAKE2b-256 9abfb2b024d203dd676811729ad8de232608b2e727a89cd5ad16fbdeeac98dd7

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d5455bd83e82b04db32c226524b1c084a71d5d9d4ada3c5d0cf5cccaf2563253
MD5 9318be308d9979b1815fafe005642267
BLAKE2b-256 fc7b8e6f9670ea1476735517b28b99b2595e9000d46ee0a276d0e0b547cc928c

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f6c87bfe9de9a35de5b28fbdac192e2526486e3d0a3be48e107789cf117925fd
MD5 5a572c7bdab63775768f00f9ce77d5bb
BLAKE2b-256 54de7b8898c9e7f73a2f4c20b621279143cfc27836dba0db676e9a923cd0a461

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 479529425f68cd69f8f4c369abf50d6f44a0e2395f5ce2b9a506c8a695aef65b
MD5 e4bb551de176a25b53500ac9cb67572c
BLAKE2b-256 548383d598af08eb297f1a644e678ce2d6c335f015c9f3c8c2532e289801293b

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 1c46037114350f25b23eb928085b29dc8acfe4de7ba6a59584b51bfc8533e14c
MD5 486ca12533a12787ed4cc3fb48adfddf
BLAKE2b-256 9ebec470e5be91cccf7fbc4db4ce42eafb8f0f34b45aeb92c5bfbf963d100e0b

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-any.whl.

File metadata

  • Download URL: wasmtime-38.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wasmtime-38.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df99e75296a504d37053bc0cae3a73cc5ec5c1942d8f086a4195afaa26274457
MD5 fe8aebd79b2b9cf9f5380c3580d81bb1
BLAKE2b-256 5c561ba8709083dbdbd0f734921704513d45fcd855e4406ae0f4a7d06c78c7e5

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-android_26_x86_64.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-android_26_x86_64.whl
Algorithm Hash digest
SHA256 c3dac04170a3fa4257ba0b0a04f360c09ddae4e67c1ceca144d757a372004e2c
MD5 b5a39bc845efb9d864280920953588c3
BLAKE2b-256 cffa52965b32fa204dde06585641ba367313db46149c3ee15f05e21babcb2d96

See more details on using hashes here.

File details

Details for the file wasmtime-38.0.0-py3-none-android_26_arm64_v8a.whl.

File metadata

File hashes

Hashes for wasmtime-38.0.0-py3-none-android_26_arm64_v8a.whl
Algorithm Hash digest
SHA256 71acc1f48ba6addbd4aee72bb249025709b31bb6a655cbecf2972f3412a8c3b0
MD5 57c724aeb0744db76858606c2d6a6328
BLAKE2b-256 417a2714d2f9424b952d71ca88ac264352f0c3d3282cf62d93a3ce337b50624e

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