Skip to content

dylan-sutton-chavez/edge-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

980 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Edge is a sandboxed subset of Python, compiled to a less than 200 KB WebAssembly binary and built in Rust to run on Cloudflare Workers and in the browser. Embed your full business logic, run LLMs client-side, build frontend apps and serverless workloads.

  • Secure by default. No file, network, or environment access, unless explicitly enabled by the host.
  • Less than 200 KB footprint. The full compiler and runtime ship as a single WASM binary.
  • Compile-time imports. Every module resolves at parse time no dynamic loading, no runtime surprises.
  • No AST, source compiles directly to bytecode in a single pass: o(n)

More about it

Repository layout

Cargo workspace; commands work from any directory.

├── cli
├── compiler
├── demo
├── docs
├── host
├── runtime
├── std
├── target
├── wasm-abi
└── wasm-pdk
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

CLI

download it to your machine (reference docs):

curl -fsSL https://dylan-sutton-chavez.github.io/edge-python/install.sh | sh

edge -h # List all commands

edge hosts the runtime in a headless Chromium provisioned by install.sh (apt, dnf, pacman, zypper, apk, or brew on macOS) for serve, repl, build and uninstall.

Browser

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <script type="module" src="https://cdn.edgepython.com/runtime/src/element.js"></script>
</head>
<body>
  <edge-python entry="./app/main.py" packages="./app/packages.json"></edge-python>
</body>
</html>

The runtime spawns a Web Worker that pre-fetches imports, dispatches native calls, and streams print() output back.

Consume the release from a Rust host

Declare edge-python as a dependency and compiler.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\"`");
  std::fs::copy(&wasm, "runtime/compiler.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.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 server-side CLI ships here (the cli/ tool targets the browser runtime), so embed compiler.wasm in around 50 LOC 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.

CI/CD

One workflow .github/workflows/main.yml that runs the complete CI/CD, where each package is a steps in a composite action under .github/actions/.

On pushes to main it deploys three Cloudflare Pages projects: edge-python-cdn (the bundled package artifacts), edge-python-demo, and edge-python-docs (served at edgepython.com).

License

MIT OR Apache-2.0

Sponsors

About

Single-pass SSA compiler and bytecode VM for a sandboxed Python subset. NaN-boxed values, dual inline caching (scalar + instance-dunder), super-instruction fusion, pure-function memoization, mark-sweep GC; classes with inheritance and dunder protocol, stackful coroutines with async/await, pattern matching, and packages.json imports. 170 KB WASM.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages