Multi-language Workers development with Rust, Python, and WebAssembly. Use when building Workers in languages other than JavaScript/TypeScript, or when integrating WASM modules for performance-critical code.
SKILL.md
Multi-Language Workers Development
Build Cloudflare Workers using Rust, Python, or WebAssembly for performance-critical operations.
Language Comparison
Feature
JavaScript/TS
Rust
Python
Startup
Fast
Fastest (WASM)
Moderate
CPU Perf
Good
Excellent
Good
Memory
Higher
Lower
Higher
Bundle Size
Smaller
Medium
Larger
Type Safety
Optional (TS)
Strict
Optional
Best For
General apps
CPU-intensive
Data/ML
Quick Decision
Need maximum performance? → Rust/WASM
Heavy computation (crypto, image processing)? → Rust/WASM
Data processing, ML inference? → Python
General web apps? → JavaScript/TypeScript
# src/entry.py
from js import Response, Headers
async def on_fetch(request, env):
url = request.url
if "/compute" in url:
result = heavy_computation()
return Response.new(f"Result: {result}")
return Response.new("Hello from Python!")
def heavy_computation():
"""CPU-intensive computation"""
return sum(1 for n in range(2, 100000) if is_prime(n))
def is_prime(n):
if n < 2:
return False
return all(n % i != 0 for i in range(2, int(n**0.5) + 1))
WASM Module Integration
// Load and use WASM module in TypeScript Worker
import wasmModule from './pkg/my_lib_bg.wasm';
import { init, process_data } from './pkg/my_lib';
let wasmInstance: WebAssembly.Instance;
export default {
async fetch(request: Request, env: Env): Promise<Response> {
// Initialize WASM once
if (!wasmInstance) {
wasmInstance = await WebAssembly.instantiate(wasmModule);
init();
}
// Use WASM function
const result = process_data(inputData);
return Response.json({ result });
},
};
When to Load References
Reference
Load When
references/rust-workers.md
Building Workers with Rust/WASM
references/python-workers.md
Using Python on Workers for Platforms
references/wasm-integration.md
Integrating WASM modules in any Worker
Performance Tips
WASM Initialization: Cache instance, use streaming
Memory: Use typed arrays for data transfer
Bundle Size: Enable LTO, strip debug info
Cold Starts: Keep WASM modules small
Data Transfer: Minimize JS/WASM boundary crossings
See Also
workers-performance - General optimization techniques