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.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, """
  (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["run"]
run()

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

So far this extension has been written by folks who are primarily Rust programmers, so it's highly likely that there's some faux pas in terms of Python idioms. Feel free to create a PR to help make things more idiomatic if you see something!

To work on this extension locally you'll first want to clone the project:

$ git clone https://github.com/bytecodealliance/wasmtime-py
$ cd wasmtime-py

Next up you'll acquire a Wasmtime installation. The wasmtime-py package expects your platform's shared library to exist at wasmtime/wasmtime.pyd. You can download the latest development version of Wasmtime by running a script in the top-level directory of the package's source (this is what CI does):

$ python download-wasmtime.py

Otherwise if you have a local checkout of Wasmtime you can symlink its libwasmtime.so (or equivalent) to wasmtime/wasmtime.pyd.

After you've got Wasmtime set up you can check it works by running all the unit tests:

$ pip install pytest
$ pytest

After that you should be good to go!

CI and Releases

The CI for this project does a few different things:

  • API docs are generated for pushes to the main branch and are published online.
  • Test coverage information is generated for pushes to the main branch and are available online.
  • Each push to main will publish a release to test.pypi.org for local inspection.
  • Tagged commits will automatically be published to pypi.org.

All commits/PRs run the full test suite, and check for code style and other errors using flake8.

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

wasmtime-0.18.1-py3-none-win_amd64.whl (2.8 MB view details)

Uploaded Python 3Windows x86-64

wasmtime-0.18.1-py3-none-manylinux1_x86_64.whl (4.3 MB view details)

Uploaded Python 3

wasmtime-0.18.1-py3-none-macosx_10_13_x86_64.whl (3.2 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: wasmtime-0.18.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for wasmtime-0.18.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c09a685a4e0c200c508f3b4111071d6085a79c6855a249c1b850601554bc8786
MD5 d554a518199cca6f803fb005570653e7
BLAKE2b-256 7efad2e9fb3ef0ae0dbf53824bce8423c815963c56508839e0cace49251da6c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wasmtime-0.18.1-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 4.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for wasmtime-0.18.1-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b3d331f0dcf49978c5a0c105423f3bf52af7e7c15ace1474adabda851e8de971
MD5 d944918758bc93d7620440a087c39379
BLAKE2b-256 00be3ea40f51827f2401d7aa64072f82816e6e8dd7793ef79c77ec697a233258

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wasmtime-0.18.1-py3-none-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: Python 3, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for wasmtime-0.18.1-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9cb2a2f4c81ba2f57da8f9b02d6739b1f3f7d0024e66e88f041d9ed520bf0913
MD5 73c958946509fbcdd2d479bb4b6dd94b
BLAKE2b-256 f9eb95fd734f862e76203ff5f40cdbe6e5bd13872f36d1baabd61a4014751b6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wasmtime-0.18.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for wasmtime-0.18.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86dac3aefba479d2ee9819724cd71e6892b2b8ae4c0a5f082b2f370dc796b279
MD5 086865a8cfd4962d640aaec1e7a38d51
BLAKE2b-256 b17ae1d156a8443313d2914bd80858eb9d65c17365044e3bd701e42b4818b4bd

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