Skip to content

dylan-sutton-chavez/edge-python

Repository files navigation

Edge Python

A compact bytecode compiler and stack VM for a sandboxed Python subset, written in Rust. See Design for the architecture.

Edge Python is distributed as a WebAssembly module — compiler.wasm, ~170 KB. It runs anywhere WebAssembly runs: browsers, Cloudflare Workers, Fastly Compute, Wasmtime, Wasmer, Spin. Sandboxed by construction.

Repository layout

Cargo workspace; commands work from any directory.

compiler/        — bytecode compiler + VM (the .wasm artifact)
runtime/         — JS host (Web Worker, module loader, IDB cache)
demo/            — playground at demo.edgepython.com
documentation/   — language and reference docs
wasm-abi/        — sealed v1 wire spec (no_std, zero deps)
wasm-pdk/        — Rust author-side PDK (#[plugin_fn], macros)
starter-module/  — minimal plugin example
cargo wasm           # release .wasm (the distributed artifact)
cargo build --release # host .rlib + cdylib for Rust embedders
cargo test --release  # full test suite

Native modules ship via three delivery paths (CDN .wasm, host capability, JS host module) — see Writing modules.

Quick start

Browser

<script type="module">
    import { createWorker } from 'https://runtime.edgepython.com/js/src/index.js';

    const worker = await createWorker({
        wasmUrl: 'https://runtime.edgepython.com/js/compiler_lib.wasm',
        imports: { "math": "https://example.com/math.wasm" }
    });
    worker.onOutput(line => console.log(line));

    await worker.run(`
        from math import add
        from "https://example.com/utils.py" import normalize
        print(add(2, 3))
        print(normalize("  hi  "))
    `);
</script>

The runtime spawns a Web Worker that pre-fetches imports, dispatches native calls, and streams print() output back. Build the WASM yourself with cargo wasm (output ~390 KB unstripped; optionally wasm-opt -Oz to shrink).

Consume the release from a Rust host

Declare edge-python as a dependency and compiler_lib.wasm from the matching GitHub Release is fetched into OUT_DIR automatically — no manual download.

# Cargo.toml
[dependencies]
edge-python = { git = "https://github.com/dylan-sutton-chavez/edge-python", tag = "v0.1.0" }
// build.rs
fn main() {
    println!("cargo::rerun-if-changed=build.rs");
    let wasm = std::env::var("DEP_COMPILER_LIB_WASM")
        .expect("`DEP_COMPILER_LIB_WASM` unset — upstream must declare `links = \"compiler_lib\"`");
    std::fs::copy(&wasm, "runtime/compiler_lib.wasm").expect("copy failed");
}

Pin to a tag for reproducible builds; use branch = "main" for unreleased changes. Requires curl on PATH. Gated by the default-on prebuilt feature.

Server / edge runtimes (Wasmtime, Wasmer, Cloudflare Workers, Fastly Compute, Spin)

Edge Python is a cdylib — your host instantiates compiler_lib.wasm and calls its exports. The same .wasm you serve to browsers is the server-side artifact; the host owns I/O, fetching, and output (WASI / runtime APIs instead of fetch / postMessage). No built-in CLI — embed compiler_lib.wasm in a ~50-line wasmtime shell for local dev.

What it is

Edge Python targets sandboxed edge computing: a dynamic, multi-paradigm Python subset with classes, async/await, structural pattern matching, and compile-time module resolution. There is no bundled stdlib — modules are external artifacts.

Full language reference, scope, and what intentionally isn't supported: What Edge Python is. Architecture details: compiler/README.md.

License

MIT OR Apache-2.0

Sponsors

About

Single-pass SSA compiler and threaded-code VM for a sandboxed Python subset. NaN-boxed values, dual inline caching, super-instruction fusion, pure-function memoization, mark-sweep GC; classes with inheritance and dunder protocol, async/await, pattern matching, and packages.json imports. around 170 KB WebAssembly module.

Topics

Resources

License

Stars

Watchers

Forks

Contributors