v0.5.2 • Actively Developed • View Modules

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

🐍

Python AST

Parse with RustPython

⚙️

Custom IR

Intermediate Rep.

🔧

WASM Binary

wasm-encoder

Optimized

Binaryen

Waspy vs Other Python Implementations

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?

🚀

Fast Compilation

Built in Rust for blazing-fast compilation times. Transform your Python functions to optimized WebAssembly in milliseconds.

🎯

Type Safety

Full support for Python type annotations. Get compile-time type checking and better WebAssembly optimization.

High Performance

Optimized WebAssembly output with Binaryen. Your Python functions run at near-native speed in any environment.

🔧

Easy Integration

Simple API that works with your existing Python code. No need to rewrite - just compile and deploy.

🌐

Universal Runtime

Run anywhere WebAssembly is supported: browsers, Node.js, serverless, edge computing, and more.

🛠️

Rich Features

Control flow, function calls, decorators, classes, and more. Comprehensive Python language support.

📦

Multi-File Support

Compile entire Python projects with multiple files, dependencies, and entry points into single WASM modules.

🔍

Project Analysis

Built-in import analysis, circular dependency detection, and project structure understanding.

🎨

Decorator Support

Function decorators including memoization, debugging, timing, and custom decorator registry.

Get Started in Minutes

1. Install Waspy

Add Waspy to your Rust project:

cargo add waspy

2. Compile Python to WASM

Use the simple API to compile your Python functions:

let wasm = waspy::compile_python_to_wasm(python_code)?;

3. Advanced Features

Compile entire projects with options:

let wasm = waspy::compile_python_project("./my_project", true)?;

4. Run Anywhere

Execute your compiled WebAssembly in any environment:

WebAssembly.instantiate(wasm).then(instance => { /* magic */ });