Python → WebAssembly
Compile Python functions to WebAssembly with ease. Built in Rust for performance and reliability.
# fibonacci.py
def fibonacci(n: int) -> int:
if n <= 1:
return n
a, b = 0, 1
for i in range(2, n + 1):
a, b = b, a + b
return b
def factorial(n: int) -> int:
result = 1
for i in range(1, n + 1):
result *= i
return result
use waspy::compile_python_to_wasm;
fn main() -> Result<(), Box> {
let python_code = std::fs::read_to_string("fibonacci.py")?;
let wasm = compile_python_to_wasm(&python_code)?;
std::fs::write("fibonacci.wasm", &wasm)?;
println!("✅ Compiled to WebAssembly!");
Ok(())
}
// Run the compiled WebAssembly
WebAssembly.instantiate(wasmBuffer).then(result => {
const { fibonacci, factorial } = result.instance.exports;
console.log(fibonacci(10)); // 55
console.log(factorial(5)); // 120
// Blazing fast execution! 🔥
});
How Waspy Works
From Python source to optimized WebAssembly in four steps.
Python AST
Parse with RustPython
Custom IR
Intermediate Rep.
WASM Binary
wasm-encoder
Optimized
Binaryen
Waspy vs Other Python Implementations
See how Waspy compares across performance, safety, and portability.
| Feature | Waspy | CPython | MicroPython | PyPy | HPy |
|---|---|---|---|---|---|
| Target | WebAssembly | Native/VM | Microcontrollers | JIT Compilation | C Extensions |
| Performance | Near-native WASM | Interpreted | Optimized for size | JIT optimized | Native speed |
| Type Safety | Compile-time | Runtime only | Runtime only | JIT inference | Runtime only |
| Universal Runtime | Browser/Server/Edge | OS dependent | Hardware specific | OS dependent | OS dependent |
| Startup Time | Instant | Module loading | Fast | JIT warmup | Import overhead |
| Memory Usage | Minimal | Standard | Ultra-low | Higher (JIT) | Standard |
| Standard Library | Basic support | Complete | Subset | Complete | Complete |
| Security | Sandboxed WASM | Full system access | Hardware limited | Full system access | Full system access |
| Use Case | Web apps, serverless | General purpose | IoT, embedded | CPU-intensive apps | C extension API |
Why Waspy?
Everything you need to compile Python to WebAssembly — fast, safe, and ready for production.
Fast Compilation
Built in Rust for blazing-fast compilation times. Transform your Python functions to optimized WebAssembly in milliseconds.
Rust-poweredType Safety
Full support for Python type annotations. Get compile-time type checking and better WebAssembly optimization.
Compile-timeHigh Performance
Optimized WebAssembly output with Binaryen. Your Python functions run at near-native speed in any environment.
BinaryenEasy Integration
Simple API that works with your existing Python code. No need to rewrite — just compile and deploy.
Drop-inUniversal Runtime
Run anywhere WebAssembly is supported: browsers, Node.js, serverless, edge computing, and more.
Run anywhereRich Features
Control flow, function calls, decorators, classes, and more. Comprehensive Python language support.
Full languageMulti-File Support
Compile entire Python projects with multiple files, dependencies, and entry points into single WASM modules.
Project-wideProject Analysis
Built-in import analysis, circular dependency detection, and project structure understanding.
Smart analysisDecorator Support
Function decorators including memoization, debugging, timing, and custom decorator registry.
ExtensibleArchitecture
Get Started in Minutes
Four steps from zero to compiled WebAssembly.
Install Waspy
Add Waspy to your Rust project:
cargo add waspy
Compile Python to WASM
Use the simple API to compile your Python functions:
let wasm = waspy::compile_python_to_wasm(python_code)?;
Advanced Features
Compile entire projects with options:
let wasm = waspy::compile_python_project("./my_project", true)?;
Run Anywhere
Execute your compiled WebAssembly in any environment:
WebAssembly.instantiate(wasm).then(instance => { /* magic */ });