Check the setup
- Python 3.10 or newer
- A notebook environment such as Jupyter or Google Colab
- A data.gov API key saved in the FDC_API_KEY environment variable
USDA analytical and branded-food nutrient records for building nutrition comparisons, ingredient research, and food-search products.
From source to product signal
FoodData Central combines USDA analytical food records with other data types, including manufacturer-supplied branded records. Start with a bounded search of Foundation and SR Legacy foods and one nutrient reported per 100 grams. Normalize units and keep each record's data type visible before comparing values.
Install the packages, then run the notebook cell.
python -m pip install pandas requests
import os
import pandas as pd
import requests
response = requests.post(
"https://api.nal.usda.gov/fdc/v1/foods/search",
params={"api_key": os.environ["FDC_API_KEY"]},
json={
"query": "lentils",
"dataType": ["Foundation", "SR Legacy"],
"pageSize": 25,
"pageNumber": 1,
},
timeout=30,
)
response.raise_for_status()
rows = []
for food in response.json()["foods"]:
for nutrient in food.get("foodNutrients", []):
if nutrient.get("nutrientName") == "Protein":
rows.append({
"fdcId": food["fdcId"],
"description": food["description"],
"dataType": food["dataType"],
"protein_per_100g": nutrient.get("value"),
"unit": nutrient.get("unitName"),
})
protein = pd.DataFrame(rows)
protein["retrieved_at_utc"] = pd.Timestamp.now(tz="UTC")
print(protein.sort_values("protein_per_100g", ascending=False).head(20))Test a useful signal
Compare protein per 100 grams across a bounded set of USDA analytical lentil search results.
U.S. Department of Agriculture Agricultural Research Service is a government source. Last verified 2026-08-11. Temporal coverage: current releases with historical reference datasets.