Code Monkey home page Code Monkey logo

wasmtime-py's Introduction

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])
instance.get_export("run").func().call()

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

wasmtime-py's People

Contributors

alexcrichton avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.