Getting Started
Installation
kokage-ui requires Python 3.11+ and installs FastAPI automatically.
Optional Dependencies
pip install kokage-ui[sql] # SQLModel storage backend
pip install kokage-ui[markdown] # Markdown rendering
CLI Scaffolding
The fastest way to start a new project:
With CRUD template:
Add pages and models to an existing project:
uvx kokage-ui add page dashboard # Create pages/dashboard.py
uvx kokage-ui add crud Product # Create models/product.py
Your First App
Create a file called app.py:
from fastapi import FastAPI
from kokage_ui import KokageUI, Page, Card, H1, P, DaisyButton
app = FastAPI()
ui = KokageUI(app)
@ui.page("/")
def home():
return Page(
Card(
H1("Hello, kokage!"),
P("Your first kokage-ui application."),
actions=[DaisyButton("Get Started", color="primary")],
title="Welcome",
),
title="My First App",
)
Run It
Open http://localhost:8000 in your browser.
How It Works
-
KokageUI(app)— Wraps your FastAPI app. Mounts the bundled htmx.js and sets up static file serving. -
@ui.page("/")— Registers a route that returns a full HTML page. The decorated function should return aPage,Component, orstr. -
Page(...)— Generates a complete<!DOCTYPE html>document with htmx and DaisyUI/Tailwind CSS automatically loaded via CDN. -
Card(...),H1(...), etc. — Python classes that render to HTML. Children are positional args, attributes are keyword args.
Adding Interactivity
Use @ui.fragment() for htmx partial responses:
from kokage_ui import Div, DaisyButton
@ui.page("/")
def home():
return Page(
Div(
DaisyButton("Load Data", color="primary",
hx_get="/api/data", hx_target="#result"),
Div(id="result"),
),
title="Interactive App",
)
@ui.fragment("/api/data")
def load_data():
return Div("Data loaded via htmx!")
Clicking the button sends an htmx GET request to /api/data and inserts the response into #result.
Adding CRUD
Generate a full CRUD interface from a Pydantic model in one line:
from pydantic import BaseModel, Field
from kokage_ui import InMemoryStorage
class Todo(BaseModel):
id: str = ""
title: str = Field(min_length=1, max_length=200)
completed: bool = False
storage = InMemoryStorage(Todo)
ui.crud("/todos", model=Todo, storage=storage)
This creates list, create, detail, edit, and delete pages at /todos.
For database persistence, use SQLModelStorage:
Next Steps
- HTML Elements — Full component reference
- DaisyUI Components — Cards, alerts, navbars, and more
- Pages & Layout — Page structure and layouts
- CRUD — One-line CRUD generation
- DataGrid — Advanced sortable/filterable tables
- Admin Dashboard — Auto-generated admin panel
- Auth — Login, register, route protection