DEV Community

Wryborg
Wryborg

Posted on

Check drug NDC codes against FDA recalls in Python

If you maintain a formulary, a pharmacy inventory app, or a medication list, you eventually need to answer a plain question: has the FDA recalled this product? The data is public in openFDA's enforcement reports, but drug and device records have different fields, and the NDC (National Drug Code) isn't always filled in. A recall can list product codes in an array, in the description text, or not at all.

This post uses the Drug & Device Recall Monitor API from Wryborg, which puts both kinds of recall into one schema and lets you filter on ndc directly. We'll check a short NDC list from Python.

The records are derived from FDA openFDA enforcement reports. They can be delayed or incomplete, and this is not medical or regulatory advice. Confirm the official record in source_url before you pull stock or tell a patient anything.

Get a key

Subscribe to the free Basic plan on the Drug & Device Recall Monitor listing on RapidAPI, then set up your environment:

export RAPIDAPI_KEY=YOUR_RAPIDAPI_KEY
python3 -m pip install requests
Enter fullscreen mode Exit fullscreen mode

Through RapidAPI the path is /recalls, with no /med/v1 prefix.

One NDC with curl

curl -s "https://drug-device-recall-monitor-api-by-wryborg.p.rapidapi.com/recalls?ndc=29300-359&limit=5" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: drug-device-recall-monitor-api-by-wryborg.p.rapidapi.com"
Enter fullscreen mode Exit fullscreen mode

The response has total, limit, offset, plan, history_from, warnings, data and disclaimer. Each recall in data has recall_number, category (drug or device), classification, status, firm, reason, reason_categories, code_info (lot and expiry), ndc (an array that may be empty) and source_url.

An NDC format gotcha

Send NDCs with hyphens, the way they're printed on the label. I tested three forms of the same product on December 5, 2026:

  • 29300-359 (the product code): 1 recall
  • 29300-359-16 (the package code): 1 recall
  • 29300035916 (11 digits, no hyphens): 0 recalls, with a normal 200 and no warning

A zero is not an error, so if your database stores NDCs without hyphens, restore the hyphens before you query. An empty page is still a billed request.

The script

import os
import time

import requests

HOST = "drug-device-recall-monitor-api-by-wryborg.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}

# NDCs exactly as printed on the label, with hyphens
INVENTORY = {
    "29300-359": "Amiodarone 200 mg",
    "00000-0000": "Placeholder NDC",
}

for ndc, label in INVENTORY.items():
    r = requests.get(
        f"https://{HOST}/recalls",
        headers=HEADERS,
        params={"ndc": ndc, "limit": 10},
        timeout=30,
    )
    r.raise_for_status()
    body = r.json()
    print(f"{ndc} ({label}): {body['total']} recall(s) since {body['history_from']}")
    for rec in body["data"]:
        print(f"  {rec['recall_number']}  {rec['classification']}  {rec['status']}  {rec['firm']}")
        print(f"  reason: {rec['reason']}")
        print(f"  lot: {rec['code_info']}")
        print(f"  {rec['source_url']}")
    time.sleep(1.1)  # stay under the free plan's rate limit
Enter fullscreen mode Exit fullscreen mode

Output from that run:

29300-359 (Amiodarone 200 mg): 1 recall(s) since 2025-12-06
  D-0183-2027  Class II  Ongoing  Unichem Pharmaceuticals USA Inc.
  reason: Presence of Foreign Substance
  lot: Lot #: ZMRH25054; Exp 07/31/2028
  https://api.fda.gov/drug/enforcement.json?search=recall_number:%22D-0183-2027%22
00000-0000 (Placeholder NDC): 0 recall(s) since 2025-12-06
Enter fullscreen mode Exit fullscreen mode

The history_from date matters. The free plan covers the last 12 months, so an older recall isn't returned. According to the API docs, fetching an older recall by id on the free plan returns a 403 with error.code plan_upgrade_required.

Matching is on the product, not the lot

A hit means the NDC appears in a recall. It doesn't mean your bottle is affected. Recalls often cover specific lots and expiry dates, so compare your lot to code_info or to the official notice. The source_url for these records is an openFDA query returning JSON.

Triage by severity

To see only the most serious recalls, filter on FDA's classification and a reason category:

curl -s "https://drug-device-recall-monitor-api-by-wryborg.p.rapidapi.com/recalls?classification=Class%20I&reason_category=contamination&limit=3" \
  -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
  -H "X-RapidAPI-Host: drug-device-recall-monitor-api-by-wryborg.p.rapidapi.com"
Enter fullscreen mode Exit fullscreen mode

On the same day this matched 121 recalls across drugs and devices in the 12-month window. Other reason_category values include cgmp_deviation, labeling, potency_dissolution, software and device_malfunction.

Try it

The free plan on RapidAPI includes 500 requests a month, enough to check a modest NDC list every day. Subscribe on the Drug & Device Recall Monitor listing.

More about the project, including the other Wryborg APIs, is at wryborg.com and in the API.market store.

Top comments (0)