Blog · 22 November 2026

Build a food-recall allergen alert in Python

This page is for Wryborg, a brand of Wright Phi Capital LLC.

If you need to know when a U.S. food recall mentions peanut, milk, or another major allergen, you can poll the Wryborg Food Recall Monitor API and alert on records you have not already seen. This post builds a short Python script that does that, with a curl and Node.js aside.

The data is derived from official U.S. government records: FDA openFDA food enforcement reports and USDA FSIS recall notices. It may be delayed or incomplete and is not a safety guarantee. Always confirm the original notice (source_url). Allergen tags, product categories, and distribution states are derived during ingest and can be wrong.

Get a Food Recall Monitor key

Plans and quotas are on the Food Recall Monitor pricing page. A free tier is available. If you choose a paid plan, payment is handled by Stripe.

Sign up, verify your email, then pay with Stripe. Your API key, which starts with wrb_, is shown in your account. It is not emailed. Manage or cancel from your account.

Each Wryborg API is its own subscription and its own key. A Food Recall Monitor key returns 403 on the others.

export WRYBORG_API_KEY=wrb_your_key
python3 -m pip install requests

Docs: api.wryborg.com/v1/docs and openapi.json. Samples: github.com/wryborg/wryborg-api-examples. Postman: Wryborg APIs workspace.

What the API lets you filter

The list endpoint is GET https://api.wryborg.com/v1/recalls. Food is served at /v1 on api.wryborg.com; there is no /food prefix. Send the key in the X-API-Key header.

The allergen query parameter accepts the nine FDA major food allergens (FALCPA + FASTER Act): milk, egg, peanut, tree_nut, soy, wheat, fish, shellfish, and sesame. Values are case-insensitive. Spaces, hyphens, and a trailing plural are accepted (tree nut and peanuts both work). GET /allergens returns the same codes, a display name, and a recall_count for each.

There is no allergen=undeclared filter. That value returns 422 with error.code invalid_parameter and lists the nine allowed values. Many allergen recalls are labeling cases, and "undeclared" usually appears in reason (for example, undeclared allergen ingredient (Peanuts, Milk)). Filter those client-side after you fetch by allergen. Do not use q=undeclared as a stand-in: q searches firm, product, and reason, and it also matches undeclared drug ingredients.

Useful companions to allergen are state (a 2-letter code or full name; a state filter also returns NATIONWIDE recalls), date_from / date_to (report_date as YYYY-MM-DD), sort (default -report_date; also report_date, recall_initiation_date, -recall_initiation_date), limit (1–100, default 25), and offset. classification, status, source, brand, product_category, and q are in the OpenAPI file.

The corpus is refreshed about every six hours, so polling more often mostly repeats the same page and still counts against your monthly quota. A successful list, including an empty page, is one billed call. GET /health is public. GET /usage reports quota and does not consume a call. The free plan covers the last 12 months; if date_from is earlier than your plan window, the response adds warnings and an X-History-Clamped header. history_from is the earliest report_date your plan may read, or null when the plan has full history.

Food Recall Monitor does not allow arbitrary browser origins. Run this on a server or your laptop, not from a public web page.

The list response

A successful page includes total, limit, offset, plan, history_from, warnings, data, and disclaimer. Each recall includes provenance (source, source_url, retrieved_at, last_verified_at) plus fields such as firm, brand, product_description, product_category, allergens, classification, status, reason, and distribution_states.

Here is a shortened live response for allergen=peanut, fetched on 22 November 2026 (America/New_York). plan is a placeholder, and several fields are omitted. total will change as the corpus is refreshed.

{
  "total": 1195,
  "limit": 5,
  "offset": 0,
  "plan": "<your_plan>",
  "warnings": [],
  "data": [
    {
      "id": "fda-H-0112-2027",
      "source": "FDA",
      "source_url": "https://api.fda.gov/food/enforcement.json?search=recall_number:%22H-0112-2027%22",
      "report_date": "2026-10-28",
      "firm": "El Ruisenor De Mexico, Inc.",
      "product_description": "Butter Toffee Peanuts; packed in a clear plastic bag. 1lb, 5lb, 50lb unit size. No UPC",
      "allergens": ["milk", "peanut"],
      "classification": "Class III",
      "distribution_states": ["CA", "HI", "IL", "KS", "NV", "OR", "WA"],
      "reason": "undeclared allergen ingredient (Peanuts, Milk)"
    }
  ],
  "disclaimer": "Data is derived from official U.S. FDA (openFDA food enforcement reports) and USDA FSIS recall notices. It is provided as-is, may be delayed or incomplete, and is not a safety guarantee. Always confirm with the original notice (source_url)."
}

The script

Save the following as allergen_alerts.py. It requests recalls for one major allergen whose report_date falls in a rolling 30-day window, prints any id it has not stored, and writes those ids to seen-recall-ids.json.

#!/usr/bin/env python3
import json, os, sys
from datetime import date, timedelta
from pathlib import Path
import requests

API_KEY = os.environ.get("WRYBORG_API_KEY")
if not API_KEY:
    sys.exit("Set WRYBORG_API_KEY to your wrb_ key from https://wryborg.com/account/signup")

