Article type: How-to guide (one task: FDA food recalls for undeclared allergens from the last 90 days, with the allergens named and the recall class, in a CSV)
Prerequisites: Python 3.9 or later with
requests(pip install requests). No API key or account: openFDA works without a key at low volumes. An Apify account only if you use the hosted version at the end.Tested on: 20 November 2026, against the live openFDA food enforcement API.
In the 90 days to 20 November, 112 of the 267 FDA food recall records gave an undeclared ingredient as the reason, most often an allergen such as wheat, tree nuts, soy or milk that the label didn't list. If you run food safety for a retailer, buy for a food business or write about recalls, you want those recalls in a table, with which allergen, how serious and when. The FDA publishes its weekly recall enforcement reports through openFDA, a free JSON API, so a short script can pull them, tag the allergens and save a CSV.
All the data in this post comes from one endpoint:
GET https://api.fda.gov/food/enforcement.json?search=...&limit=1000&skip=0
search takes field queries such as report_date:[20260822 TO 20261120] AND reason_for_recall:undeclared. The response has meta.results.total and up to 1,000 results, one per recalled product. Without a key, openFDA limits how many requests you can make per minute and per day; this script needs one request per 1,000 records.
How do I get FDA allergen recalls into a CSV?
Save this as fda_allergen_recalls.py and run python fda_allergen_recalls.py (or pass another number of days):
import csv
import re
import sys
import time
from collections import Counter
from datetime import date, timedelta
from urllib.robotparser import RobotFileParser
import requests
DAYS = int(sys.argv[1]) if len(sys.argv) > 1 else 90
API = "https://api.fda.gov/food/enforcement.json"
UA = "fda-allergen-recalls-tutorial/1.0 (python-requests)"
# The nine major US food allergens, and words that name them in recall reasons.
ALLERGENS = {
"milk": r"milk|dairy|whey|casein",
"egg": r"eggs?\b",
"peanut": r"peanuts?",
"tree nuts": r"tree nuts?|almonds?|walnuts?|cashews?|pecans?|pistachios?|hazelnuts?|macadamia|brazil nuts?|pine nuts?",
"wheat": r"wheat|gluten",
"soy": r"soy|soybeans?",
"sesame": r"sesame",
"fish": r"\bfish\b|anchov|tuna|salmon|cod\b|pollock",
"shellfish": r"shellfish|shrimp|crab|lobster|crustacean",
}
session = requests.Session()
session.headers["User-Agent"] = UA
# 1. robots.txt first (api.fda.gov has none, which means no restrictions).
robots = RobotFileParser("https://api.fda.gov/robots.txt")
robots.read()
if not robots.can_fetch(UA, API):
sys.exit("robots.txt disallows the API for this script")
# 2. Food enforcement reports from the last DAYS days whose reason mentions an undeclared ingredient.
end, start = date.today(), date.today() - timedelta(days=DAYS)
search = f"report_date:[{start:%Y%m%d} TO {end:%Y%m%d}] AND reason_for_recall:undeclared"
records, skip, total = [], 0, None
while total is None or skip < total:
r = session.get(API, params={"search": search, "limit": 1000, "skip": skip}, timeout=60)
if r.status_code == 404: # openFDA answers 404 when nothing matches
break
r.raise_for_status()
page = r.json()
total = page["meta"]["results"]["total"]
records += page["results"]
skip += len(page["results"])
time.sleep(1) # no key: stay well under openFDA's per-minute limit
print(f"{total or 0} food enforcement records, report dates {start} to {end}, reason mentions 'undeclared'; read {len(records)}")
# 3. One row per record, with the allergens its reason names.
rows = []
for rec in records:
reason = rec.get("reason_for_recall", "")
found = [name for name, pattern in ALLERGENS.items() if re.search(pattern, reason, re.I)]
rows.append({
"report_date": f"{rec['report_date'][:4]}-{rec['report_date'][4:6]}-{rec['report_date'][6:]}",
"recall_number": rec["recall_number"],
"event_id": rec.get("event_id", ""),
"classification": rec.get("classification", ""),
"status": rec.get("status", ""),
"allergens": "; ".join(found),
"state": rec.get("state", ""),
"distribution": rec.get("distribution_pattern", ""),
"product": rec.get("product_description", ""),
"reason": reason,
})
rows.sort(key=lambda r: (r["classification"], r["report_date"]), reverse=False)
out = f"fda_allergen_recalls_{end}.csv"
with open(out, "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=list(rows[0]))
w.writeheader()
w.writerows(rows)
print(f"wrote {len(rows)} rows to {out}")
# 4. What's in it.
print(f" {len({r['event_id'] for r in rows})} recall events (one event can cover several products)")
for c, n in sorted(Counter(r["classification"] for r in rows).items()):
print(f" {c:<12}{n:>5}")
print(f" {sum(not r['allergens'] for r in rows)} name none of the nine major allergens")
print(" allergens named most often:")
for name, n in Counter(a for r in rows for a in r["allergens"].split("; ") if a).most_common(9):
print(f" {name:<12}{n:>5}")
Output on 20 November 2026 (it took about 2 seconds):
112 food enforcement records, report dates 2026-08-22 to 2026-11-20, reason mentions 'undeclared'; read 112
wrote 112 rows to fda_allergen_recalls_2026-11-20.csv
36 recall events (one event can cover several products)
Class I 27
Class II 48
Class III 37
36 name none of the nine major allergens
allergens named most often:
wheat 24
tree nuts 19
soy 15
milk 12
sesame 11
peanut 8
egg 5
shellfish 4
fish 2
Some rows from fda_allergen_recalls_2026-11-20.csv (product, company and reason columns left out):
report_date,recall_number,classification,allergens,status
2026-09-02,H-1259-2026,Class I,peanut,Ongoing
2026-09-02,H-1301-2026,Class I,egg,Ongoing
2026-09-09,H-1329-2026,Class I,milk,Ongoing
2026-09-16,H-1330-2026,Class I,wheat,Ongoing
2026-10-21,H-0092-2027,Class I,shellfish,Ongoing
Why it's built this way:
-
robots.txtfirst.api.fda.govhas norobots.txt(it answers 404), which means no restrictions, but the script checks before reading. -
Let openFDA do the first filter. Searching
reason_for_recall:undeclaredwithin the date range returns 112 of the 267 food recall records in those 90 days, so there's far less to download and the pages stay small. - Tag allergens locally. The reason is free text written by the FDA, so the script matches words for the nine major US allergens and lists every one it finds. A reason that names two allergens counts for both.
-
Class I first. The CSV is sorted by
classification, and Class I is the FDA's most serious class, so the top rows matter most.
What should I check before I trust the list?
- The newest week is often empty. Every record in these 90 days had a Wednesday report date, and the newest was 11 November. A search for 12 to 20 November returned HTTP 404 "No matches found!". openFDA uses 404 for "zero results", so treat it as an empty list, not an error.
-
Report date isn't the recall date.
report_dateis when the recall appeared in the FDA's weekly report. For these 112 records, the gap fromrecall_initiation_datewas 65 days at the median (13 to 259 days). Filter onreport_datefor "new this week", but userecall_initiation_datefor when it started. -
One recall event can be many records. The 112 records came from 36 recall events (
event_id). One event had 61 records, one per product, with 5 in Class I, 26 in Class II and 30 in Class III. Count events, not rows, if you're counting recalls. - "Undeclared" isn't always a major allergen. 36 of the 112 reasons named none of the nine. 20 named food colours (FD&C Red, Yellow and so on) and 14 named sulfites, 5 of them both; 4 named the drug ingredients sildenafil and tadalafil, and 3 named sugar, aspartame, or salt, garlic and onions. 17 of the 36 called it an "undeclared allergen ingredient" and named the substance in brackets. Read the reason before you tell anyone it's a peanut recall.
- Search "undeclared", not "allergen". In the same 90 days, 72 reasons contained "allergen" and only 2 of those lacked "undeclared", while "undeclared" found 112.
-
Paging has hard limits.
limit=1001returned HTTP 400 ("Limit cannot exceed 1000 results"), andskip=26000returned HTTP 400 ("Skip value must 25000 or less"). For bigger pulls, use shorter date ranges.
To watch one allergen, add AND reason_for_recall:sesame to search. For drugs or medical devices, change food in the URL to drug or device.
The hosted version (Disclosure: we built this)
We built an Apify Actor, Product Recall API: EU Safety Gate, CPSC & FDA Recalls, that reads the same openFDA enforcement reports (food, drugs and medical devices) plus US CPSC recalls and EU Safety Gate alerts, in one schema. Keywords are searched in the product description, the recalling company and the reason, matched from the start of each word, and FDA classes map to one risk scale (Class I to serious, II to moderate, III to low) with the original wording kept. Barcodes match across UPC and EAN forms. With monitorMode on and a weekly schedule, each run returns only recalls it hasn't returned before. A source with nothing in range gets a free no_matches row, and requests to openFDA are paced at most once a second. Every FDA row carries openFDA's disclaimer.
What it doesn't do: it doesn't tag allergens for you (the reason text is in hazard, so filter on it), and it reads at most 2,000 records per FDA dataset per run outside monitor mode. FDA enforcement reports have no page per recall, so the official link is an openFDA query. Food alerts from other countries aren't included. It's pay per event; prices on the Actor's Pricing tab. For example (not run for this post):
{
"sources": ["US_FDA"],
"fdaProductTypes": ["food"],
"keywords": ["undeclared"],
"publishedWithinDays": 90,
"maxResults": 0
}
Data provided by the U.S. Food and Drug Administration (open.fda.gov), read 20 November 2026. Do not rely on openFDA to make decisions regarding medical care; treat all results as unvalidated. This post and the Actor are not affiliated with or endorsed by the FDA.
Your Evenings
Top comments (0)