> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pylonsync.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Run Pylon in five minutes with a schema, policy, server function, and live sync.

This walkthrough runs a Pylon server with a schema, one policy, and one server function. You then call the API with `curl` to see it work. For a realtime UI, point the [React SDK](https://docs.pylonsync.com/clients/react.md), [Swift SDK](https://docs.pylonsync.com/clients/swift.md), or [React Native SDK](https://docs.pylonsync.com/clients/react-native.md) at the running server. You can also clone one of the [example apps](https://github.com/pylonsync/pylon-examples).

> [!TIP]
>
> **Start from a working app:**
>
> ```bash theme={null}
> npm create @pylonsync/pylon@latest my-app -- --template todo
> cd my-app && npm run dev
> ```
>
> This scaffolds a full-stack Pylon app with a React 19 SSR frontend and API on one port. The Pylon CLI is a project dependency, so `npm run dev` needs no global install. Run `npm create @pylonsync/pylon@latest` without arguments to choose among the `default` (SaaS), `todo`, `chat`, `shop`, `consumer`, `waitlist`, `ai-chat`, and other templates. Each app includes a `pylon test` setup.
>
> Deploy with `npm run deploy` or `pylon deploy`; see [Deploy](https://docs.pylonsync.com/operations/deploy.md).

The rest of this page builds a minimal backend by hand so you can see each piece. It uses a global `pylon` binary; if you'd rather start from the scaffold above, skip to [Concepts](https://docs.pylonsync.com/concepts/entities.md).

## 1. Install the CLI

```bash theme={null}
curl -fsSL https://www.pylonsync.com/install.sh | bash
```

Downloads a prebuilt `pylon` binary to `~/.local/bin`. Linux and macOS, x86\_64 and arm64. No Rust toolchain required. (The `npm create` scaffold above doesn't need this. It bundles the CLI. Install globally when you want `pylon` on your PATH for the from-scratch flow below.)

Pylon needs Bun ≥ 1.0 at runtime. It runs your server functions and SSR on Bun.

Verify:

```bash theme={null}
pylon --version
```

Other ways to install:

```bash theme={null}
# Cargo (compiles from source)
cargo install pylon-cli

# Docker
docker pull ghcr.io/pylonsync/pylon:latest
```

## 2. Scaffold a new app

```bash theme={null}
pylon init notes
cd notes
```

This scaffolds a Bun workspace with the API at `apps/api/`:

```
notes/
  apps/
    api/
      app.ts             # schema + manifest entry point
      sdk.ts             # local re-export of @pylonsync/sdk
      tsconfig.json
      package.json
  package.json           # workspace root
  .gitignore
  README.md
```

`pylon init` scaffolds the backend only, with no frontend framework, because Pylon renders React on the server natively. To also generate a separate frontend, pass `--frontend react` (Vite), `--frontend tanstack`, or `--frontend nextjs`, or pick interactively when stdin is a TTY. For a full-stack app with SSR pages, use `npm create @pylonsync/pylon` (above) instead.

You'll add a `functions/` directory under `apps/api/` by hand in step 4.

## 3. Define the schema

Replace `apps/api/app.ts` with:

```ts theme={null}
import { entity, field, policy, buildManifest } from "@pylonsync/sdk";

const Note = entity(
  "Note",
  {
    title: field.string(),
    body: field.string(),
    authorId: field.string(),
    updatedAt: field.datetime(),
  },
  {
    indexes: [{ name: "by_author", fields: ["authorId"], unique: false }],
  },
);

const notePolicy = policy({
  name: "note_public",
  entity: "Note",
  allowRead: "true",
  allowInsert: "auth.userId == data.authorId",
  allowUpdate: "auth.userId == data.authorId",
  allowDelete: "auth.userId == data.authorId",
});

const manifest = buildManifest({
  name: "notes",
  version: "0.1.0",
  entities: [Note],
  policies: [notePolicy],
  queries: [],
  actions: [],
  routes: [],
});

// Not a debug leftover: the CLI runs `bun run app.ts` and parses stdout as
// your manifest (see crates/cli/src/bun.rs). Deleting this line breaks every
// pylon command that reads your schema.
console.log(JSON.stringify(manifest, null, 2));
```

The trailing `console.log` is required. `pylon dev` captures stdout as the manifest.

## 4. Add a server function

Create `apps/api/functions/createNote.ts`:

```ts theme={null}
import { mutation, v } from "@pylonsync/functions";

export default mutation({
  // `auth: "guest"` lets the guest session from step 6 call this. The
  // default is `auth: "user"`, which rejects guest sessions — switch to it
  // once you have real accounts. Either way `ctx.auth.userId` is a stable
  // string, so it's safe to use as the author id.
  auth: "guest",
  args: {
    title: v.string(),
    body: v.string(),
  },
  async handler(ctx, args) {
    const id = await ctx.db.insert("Note", {
      title: args.title,
      body: args.body,
      authorId: ctx.auth.userId,
      updatedAt: new Date().toISOString(),
    });
    return { id };
  },
});
```

The filename becomes the RPC name. It is callable at `POST /api/fn/createNote`.

`pylon init` already adds `@pylonsync/sdk` + `@pylonsync/functions` to `apps/api/package.json`. If you skipped init or removed the deps, install them manually:

```bash theme={null}
cd apps/api && bun add @pylonsync/sdk @pylonsync/functions
```

## 5. Run the server

```bash theme={null}
cd apps/api
pylon dev
```

`pylon dev` does four things:

* auto-discovers `app.ts` (and `schema.ts` for legacy projects).
* watches `app.ts` and `functions/*.ts`.
* auto-migrates the database (SQLite at `.pylon/dev.db` by default, Postgres if `DATABASE_URL` is set).
* serves the API on `http://localhost:4321`.

Expected output:

```
✓ notes v0.1.0 — 1 entities, 0 queries, 0 actions, 1 policies, 0 routes
  Server:   http://localhost:4321
  Database: .pylon/dev.db
```

## 6. Call the API

Create a guest session:

```bash theme={null}
curl -X POST http://localhost:4321/api/auth/guest
# → { "token": "eyJ…", "user_id": "usr_01H…" }
```

Call the mutation (replace `TOKEN` with the value from above):

```bash theme={null}
curl -X POST http://localhost:4321/api/fn/createNote \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title":"First note","body":"hello from Pylon"}'
# → { "id": "not_01H…" }
```

List the rows:

```bash theme={null}
curl http://localhost:4321/api/entities/Note
# → [{ "id": "not_01H…", "title": "First note", ... }]
```

You now have a working Pylon backend with a typed schema, row-level policy, RPC function, and HTTP API.

## Next steps

> [card] [Entities](https://docs.pylonsync.com/concepts/entities.md)
>
> All the field types and index options.

> [card] [Policies](https://docs.pylonsync.com/concepts/policies.md)
>
> How row-level access rules work.

> [card] [Functions](https://docs.pylonsync.com/concepts/functions.md)
>
> Queries, mutations, actions, validators.

> [card] [Live queries](https://docs.pylonsync.com/concepts/live-queries.md)
>
> How `db.useQuery` stays in sync.

> [card] [Testing](https://docs.pylonsync.com/testing.md)
>
> `pylon test` — pure logic, components, functions over HTTP.

Want a full UI?

* **React**: the [chat example](https://github.com/pylonsync/pylon-examples/tree/main/chat) — schema, functions, Vite app, live subscriptions
* **Swift / SwiftUI**: the [swift-todo example](https://github.com/pylonsync/pylon-examples/tree/main/swift-todo) — minimal iOS/macOS app with optimistic mutations
* **React Native**: the [chat example](https://github.com/pylonsync/pylon-examples/tree/main/chat) ports cleanly to RN with the [`@pylonsync/react-native`](https://docs.pylonsync.com/clients/react-native) bridge

For all three, the same Pylon server backs the UI. The wire format is identical across platforms.

## Hand the rest to a coding agent

Once your backend runs, the rest happens in the shell. Stack0 Cloud has a [one-paste handoff flow](https://docs.pylonsync.com/operations/agent-handoff.md) that signs your coding agent (Claude Code, Codex, OpenCode, Cursor, Aider, grok build) into your account, installs the Pylon skill, and asks what to build. No token enters the chat history. From there the agent can use the [full CLI surface](https://docs.pylonsync.com/operations/cli.md): `pylon secrets`, `pylon logs tail`, `pylon deploy`, `pylon domains add`, `pylon db backup`, `pylon data list <Entity>`, etc.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.