# fhadmin


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

A lightweight, customizable admin panel for FastHTML applications with
SQLite databases.

## Features

- 🔐 Simple password authentication
- 📊 Table browser with card-based overview
- 🔍 Full-text search across text columns
- ✏️ Inline cell editing
- ➕ Create new records via modal
- 🗑️ Delete records
- 💻 SQL console for custom queries
- 📄 Pagination with smart page buttons
- 🎨 Beautiful UI with DaisyUI/Tailwind

## Installation

``` bash
pip install fhadmin
```

## Quick Start

``` python
from fasthtml.common import *
from fhadmin.core import AdminConfig, create_admin
from fastlite import database

# Create your main app
app = FastHTML()

# Configure and mount the admin panel
cfg = AdminConfig(db_path="data/mydata.sqlite", password="secret")
admin_app = create_admin(cfg)
app.mount("/admin", admin_app)
```

Visit `/admin/login` to access the admin panel.

## Configuration

The
[`AdminConfig`](https://vacmar01.github.io/fhadmin/core.html#adminconfig)
dataclass accepts:

| Parameter  | Type          | Default      | Description                  |
|------------|---------------|--------------|------------------------------|
| `db_path`  | `str \| Path` | *required*   | Path to SQLite database file |
| `password` | `str`         | `"admin123"` | Admin login password         |

## How It Works

fhadmin uses a configuration-based architecture that stores settings in
`app.state.cfg`. Routes read the configuration at request time, making
it:

- **Notebook-friendly** — Rerun any route cell without side effects
- **Easy to debug** — Routes are plain functions, no closures
- **Flexible** — Change database or password at runtime if needed

## Routes

| Route | Method | Description |
|----|----|----|
| `/login` | GET/POST | Authentication |
| `/logout` | POST | End session |
| `/tables` | GET | Table overview cards |
| `/tables/{tbl}` | GET | Browse table with search & pagination |
| `/tables/{tbl}/new` | GET/POST | Create new record |
| `/tables/{tbl}/{pk}` | DELETE | Delete record |
| `/tables/{tbl}/{pk}/edit/{col}` | GET/PUT | Inline cell editing |
| `/tables/{tbl}/sql` | POST | Execute custom SQL |

## Requirements

- Python 3.10+
- fasthtml
- fastlite
- fhdaisy
- fh-heroicons

## License

MIT
