{"id":4321,"library":"wasmer","title":"Wasmer Python","description":"Wasmer is a comprehensive WebAssembly runtime for Python, allowing developers to execute WebAssembly binaries securely and efficiently within Python applications. It compiles Wasm modules into native code for near-native performance. The current version, 1.1.0, was released in January 2022, and the project is actively maintained with ongoing developments, including features for Wasmer Edge.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/wasmerio/wasmer-python","tags":["WebAssembly","Wasm","runtime","compiler","FFI","Python extension","serverless"],"install":[{"cmd":"pip install wasmer wasmer_compiler_cranelift","lang":"bash","label":"Install Wasmer with Cranelift compiler (recommended for development)"},{"cmd":"pip install wasmer wasmer_compiler_llvm","lang":"bash","label":"Install Wasmer with LLVM compiler (recommended for production)"}],"dependencies":[{"reason":"Provides the Cranelift compiler, recommended for development workflows. Wasmer itself provides only headless engines by default.","package":"wasmer_compiler_cranelift","optional":false},{"reason":"Provides the LLVM compiler, generally recommended for production for optimized performance. Wasmer itself provides only headless engines by default.","package":"wasmer_compiler_llvm","optional":true},{"reason":"Provides the Singlepass compiler. Wasmer itself provides only headless engines by default.","package":"wasmer_compiler_singlepass","optional":true}],"imports":[{"symbol":"Store","correct":"from wasmer import Store"},{"symbol":"Module","correct":"from wasmer import Module"},{"symbol":"Instance","correct":"from wasmer import Instance"},{"note":"Used to select the engine, e.g., engine.JIT or engine.Native.","symbol":"engine","correct":"from wasmer import engine"},{"note":"Utility to convert WebAssembly Text Format (WAT) to WebAssembly binary format (Wasm).","symbol":"wat2wasm","correct":"from wasmer import wat2wasm"}],"quickstart":{"code":"from wasmer import Store, Module, Instance\nfrom wasmer_compiler_cranelift import Compiler\nfrom wasmer import engine\n\n# Create a Wasmer Store, which holds the engine and compiler\nstore = Store(engine.JIT(Compiler))\n\n# Define a WebAssembly module in WAT (WebAssembly Text Format)\nwasm_module_wat = \"\"\"\n(module\n  (type (func (param i32 i32) (result i32)))\n  (func (export \"sum\") (type 0) (param i32) (param i32) (result i32)\n    local.get 0\n    local.get 1\n    i32.add)\n)\n\"\"\"\n\n# Compile the module\nmodule = Module(store, wasm_module_wat)\n\n# Instantiate the module\ninstance = Instance(module)\n\n# Call the exported 'sum' function\nresult = instance.exports.sum(5, 37)\nprint(f\"The sum is: {result}\") # Expected: 42","lang":"python","description":"This quickstart demonstrates how to compile and run a simple WebAssembly module that exports a 'sum' function. It initializes a Wasmer store with the Cranelift compiler, defines a WAT module, compiles it, instantiates it, and then calls the exported function."},"warnings":[{"fix":"Refer to the official 1.0.0 migration guide and examples for the new API patterns. The core components like `Store`, `Module`, `Instance` remain, but their constructors and interactions have changed.","message":"The API underwent a complete rewrite between versions 0.x and 1.0.0 to better align with the core Wasmer runtime API. Code written for 0.x will not be compatible with 1.x without significant changes.","severity":"breaking","affected_versions":"0.x to 1.0.0"},{"fix":"Always install a compiler alongside `wasmer` (e.g., `pip install wasmer wasmer_compiler_cranelift`) and explicitly pass the compiler to the `engine` when creating a `Store`.","message":"The `wasmer` package itself ships with headless engines but no compilers by default. To compile WebAssembly modules, you *must* install a separate compiler package like `wasmer_compiler_cranelift` or `wasmer_compiler_llvm`. If no compiler is installed, compilation will fail.","severity":"gotcha","affected_versions":"All 1.x versions"},{"fix":"Utilize `instance.memory.buffer` and Python's buffer protocol (e.g., `bytearray(instance.memory.buffer)` or `memoryview(instance.memory.buffer)`) for efficient memory interaction.","message":"Memory access patterns changed and improved. Older methods for memory views could be less performant. For faster read/write operations on WebAssembly memory, use the `Memory.buffer` getter which implements the Python buffer protocol.","severity":"gotcha","affected_versions":"< 0.4.1"},{"fix":"Be aware that Python on Wasmer Edge is still evolving. Report any issues encountered to the Wasmer team for support and to contribute to its improvement. Consult Wasmer Edge documentation for latest status.","message":"Deploying Python applications to Wasmer Edge (a serverless WebAssembly platform) is currently in Beta. While actively developed, users might encounter 'rough edges' or unexpected behavior with complex projects.","severity":"gotcha","affected_versions":"All versions supporting Wasmer Edge"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}