ALLERGEN = os.environ.get("ALLERGEN", "peanut")
DAYS = int(os.environ.get("LOOKBACK_DAYS", "30"))
STATE_FILE = Path("seen-recall-ids.json")
BASE = "https://api.wryborg.com/v1"

date_from = (date.today() - timedelta(days=DAYS)).isoformat()
response = requests.get(
    f"{BASE}/recalls",
    headers={"X-API-Key": API_KEY},
    params={
        "allergen": ALLERGEN,
        "date_from": date_from,
        "sort": "-report_date",
        "limit": 100,
    },
    timeout=30,
)
if not response.ok:
    err = response.json().get("error") if response.headers.get("content-type", "").startswith("application/json") else response.text
    sys.exit(f"HTTP {response.status_code}: {err}")

payload = response.json()
seen = set(json.loads(STATE_FILE.read_text())) if STATE_FILE.exists() else set()
new_rows = [row for row in payload["data"] if row["id"] not in seen]

if not new_rows:
    print(f"No new {ALLERGEN} recalls since {date_from} (checked {len(payload['data'])} row(s)).")
else:
    print(f"{len(new_rows)} new {ALLERGEN} recall(s) since {date_from}:\n")
    for recall in new_rows:
        print(f"New {recall.get('classification')} recall {recall['id']} ({recall['source']})")
        print(f"  Report date: {recall.get('report_date')}")
        print(f"  Firm: {recall.get('firm')}")
        print(f"  Product: {recall.get('product_description')}")
        print(f"  Allergens: {', '.join(recall.get('allergens') or [])}")
        print(f"  States: {', '.join(recall.get('distribution_states') or [])}")
        print(f"  Reason: {recall.get('reason')}")
        print(f"  Confirm: {recall['source_url']}\n")

for row in payload["data"]:
    seen.add(row["id"])
STATE_FILE.write_text(json.dumps(sorted(seen), indent=2) + "\n")

The first time you run it, every recall in the lookback window is new. Later runs only print unseen ids. This live 30-day run was from 22 November 2026 (America/New_York):

5 new peanut recall(s) since 2026-10-23:

New Class III recall fda-H-0112-2027 (FDA)
  Report date: 2026-10-28
  Firm: El Ruisenor De Mexico, Inc.
  Product: Butter Toffee Peanuts; packed in a clear plastic bag. 1lb, 5lb, 50lb unit size. No UPC
  Allergens: milk, peanut
  States: CA, HI, IL, KS, NV, OR, WA
  Reason: undeclared allergen ingredient (Peanuts, Milk)
  Confirm: https://api.fda.gov/food/enforcement.json?search=recall_number:%22H-0112-2027%22

python3 allergen_alerts.py
No new peanut recalls since 2026-10-23 (checked 5 row(s)).

Set ALLERGEN and LOOKBACK_DAYS to change the filter, or add a state query parameter (for example CA). To keep only undeclared-labeling cases, drop rows whose reason does not contain "undeclared" before you compare ids.

This watches report_date. It will not notice a field change on an older recall outside the window, and it is not a substitute for the official change feed. GET /recalls/changes lists created and updated recalls since a UTC timestamp (since is required) and pages with after_seq / next_seq. That endpoint requires Ultra or Mega; other plans get 403 with error.code plan_upgrade_required, and that 403 is not billed.

Optional Slack webhook

Inside the for recall in new_rows: loop, build text from the same fields you printed, then POST it to a Slack incoming webhook:

text = "\n".join(
    [
        f"New {recall.get('classification')} recall {recall['id']} ({recall['source']})",
        f"  Product: {recall.get('product_description')}",
        f"  Reason: {recall.get('reason')}",
        f"  Confirm: {recall['source_url']}",
    ]
)
webhook = os.environ.get("SLACK_WEBHOOK_URL")
if webhook:
    requests.post(webhook, json={"text": text}, timeout=30).raise_for_status()

Leave SLACK_WEBHOOK_URL unset to print only.

curl and JavaScript

curl -sS -H "X-API-Key: ${WRYBORG_API_KEY}" \
  "https://api.wryborg.com/v1/recalls?allergen=peanut&date_from=2026-10-23&sort=-report_date&limit=5"

Save this as list-recalls.mjs and run node list-recalls.mjs (Node 18 or later). Use .mjs so top-level await works.

const key = process.env.WRYBORG_API_KEY;
const url =
  "https://api.wryborg.com/v1/recalls?allergen=peanut&date_from=2026-10-23&sort=-report_date&limit=5";
const response = await fetch(url, { headers: { "X-API-Key": key } });
if (!response.ok) {
  console.error(response.status, await response.text());
  process.exit(1);
}
const page = await response.json();
for (const recall of page.data) {
  console.log(recall.id, recall.reason, recall.source_url);
}

This API does not allow arbitrary browser origins, so do not paste a key into a public web page.

Run it every six hours

A cron entry such as 5 */6 * * * is enough given the ingest cadence. Keep the seen-id file in a stable path so restarts do not replay the same alerts. Failed authentication is rate limited (30 failures per IP, and 300 across all IPs, each minute), so do not retry a bad key in a tight loop. Open source_url before you act, and check classification, status, distribution_states, and reason against the official notice. This script is not medical or legal advice, and it is not a food-safety guarantee.

Further reading

All posts