Habit Tracker
Habit tracker API with streak labels as computed columns, deployable to Pixeltable Cloud
One app.py with 1 table, 3 computed columns, 4 HTTP routes. Needs pixeltable[serve]>=0.7.14. Updated 2026-09-24.
app.py
"""Habit Tracker API built with Pixeltable.pxt schema update app.py habitspxt service run app.py habits"""import pixeltable as pxtimport pixeltable.functions as pxtffrom pixeltable.serving import FastAPIRouterfrom udfs import habit_blurb, streak_label# ---- tables ----TableModel = pxt.model_base()class Habits(TableModel, name='habits'):id = pxt.Column(value=pxtf.uuid.uuid7(), primary_key=True)name: pxt.Stringcategory: pxt.Stringstreak_days: pxt.Int | Nonenotes: pxt.String | Nonelabel = streak_label(streak_days)name_upper = pxtf.string.upper(name)name_blurb = habit_blurb(name, category)# ---- queries ----@pxt.querydef by_category(category: str):"""Habits in a category, longest streak first."""return Habits.where(Habits.category == category).select(Habits.id, Habits.name, Habits.streak_days, Habits.label).order_by(Habits.streak_days, asc=False)# ---- routes ----habits_api = FastAPIRouter(name='habits_api')habits_api.add_insert_route(Habits, path='/habits',inputs=[Habits.name, Habits.category, Habits.streak_days, Habits.notes],outputs=[Habits.id, Habits.label, Habits.name_upper, Habits.name_blurb],)habits_api.add_update_route(Habits, path='/habits/update', inputs=[Habits.streak_days],outputs=[Habits.id, Habits.streak_days, Habits.label])habits_api.add_compute_route(Habits, path='/streak-label', inputs=[Habits.streak_days], outputs=[Habits.label])habits_api.add_query_route(path='/habits/by-category', query=by_category, method='get')
What app.py declares
Each row links to its line.
- runs on insert
- stored
- index
- route
serves habits_api
- POST/habitsinsert, habitstakes name, category, streak_days, notes; returns id, label, name_upper, name_blurbL39
- POST/habits/updateupdate, habitstakes streak_days; returns id, streak_days, labelL44
- POST/streak-labelcompute, habitstakes streak_days; returns labelL46
- GET/habits/by-categoryquery, by_categorytakes categoryL47
Run it
Needs uv. The routes then answer on port 8000.
terminal
git clone https://github.com/pierrebrunelle/pixeltable-habit-trackercd pixeltable-habit-trackeruv syncuv run pxt schema update app.py habitsuv run python seed.py habitsuv run pxt service run app.py habits --port 8000
Related apps
- Forge Heat CyclesForge heat-cycle registry API: B-tree indexes, chained risk UDFs, and parallel shop-floor writersShares: UDFs
- Climbing Route ToposClimbing-route topo registry API: photo uploads with thumbnails, grayscale copies, grade bands and index-backed crag lookupsShares: UDFs
- Warehouse Pick ListsWarehouse pick-list REST API: units, pick zones, waves and tote labels as incremental computed columns over Json order linesShares: UDFs