# Installation & Getting Started

- **Section:** Getting Started
- **URL:** https://refast.fastapicloud.dev/docs/getting-started
- **Markdown:** https://refast.fastapicloud.dev/docs/getting-started.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/getting_started/installation.py
- **Applies to:** refast 0.12.2

## Prerequisites

- **Python 3.11+**
- Basic knowledge of Python and FastAPI is helpful but not required.

## Installation

Refast is available on PyPI and can be installed with `pip` or `uv`.

```bash
# Using pip
pip install refast

# Using uv (recommended)
uv pip install refast
```

## Your First App

Create a file named `app.py` with the following content:

```python
from fastapi import FastAPI
from refast import RefastApp, Context
from refast.components import Container, Heading, Text

# 1. Create the Refast app instance
ui = RefastApp(title="Hello Refast")

# 2. Define a page handler
@ui.page("/")
def home(ctx: Context):
    return Container(
        class_name="max-w-2xl mx-auto p-8 text-center",
        children=[
            Heading("Hello, Refast!", level=1, class_name="text-4xl mb-4"),
            Text("Your first Refast app is up and running."),
        ],
    )

# 3. Mount Refast to a FastAPI app
app = FastAPI()
app.include_router(ui.router)
```

## Run It

Refast apps are standard ASGI applications. You can run them with `uvicorn`:

```bash
uvicorn app:app --reload
```

Open [http://localhost:8000](http://localhost:8000) in your browser. You should see your "Hello, Refast!" message.

## Code Walkthrough

1. **`RefastApp`**: This is the main entry point. It handles page registration, event routing, and configuration.
2. **`@ui.page("/")`**: A decorator that registers a Python function as the handler for a specific route.
3. **`ctx: Context`**: The context object is passed to every page handler and callback. It provides access to state, session data, and methods like `navigate()` or `refresh()`.
4. **Components**: Functions like `Container`, `Heading`, and `Text` return Python objects representing UI elements. These are serialized to JSON and rendered by React on the client.
5. **`app.include_router(ui.router)`**: Refast integrates seamlessly into any FastAPI application by exposing a standard APIRouter.

## Debug Mode & Diagnostic Popups

You can enable debug mode by setting `debug=True` when initializing `RefastApp`:

```python
ui = RefastApp(title="Hello Refast", debug=True)
```

Enabling debug mode activates client-side developer diagnostics and error popups:
* **Real-time Diagnostic Popups**: When backend exceptions, callback errors, or Pydantic validation failures occur, Refast emits a `debug_event` that opens a diagnostic popup in the browser displaying error messages, full stack traces, and WebSocket event payloads.
* **Interactive Debug Panel**: Displays a floating developer panel in the browser, showing detailed real-time logs of all incoming and outgoing **WebSocket messages** (events, UI updates, state syncs, and actions).
* **Missing Component Popovers**: If the frontend encounters an unregistered component type, it renders a diagnostic popover button (e.g. `Unknown: component_name`) revealing the component's name, props, and serialized JSON tree.

## Next Steps

Now that you have Refast running, take the **Quick Tour** to build an interactive application.

- [Quick Tour](https://refast.fastapicloud.dev/docs/quick-tour) — Build a Todo app in 5 minutes
- [Architecture](https://refast.fastapicloud.dev/docs/architecture) — Understand how Refast works
- [Examples](https://refast.fastapicloud.dev/docs/examples) — See what's possible

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
