Registry / ai-ml / wasmer-compiler-cranelift

wasmer-compiler-cranelift

JSON →
library1.1.0pypypi✓ verified 27d ago

The `wasmer-compiler-cranelift` library provides the Cranelift compiler backend for the `wasmer` Python package, enabling the compilation of WebAssembly (Wasm) modules. Cranelift is known for its balanced approach, offering faster compilation times compared to LLVM, moderate runtime performance, and enhanced security against malicious Wasm input. The current Python package version is `1.1.0` (released Jan 2022), though the underlying Wasmer runtime frequently updates, with Wasmer 7.0 (Jan 2026) featuring an upgraded Cranelift backend and new capabilities for Python integration.

pip install wasmer wasmer-compiler-cranelift
INSTALL
IMPORT
SIG · WASMER-COMPILER-CR
W
wasmer-compiler-cranelift
ai-mlpythonv1.1.0
Install
1.7s avg
Import
—
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 28MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Compiler
✓ from wasmer_compiler_cranelift import Compiler
Imports the Cranelift compiler backend.
Store
✓ from wasmer import Store
Imports the Wasm store context.
Module
✓ from wasmer import Module
Imports the Wasm module class.
Instance
✓ from wasmer import Instance
Imports the Wasm instance class.
engine
✓ from wasmer import engine
Imports the Wasmer engine types (e.g., JIT, Native).
wat2wasm
✓ from wasmer import wat2wasm
Utility to convert WebAssembly Text (WAT) to Wasm bytes.

This quickstart demonstrates how to initialize a Wasmer Store with the Cranelift compiler, compile a simple WebAssembly module defined in WAT format, instantiate it, and call an exported function.

from wasmer import Store, Module, Instance, engine, wat2wasm from wasmer_compiler_cranelift import Compiler # 1. Create a Store with the Cranelift compiler # You can choose between JIT (Just-In-Time) or Native engine. # JIT is good for development and dynamic compilation. store = Store(engine.JIT(Compiler)) # 2. Define a WebAssembly module in WebAssembly Text Format (WAT) wasm_bytes = wat2wasm( """ (module (type (func (param i32 i32) (result i32))) (func (export "sum") (type 0) (param i32) (param i32) (result i32) local.get 0 local.get 1 i32.add ) ) """ ) # 3. Compile the Wasm module module = Module(store, wasm_bytes) # 4. Instantiate the module instance = Instance(module) # 5. Call an exported function result = instance.exports.sum(5, 37) print(f"Result of sum(5, 37): {result}") # Expected: 42
Debug
Known issues
breakingThe `wasmer-python` API, including how compilers are used, underwent significant changes with the `1.0.0` release to better align with the Wasmer C API. Code written for `0.x` versions will likely break.
fix
Refer to the `wasmer-python` 1.x documentation for updated API usage, particularly for `Store`, `Module`, and `Instance` creation.
affects: <1.0.0
gotcha`wasmer-compiler-cranelift` is a companion package and requires the `wasmer` package to be installed alongside it to function correctly. It is not a standalone runtime.
fix
Ensure both `wasmer` and `wasmer-compiler-cranelift` are installed: `pip install wasmer wasmer-compiler-cranelift`.
affects: All
gotchaWhile Cranelift offers faster compilation, the `wasmer-compiler-llvm` backend typically provides approximately 50% better runtime performance for production environments where execution speed is critical. Choose the compiler based on your specific needs (fast compilation vs. fast execution).
fix
Consider `wasmer-compiler-llvm` for production workloads requiring maximum execution speed: `from wasmer_compiler_llvm import Compiler`.
affects: All
gotchaIf a pre-compiled binary wheel for `wasmer` (and its compilers) is not available for your specific system or Python version, a fallback pure-Python wheel might be installed. This can lead to an `ImportError` at runtime with the message 'Wasmer is not available on this system'.
fix
Verify that a compatible binary wheel is available for your platform/Python version. Check the official `wasmer` documentation or PyPI for supported environments. You might need to build from source in some cases.
affects: All
Upgrade
Version history
1.1.0latest on PyPI · released Jan 7, 2022
Audit
Dependencies
wasmerrequiredRequired for the core WebAssembly runtime and API.
Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
wasmer-compiler-cranelift — pip install wasmer-compiler-cranelift · libregistry