A WebAssembly runtime powered by Wasmtime
Project description
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(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 master branch and are published 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.
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
Built Distributions
Hashes for wasmtime-0.17.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5b60287cfed4781bea9ec849e4965cb9f05aa0c60bcc0707e31e69da1b13d52 |
|
MD5 | 6d91e36fb79ba4201b5f4e643779b976 |
|
BLAKE2b-256 | f6b18faa35d7372d6b91abb0a30ecf05e82318723bd3f62973a8ed3618e5c539 |
Hashes for wasmtime-0.17.0-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53132ddd5c9068c9f0a4c393e1287c303047bed306004df1bbf97863dc2b13b2 |
|
MD5 | f215996452464da2c29970d849d82f57 |
|
BLAKE2b-256 | e192aad71581d24c182e2645f1c397df09a6747f1f31f5abe8a99fb374dbb703 |
Hashes for wasmtime-0.17.0-py3-none-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e6c2c73b693f1b449219d4be2fc905eb7b07a7480fcea1bd48c25b601ae934b |
|
MD5 | 60317db1d5cf7dc6e71ee62f2ff443c6 |
|
BLAKE2b-256 | 211a3ab4a00fa5f1ef49f6748a323790e0e7731b57b637d095831f26ccc2ef5a |
Hashes for wasmtime-0.17.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acdad4a59fa704094d4946155936b9be7a70883bdcb37a2a5f527be176786fd6 |
|
MD5 | cf02386734ba5320cb1c3fc1ff97f61d |
|
BLAKE2b-256 | 02ff6f533675769102aa742915930c748ab65ef71263117c55e03107f7e6d080 |