Add FDA product details to NDCs in Python
Enrich an NDC-coded inventory with product names, labelers and dosage forms using the FDA NDC reference.
The example and its inputs
Suppose your inventory contains drug package NDCs and quantities, but no consistent product names. You want to add names, labelers and dosage forms so an analyst can review the inventory and organize a report.
input.csv contains three fictional inventory lines, repeated in the inventory list in the Python code below. The line IDs and quantities are invented to demonstrate enrichment; the codes identify real package records in the reference. Two use FDA hyphenated formatting and one uses an 11-digit billing representation. The input CSV is optional because the code includes the inventory.
products.csv and packages.csv are small, unchanged selections from the paid FDA NDC Product & Package Reference. The package table connects the NDC to a product_id; the product table supplies the attributes. Both samples retain all the columns of their complete tables.
Download the product samples
Use a separate working folder for this example and save both CSVs there.
The full download also includes ingredients and a normalized NDC index. This example needs only the product and package tables because the task is to add product attributes.
Code example
Run this in one Jupyter cell, an IPython session, or a Python script. It uses Python’s standard library. It converts supported NDC formats to an 11-digit matching key, finds the associated product, and prints its name, labeler and dosage form alongside each inventory line.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
import csv
import re
from collections import defaultdict
# Fictional inventory lines and quantities, also provided in input.csv.
inventory = [
{"line_id": "L1", "ndc": "0002-0152-01", "units": 10},
{"line_id": "L2", "ndc": "0002-0213-01", "units": 8},
{"line_id": "L3", "ndc": "50090000500", "units": 12},
]
def ndc11(value):
"""Normalize explicit billing NDCs or supported hyphenated package codes."""
if not isinstance(value, str):
return ""
value = value.strip()
if re.fullmatch(r"[0-9]{11}", value):
return value
parts = value.split("-")
if (tuple(map(len, parts)) in {(4, 4, 2), (5, 3, 2), (5, 4, 1), (5, 4, 2)}
and all(re.fullmatch(r"[0-9]+", part) for part in parts)):
return "".join(part.zfill(width) for part, width in zip(parts, (5, 4, 2)))
return ""
with open("products.csv", newline="", encoding="utf-8-sig") as f:
products = list(csv.DictReader(f))
with open("packages.csv", newline="", encoding="utf-8-sig") as f:
packages = list(csv.DictReader(f))
by_id = {row["product_id"]: row for row in products}
if len(by_id) != len(products) or "" in by_id:
raise ValueError("Product IDs must be unique and nonblank")
by_ndc = defaultdict(set)
for row in packages:
if row["product_id"] not in by_id:
raise ValueError("Package points to a missing product")
code = ndc11(row["package_ndc"])
if code:
by_ndc[code].add(row["product_id"])
results = []
for row in inventory:
code = ndc11(row["ndc"])
ids = sorted(by_ndc.get(code, set()))
product = by_id[ids[0]] if len(ids) == 1 else None
results.append({
**row,
"ndc11": code,
"match_status": "unsupported_or_missing" if not code else
"not_in_reference" if not ids else
"ambiguous_product" if len(ids) > 1 else "matched",
"brand_name": product["brand_name"] if product else "",
"generic_name": product["generic_name"] if product else "",
"labeler_name": product["labeler_name"] if product else "",
"dosage_form": product["dosage_form"] if product else "",
})
for row in results:
name = row["brand_name"] or row["generic_name"] or "—"
print(f'{row["line_id"]} | {row["ndc"]} | {row["units"]} units | {row["match_status"]}')
print(f' {name} | {row["labeler_name"]} | {row["dosage_form"]}')
Analysis of the output
L1 | 0002-0152-01 | 10 units | matched
Zepbound | Eli Lilly and Company | INJECTION, SOLUTION
L2 | 0002-0213-01 | 8 units | matched
Humulin R | Eli Lilly and Company | INJECTION, SOLUTION
L3 | 50090000500 | 12 units | matched
TYLENOL EXTRA STRENGTH | A-S Medication Solutions | TABLET, FILM COATED
The first two lines receive Zepbound and Humulin R product attributes from Eli Lilly and Company. The third receives a Tylenol Extra Strength record labeled by A-S Medication Solutions. The reference preserves the source’s capitalization. labeler_name identifies the listed labeler; it should not be assumed to name the original manufacturer.
The results list retains each NDC and quantity and adds separate brand_name, generic_name, labeler_name and dosage_form fields. These can populate a readable inventory or support grouping by dosage form. The printed name prefers the brand name and falls back to the generic name.
The third input, 50090000500, matches the source package code 50090-0005-0 after padding its final segment. The code accepts explicit 11-digit values and the supported hyphenated patterns; it does not guess the boundaries of an unhyphenated 10-digit code. Keep NDCs as text throughout import.
If your data produces multiple candidate products, the example retains the inventory line with ambiguous_product and leaves its attributes blank for review. Repeated package entries pointing to the same product can supply its product attributes, but this code does not select a package description or marketing date. Missing and unsupported identifiers also remain visible. not_in_reference describes the file you supplied, so use the full reference when evaluating your own coverage.
Using the full dataset
Replace the two sample CSVs with products.csv and packages.csv from the purchased ZIP, or change the two paths to their extracted locations. Replace the inventory list with your records, or load a CSV:
with open("my-inventory.csv", newline="", encoding="utf-8-sig") as f:
inventory = list(csv.DictReader(f))
Use line_id, ndc and units columns, or adjust those names in the example. Insert the loading lines where the example inventory appears. The CSV reader preserves identifier strings; convert quantities separately if you plan to calculate totals.
The full reference contains 138,339 product records, 256,752 package entries and 222,261 ingredient entries from the retained FDA snapshot. It includes a normalized index, field dictionaries, a quality report and a fuller join.py helper with ingredient counts and package-detail statuses. Use product_id when joining the related tables; a product NDC is not a unique product-record key.
Sources and versions
The retained FDA NDC directory source edition is 2026-10-09. The ACD package was produced on 2026-10-13. This guide uses that existing release; it does not announce a new FDA source edition.
Directory inclusion does not establish FDA approval or current availability. This reference supports source-record enrichment, not clinical decisions or historical transaction matching. For therapeutic classifications, see the separate NDC → ATC guide.
Example checked October 15, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.