{"id":4846,"library":"wasmtime","title":"Wasmtime Python Bindings","description":"Wasmtime-py provides Python bindings for the Wasmtime project, a fast, secure, and standards-compliant WebAssembly runtime. It allows Python applications to validate, compile, instantiate, and interact with WebAssembly modules, including support for WASI and the Component Model. The library follows the Wasmtime versioning scheme, releasing a new major version monthly, which can include breaking changes. The current version is 43.0.0.","status":"active","version":"43.0.0","language":"en","source_language":"en","source_url":"https://github.com/bytecodealliance/wasmtime-py","tags":["WebAssembly","Wasm","runtime","bytecode","sandbox","compiler","WASI","component-model"],"install":[{"cmd":"pip install wasmtime","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Store","correct":"from wasmtime import Store"},{"symbol":"Module","correct":"from wasmtime import Module"},{"symbol":"Instance","correct":"from wasmtime import Instance"},{"symbol":"Func","correct":"from wasmtime import Func"},{"symbol":"FuncType","correct":"from wasmtime import FuncType"}],"quickstart":{"code":"from wasmtime import Store, Module, Instance, Func, FuncType\n\n# Almost all operations in Wasmtime require a contextual 'store' argument.\nstore = Store()\n\n# Define a simple WebAssembly module in WAT format.\n# It imports a 'hello' function and exports a 'run' function that calls 'hello'.\nwasm_text = '''\n(module\n  (func $hello (import \"\" \"hello\"))\n  (func (export \"run\") (call $hello))\n)\n'''\n\n# Compile the module. This step happens once.\nmodule = Module(store.engine, wasm_text)\n\n# Define the Python function that the WebAssembly module will import.\ndef say_hello():\n    print(\"Hello from Python!\")\n\n# Create a Func object from the Python function, specifying its signature.\n# Here, it takes no parameters and returns nothing.\nhello_func = Func(store, FuncType([], []), say_hello)\n\n# Instantiate the module, providing the necessary imports.\n# The `hello_func` is mapped to the `\"\" \"hello\"` import.\ninstance = Instance(store, module, [hello_func])\n\n# Get the exported 'run' function from the WebAssembly module.\nrun = instance.exports(store)[\"run\"]\n\n# Call the WebAssembly 'run' function.\n# This in turn calls the Python `say_hello` function.\nrun(store)\n","lang":"python","description":"This quickstart demonstrates how to compile and instantiate a WebAssembly module using `wasmtime-py`. It defines a simple WAT module that imports a host function and exports a function to call it. The Python host function `say_hello` is then bound to the WebAssembly import and executed."},"warnings":[{"fix":"Review release notes and migration guides when upgrading major versions. Consider using dependency pinning or tools to automate version bumps.","message":"Wasmtime-py releases a new major version monthly, and these new versions can introduce breaking changes to the API and behavior. Users should regularly update their dependency requirements.","severity":"breaking","affected_versions":"All major versions, especially during upgrades (e.g., v42.x.x to v43.x.x)"},{"fix":"Upgrade to `wasmtime` version 43.0.1 or newer. If upgrading is not possible, avoid cloning `Linker` objects; instead, create a new `Linker` and manually re-register host APIs.","message":"Version 43.0.0 of `wasmtime` (the underlying Rust crate) has a use-after-free bug when cloning a `wasmtime::Linker` object. This can lead to segfaults if the original linker instance is dropped and then the cloned instance is used. The Python bindings are affected if they expose or implicitly use this unsound cloning behavior.","severity":"breaking","affected_versions":"43.0.0"},{"fix":"For performance-critical applications involving frequent, small Wasm function calls, consider using the Rust bindings directly or batching calls to reduce interop overhead. Python bindings are less optimized for this specific use case.","message":"Calling small WebAssembly functions from Python using `wasmtime-py` incurs a noticeable performance overhead (approximately 30μs per call in benchmarks). This is due to the overhead of interop between Python and the underlying Wasmtime C API.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that the latest features available in Wasmtime's core (Rust/C) might not be immediately available in the Python bindings. Consult the `wasmtime-py` documentation and GitHub repository for the most up-to-date feature set.","message":"Python bindings for Wasmtime are built on the C API and developed externally from the main Wasmtime repository. This means that updates and new features in `wasmtime-py` may lag behind the core Wasmtime project's Rust and C APIs.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}