Skip to content

Commit 7627808

Browse files
docs(cli:introduction): Include CLI docs, and clean introduction.
1 parent 413a65c commit 7627808

3 files changed

Lines changed: 177 additions & 4 deletions

File tree

docs/pages/getting-started/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ description: "What Edge Python is and where to go next."
55

66
# Introduction
77

8-
Edge Python is a sandboxed Python subset compiled to a less 200 KB WebAssembly module release, built in Rust to run on Cloudflare Workers, and the browser.
8+
Welcome to the Edge Python docs! 👋 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.
99

10-
## Explore
10+
## Ecosystem
1111

1212
1. [Quickstart](/getting-started/quickstart): Run your first Edge Python program in under a minute.
13-
2. [The language](/language/syntax): How to write a program?
13+
2. [Syntax](/language/syntax): How to write a program?
1414
3. [Reference](/reference/builtins): All the builtin methods.
1515
4. [Implementation](/implementation/design): Compiler architecture, dispatch model, and runtime layout.
1616

@@ -22,7 +22,7 @@ Run live in your browser at [demo.edgepython.com](https://demo.edgepython.com/).
2222

2323
### Command Line Interface:
2424

25-
Or download it to your machine ([reference docs](https://github.com/dylan-sutton-chavez/edge-python/tree/main/cli)):
25+
Or download it to your machine ([reference docs](/reference/builtins)):
2626

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

docs/pages/reference/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
packages: 'Packages',
66
imports: 'Imports',
77
'writing-modules': 'Writing Modules',
8+
cli: 'CLI',
89
'wasm-abi': 'WASM ABI',
910
'limits-and-errors': 'Limits and Errors',
1011
}

docs/pages/reference/cli.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: "CLI"
3+
description: "The Edge Python developer CLI: run, serve, repl, init, package management, and build."
4+
---
5+
6+
The `edge` developer CLI. Write `.py`, run it, serve it, ship it — you never compile anything yourself. `edge` hosts the [Edge Python runtime](/getting-started/what-it-is#where-it-runs) in a headless Chromium provisioned at install time, then runs your code against it. You just point it at a file.
7+
8+
```bash
9+
edge run app.py # run a script
10+
edge serve # dev server with live reload
11+
edge repl # interactive shell (demo)
12+
edge test # run *_test.py files (not implemented yet)
13+
edge init my-app # scaffold a project
14+
edge add network # add a package to packages.json
15+
edge remove network # remove a package from packages.json
16+
edge build # bundle to dist/
17+
edge uninstall # remove the binary, PATH entry, optionally Chromium
18+
```
19+
20+
The runtime does the actual work; `edge` is the loop around it. It launches system Chromium headless, serves the runtime alongside your code, runs everything in that browser, and streams output back to your terminal. `edge serve` opens the same setup in your own browser.
21+
22+
## Install
23+
24+
```bash
25+
# Prebuilt binary (recommended)
26+
curl -fsSL https://dylan-sutton-chavez.github.io/edge-python/install.sh | sh
27+
28+
# Or from source (any platform with Rust and Cargo)
29+
cargo install --path cli
30+
```
31+
32+
`install.sh` drops the binary at `~/.local/bin/edge` and appends that directory to your `~/.bashrc` or `~/.zshrc` if it isn't already on `PATH`. Open a new shell (or `source` the file it printed) and `edge --version` should work. Re-run the same `curl … | sh` line any time to upgrade. To remove everything: `curl -fsSL https://dylan-sutton-chavez.github.io/edge-python/uninstall.sh | sh` (asks before touching Chromium).
33+
34+
`install.sh` also provisions Chromium if it isn't already on `PATH`. It reads `/etc/os-release` and uses the host's package manager (`apt`, `dnf`, `pacman`, `zypper`, `apk`, or `brew --cask` on macOS); `sudo` is invoked only when not running as root. On an unsupported distro, install Chrome/Chromium manually or set `EDGE_CHROME_PATH=/path/to/chrome`. See [Bring your own browser](#bring-your-own-browser).
35+
36+
## `edge run` — run a Python file
37+
38+
Runs a script and streams its output to the terminal. Imports resolve through [`packages.json`](/reference/imports#packagesjson); uncaught errors print a traceback to stderr and exit with code 1.
39+
40+
```text
41+
$ edge run hello.py
42+
Hello from Edge Python
43+
the sum is 42
44+
```
45+
46+
```text
47+
$ edge run broken.py
48+
before
49+
error: ZeroDivisionError: division by zero
50+
--> <input>:2:1
51+
|
52+
2 | x = 1 / 0
53+
| ^
54+
```
55+
56+
A `raise SystemExit(code)` with an integer (or no argument) exits cleanly with that code and no traceback; a string argument is reported as an error and exits 1.
57+
58+
Flags: `--packages <file>` (custom manifest). When no path is given, `edge run` reads from stdin if it is piped (`cat hello.py | edge run`); it errors out if stdin is a terminal.
59+
60+
## `edge serve` — local dev server
61+
62+
A dev server for browser apps. Serves your project directory and reloads the page on any file change via an injected polling client.
63+
64+
```text
65+
$ edge serve
66+
http://localhost:5173
67+
watching .
68+
```
69+
70+
Flags: `--port <n>` (default `5173`), `--open` (open the browser).
71+
72+
## `edge repl` — interactive shell (demo)
73+
74+
An interactive Edge Python shell for quick experiments.
75+
76+
```text
77+
$ edge repl
78+
Edge Python 0.1.0 · .exit, Ctrl+C or Ctrl+D to quit
79+
>>> from math import sqrt, pi
80+
>>> print(sqrt(2))
81+
1.4142135623730951
82+
>>> print([n * n for n in range(5)])
83+
[0, 1, 4, 9, 16]
84+
>>> .exit
85+
```
86+
87+
History (arrow keys) and multi-line blocks (a line ending in `:` continues until a blank line) are supported. `.exit`, `Ctrl+C`, or `Ctrl+D` quit; `.reset` wipes the accumulated session. Expression results are not auto-printed — use `print()` explicitly.
88+
89+
State is preserved by **recompiling and rerunning the accumulated session on every prompt**: the runtime resets its VM on each `run_start`, so imports and definitions only persist by replay. Trade-offs — side effects (`time()`, `random()`, network, IO) re-fire on every input, the chunk heap grows linearly with session length, and each eval pays the recompile cost. For long sessions or side-effect-heavy code, prefer `edge run` on a script.
90+
91+
> This is a demo: actual cost is O(n²). A first-class incremental compile path in the VM is the proper fix and is tracked for a future runtime change.
92+
93+
## `edge test` — test runner
94+
95+
Not implemented yet. The `test` package itself (the harness you import) is available: `edge add test` writes it to `packages.json`, and both `edge run` and `edge serve` resolve it by default, so a script can already `from test import fixture, test, raises, run` and call `run()` itself.
96+
97+
## `edge init` — scaffold a workspace
98+
99+
Scaffolds a ready-to-run project: an entry script, an HTML host page, and a manifest.
100+
101+
```text
102+
$ edge init my-app
103+
created my-app/
104+
├─ index.html
105+
├─ main.py
106+
└─ packages.json
107+
108+
next:
109+
cd my-app && edge serve
110+
```
111+
112+
`--bare` skips `index.html` for script-only projects.
113+
114+
## `edge add` / `edge remove` — package manager
115+
116+
Manage [`packages.json`](/reference/imports#packagesjson) by name. `edge` knows the official std (`json`, `re`, `math`, `test`) and host (`dom`, `network`, `storage`, `time`) packages, so you don't paste URLs. Most std packages are `.wasm`; `test` is pure Edge Python, so it resolves to `test.py`. See [Official packages](/reference/packages) for the full catalog.
117+
118+
```text
119+
$ edge add math network
120+
+ math std
121+
+ network host
122+
123+
updated packages.json
124+
```
125+
126+
```text
127+
$ edge remove network
128+
- network
129+
130+
updated packages.json
131+
```
132+
133+
Point a package at a custom URL with `edge add foo=https://example.com/foo.wasm`.
134+
135+
## `edge build` — portable bundle
136+
137+
Bundles your app into a self-contained `dist/` for offline use or self-hosting: the runtime, the `compiler.wasm`, your scripts, and every package vendored locally so nothing is fetched at runtime.
138+
139+
```text
140+
$ edge build
141+
successful - vendored runtime
142+
successful - fetched compiler.wasm
143+
successful - vendored packages
144+
145+
bundled to dist/
146+
147+
13 runtime files + compiler.wasm
148+
2 packages
149+
3 scripts
150+
151+
1.24 MB · 5.3s
152+
```
153+
154+
Flags: `--out <dir>` (default `dist/`).
155+
156+
## `edge uninstall`
157+
158+
Removes the binary and its `PATH` entry, and asks before removing Chromium. Equivalent to the `uninstall.sh` one-liner in [Install](#install).
159+
160+
## Global flags
161+
162+
| Flag | Effect |
163+
|------|--------|
164+
| `--packages <file>` | Use a specific manifest instead of `./packages.json` |
165+
| `--no-color` | Disable colored output |
166+
| `--version` / `-V` | Print version |
167+
168+
`Ctrl+C` cancels any running command cleanly.
169+
170+
## Bring your own browser
171+
172+
`edge` drives whatever system Chrome/Chromium is on `PATH` (`chromium`, `chromium-browser`, `google-chrome`, or `microsoft-edge`). `install.sh` provisions it on supported distros and macOS; on anything else, install it manually or point `EDGE_CHROME_PATH=/path/to/chrome` at the binary.

0 commit comments

Comments
 (0)