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

You can install this extension via:

pip install wasmtime

Currently only x86_64 Windows, macOS, and Linux are supported for this Python extension.

Usage

An example of compiling a module and importing functionality from Python can be done with:

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

If your wasm modules works this way, then you can also import the wasm module directly into Python without 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

# And now you're 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 send 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. This extension expects your platform's shared library to exist at wasmtime/wasmtime.pyd. You can download the latest development version of Wasmtime with python download-wasmtime.py (this is what CI does). 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 make sure it works by running all the tests:

$ pip install pytest
$ pytest

And after that you should be good to go!

CI and Releases

It's intended that this module is a largely automated process for all of the particulars. The CI for this project does a few different things:

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

Otherwise all commits/PRs run the full test suite and also check for style with 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.16.0-py3-none-win_amd64.whl (2.5 MB view details)

Uploaded Python 3Windows x86-64

wasmtime-0.16.0-py3-none-manylinux1_x86_64.whl (3.9 MB view details)

Uploaded Python 3

wasmtime-0.16.0-py3-none-macosx_10_13_x86_64.whl (2.9 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: wasmtime-0.16.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for wasmtime-0.16.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ab0427c417adf87e787723d517dabd08dc26c54d196ff4dbc577e99a9f702326
MD5 7850c2486b2222f14748a1096e9b8ac8
BLAKE2b-256 53d6955294fa8c190597da8dcab7e37c04cb9ff698d3fd4a177709bff97e79f1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wasmtime-0.16.0-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 3.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for wasmtime-0.16.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 304f908ab116b03011257afb8ff71deccbdcc190c70f77069cbd8c97182f18f9
MD5 83b357dbc7543c9cd0b8550665df964d
BLAKE2b-256 3209ca100a0fb118ef88218a0411b5b17da140cd057a865c8e18cad9d840fd07

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wasmtime-0.16.0-py3-none-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: Python 3, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for wasmtime-0.16.0-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 03ba43a3b80dfdb991e072ab1d680c0b6cda029c3bed763e52a8104dd707b3af
MD5 b5a7fd076284b13902de1b9b078a5c56
BLAKE2b-256 ba3da5462781865287fc3d7f1eacfb43cd516e5b57d40900de61555ec3b893c7

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