Skip to content
Example apps

Recipe Box

Recipe box API with ingredient counts and quick-meal search as computed columns and queries

One app.py with 1 table, 3 computed columns, 4 HTTP routes. Needs pixeltable[serve]>=0.7.14. Updated 2026-09-23.

app.py
"""Recipe Box API built with Pixeltable.
pxt schema update app.py recipes
pxt service run app.py recipes
"""
import pixeltable as pxt
import pixeltable.functions as pxtf
from pixeltable.serving import FastAPIRouter
from udfs import ingredient_count, teaser
# ---- tables ----
TableModel = pxt.model_base()
class Recipes(TableModel, name='recipes'):
id = pxt.Column(value=pxtf.uuid.uuid7(), primary_key=True)
title: pxt.String
ingredients: pxt.String
minutes: pxt.Int | None
notes: pxt.String | None
n_ingredients = ingredient_count(ingredients)
title_upper = pxtf.string.upper(title)
title_blurb = teaser(title, minutes)
# ---- queries ----
@pxt.query
def quick_recipes(max_minutes: int):
"""Recipes that fit a time budget, fastest first."""
return Recipes.where(Recipes.minutes <= max_minutes).select(
Recipes.id, Recipes.title_blurb, Recipes.n_ingredients
).order_by(Recipes.minutes)
# ---- routes ----
recipes_api = FastAPIRouter(name='recipes_api')
recipes_api.add_insert_route(
Recipes, path='/recipes',
inputs=[Recipes.title, Recipes.ingredients, Recipes.minutes, Recipes.notes],
outputs=[Recipes.id, Recipes.n_ingredients, Recipes.title_upper, Recipes.title_blurb],
)
recipes_api.add_update_route(
Recipes, path='/recipes/update',
inputs=[Recipes.title, Recipes.ingredients, Recipes.minutes, Recipes.notes],
outputs=[Recipes.id, Recipes.n_ingredients, Recipes.title_upper, Recipes.title_blurb],
)
recipes_api.add_compute_route(Recipes, path='/ingredient-count', inputs=[Recipes.ingredients],
outputs=[Recipes.n_ingredients])
recipes_api.add_query_route(path='/recipes/quick', query=quick_recipes, method='get')

Run it

Needs uv. The routes then answer on port 8000.

terminal
git clone https://github.com/pierrebrunelle/pixeltable-recipe-box &&
cd pixeltable-recipe-box &&
git checkout a71c1beccb19f13e563d4b6f9b58f130c3ac56d4 &&
uv sync &&
uv run pxt schema update app.py recipes &&
uv run python seed.py recipes &&
uv run pxt service run app.py recipes --port 8000