# PyWeft documentation, as plain text Everything in one file, for AI tools. The site: https://prassanthn.github.io/PyWeft/ Contents: the guide for coding assistants, the framework guide, the pyweft-ui reference, the pyweft-ui guide. --- # Writing this app: a PyWeft guide for coding assistants This is a **PyWeft** app: a Python UI framework. Components are `.weft` files with an XML template, a Python code block and scoped CSS. It runs in the browser (Python on WebAssembly via Pyodide) or as a desktop window. PyWeft is new: don't assume Vue, React, Svelte, Blazor or Jinja syntax. The rules below are the ones that differ. Written for pyweft 0.6.0. Refresh with `pyweft agents .` after upgrading. Full documentation: https://prassanthn.github.io/PyWeft/ (all of it as plain text: https://prassanthn.github.io/PyWeft/llms-full.txt). ## Commands ```bash uv run pyweft check . # find mistakes without running it (exit 1 on errors) uv run pyweft run . # dev server with hot reload: http://127.0.0.1:8642/ uv run pyweft run . --desktop # in a native window (needs: uv add "pyweft[desktop]") uv run pyweft build . # static site in dist/ (any static host) uv add # a dependency, installed in the browser at load ``` **After changing any `.weft` file, run `uv run pyweft check .` and fix what it reports** before saying you're done. It loads every component and reports, with file and line: template and Python errors, unknown names, handlers, `@bind` fields and components, props a component doesn't take, events it never emits, slots it doesn't have, and the traps below. It suggests the name you probably meant. `--json` gives the same as JSON. (`pip install`/`python -m pyweft` work too.) Dependencies go in `pyproject.toml`'s `[project].dependencies`, managed with `uv add`; in the browser they (and everything they depend on) must be pure-Python wheels or packages Pyodide has built (numpy, pandas, pydantic 2.7, ...). LangChain and the OpenAI and Anthropic SDKs don't install in the browser (native code); call an HTTP API with `pyweft.http`, or use the desktop app, where any package works. `pyweft check` reports a dependency that won't install. There is no other manifest. ## The app folder - `app.weft`: the root component. Other `.weft` files are components. - `` in a template is `TodoItem.weft` or `todo_item.weft` **next to the file using it**; `` is `widgets/row.weft` from the app root. - `.py` files are ordinary modules (shared data, a `Store`); import them by name from a code block. A changed `.py` reloads the page. - `styles.css` (any `.css` at the root): global CSS. `head.html`: extra `` content (fonts, CDN CSS). `assets/`: files served at `assets/...`. - `pyproject.toml` `[tool.pyweft]`: `title`, `icon = "assets/icon.png"`. - Folders starting with `_`, `dist/` and `node_modules/` are not shipped. Everything else in the app is visible to visitors: no secrets in it. ## A component ```xml items: list = [] text: str = "" next_id: int = 1 @property def left(self): return sum(1 for item in self.items if not item["done"]) def add(self): if self.text.strip(): self.items.append({"id": self.next_id, "text": self.text.strip(), "done": False}) self.next_id += 1 self.text = "" def toggle(self, item): item["done"] = not item["done"] def remove(self, item): self.items = [i for i in self.items if i["id"] != item["id"]] ``` - **Three blocks:** `