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

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
Full support
Partial support
Limited / None

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-powered
🎯

Type Safety

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

Compile-time

High Performance

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

Binaryen
🔧

Easy Integration

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

Drop-in
🌐

Universal Runtime

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

Run anywhere
🛠️

Rich Features

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

Full language
📦

Multi-File Support

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

Project-wide
🔍

Project Analysis

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

Smart analysis
🎨

Decorator Support

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

Extensible

Architecture

Binaryen core::config::load_project_config analysis::project::analyze_dependencies Combine All IRModules Same as Single File from here 📁 Project Directory ⚙️ Project Config + File List 🔗 Dependency Graph + Import Analysis For Each Python File 🐍 Python Source 🌳 AST 📦 IRModule 🔀 Resolve Circular Dependencies 📦 Resolved IRModule 🚪 IRModule + Entry Points ⚙️ Compilation Context WASM 🚀 Optimized WASM

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 */ });