# Stario

Stario is a Python framework for server-rendered hypermedia apps. Handlers are async functions that write HTML through a `Writer`. Routes are explicit `Route` values. Datastar morphs the page in the browser. A long-lived SSE stream keeps a page live. State lives on the server. Stario is not ASGI; run it with `python -m app.main`, or `just dev` / `uv run watchfiles 'python -m app.main' app/ static/` in development.

## Start here

- [AGENTS.md](https://stario.dev/AGENTS.md): the app guide, enough for a first app. Copy it into every Stario repo: the loop, a live page with search and paging, commands, names, the rules that bite, accounts.
- [stario-create](https://github.com/stariodev/stario-create): `uvx stario-create new my-app --db` creates a runnable app with the guide, the skills, and a `justfile`.
- [llms-full.txt](https://stario.dev/llms-full.txt): the guide and the skills in one file, for tools that want more context.
- [The Stario way](https://stario.dev/docs/explanation/the-stario-way): why Stario is shaped this way.

## Skills (loaded when their topic comes up)

- [stario-accounts](https://stario.dev/skills/stario-accounts/SKILL.md): Accounts past the add auth kits in a Stario app - Google or GitHub sign-in setup, a signed-in header, rows each user owns, profiles and settings, password change, roles and admin pages, API tokens. Use when the task goes past sign-up, sign-in and protected pages (AGENTS.md has those).
- [stario-background](https://stario.dev/skills/stario-background/SKILL.md): State and work outside SQLite in a Stario app - a live page on state in memory (Relay), slow work with live progress (an export, an import, a model call), a timer loop, a message to one tab, clean shutdown. Use when state is not in the database or work outlasts the request.
- [stario-js](https://stario.dev/skills/stario-js/SKILL.md): JavaScript in a Stario app - a static/js file per behaviour, app.name functions called from data.on, clipboard, drag, charts, editors, keyboard input; the browser check for JS that holds state. Use before writing any script or addEventListener. Not for what data.* attributes already do.
- [stario-migrate](https://stario.dev/skills/stario-migrate/SKILL.md): Change SQLite tables that already hold rows in a Stario app - add a column and fill old rows, rename or retype one, an index, a test on an old database. Use when a table with rows gets a new or changed column (an app in use, an upgrade). Not for new tables, which CREATE TABLE IF NOT EXISTS makes.
- [stario-outside-api](https://stario.dev/skills/stario-outside-api/SKILL.md): Call an outside HTTP API from a Stario app - an httpx client opened in bootstrap, typed results, a cache, a 404 or 502 page when the service fails, offline tests with httpx.MockTransport. Use when pages read data from another service over HTTP.
- [stario-reference](https://stario.dev/skills/stario-reference/SKILL.md): Stario, Datastar and litewriter names past AGENTS.md - more data.* and at.* options, SSE morph modes, dialogs, infinite scroll, a live navbar count, uploads, signed cookies, middleware, error pages, server settings, JSON endpoints. Use when AGENTS.md lacks a name or pyrefly rejects one.
- [stario-tests](https://stario.dev/skills/stario-tests/SKILL.md): TestClient tests for a Stario app - pages, Datastar commands, plain forms, live streams in two tabs, sign-in, bad input. Use when the task asks for tests or ships no acceptance suite. Not when the task ships its own suite (npm test, Playwright).

## Docs

- [Hello world](https://stario.dev/docs/tutorials/hello-world): first bootstrap, handler, page.
- [Realtime tiles](https://stario.dev/docs/tutorials/realtime-tiles): one live page in one file.
- [Chat room](https://stario.dev/docs/tutorials/chat-room): the same idea as a project tree.
- [Live pages](https://stario.dev/docs/explanation/live-pages): one open response, short commands, render from state.
- [Structuring apps](https://stario.dev/docs/how-tos/structuring-apps): the file tree.
- [Datastar from Python](https://stario.dev/docs/how-tos/datastar-sdk): `data`, `at`, `SSE`, `read_signals`.
- [Routing](https://stario.dev/docs/reference/routing): `Route`, `app.add`, middleware.
- [Runtime](https://stario.dev/docs/reference/runtime): bootstrap lifecycle, `App`, `Server`.
- [Configuration](https://stario.dev/docs/reference/configuration): `STARIO_*` variables, `ServerConfig`.
- [Testing](https://stario.dev/docs/reference/testing): `TestClient`, `stream`, `iter_events`.
- [Telemetry](https://stario.dev/docs/reference/telemetry): spans and tracers.
- [JSON](https://stario.dev/docs/reference/json): the process-wide codec.

## Examples

- [chat-room](https://github.com/stariodev/stario/tree/main/examples/chat-room): the reference project tree.
- [tiles](https://github.com/stariodev/stario/tree/main/examples/tiles): single-file live board.
- [hello-world](https://github.com/stariodev/stario/tree/main/examples/hello-world): one route, one page.

## Defaults in one paragraph

A page is a resource: the path names it, and the query holds the view (sort, filter, columns). Every route is in `app/urls.py`; the tables and every read and write are in `app/data.py`; pages live in `app/pages/<area>.py`, one module per area, each page a class with its render functions. The class's fields are its dependencies, `register(app)` adds its routes, and each route is one method. A page whose state cannot change while it is open is one `GET`, plus private reads that patch one part. A live page is `GET /page`, `GET /page/live`, and `POST` commands that read, validate, write, and then reply. Only the stream sends HTML; a message for one tab goes through `Relay` on `tab.<id>`. The HTTP status is the reaction of the browser; the span is the outcome of the work. SQLite tables have plain columns; a table of `id` plus JSON is an option. Tests run through `TestClient(bootstrap)` and read the stream with `iter_events()`.
