Analysis API
The analysis module provides tools for analyzing nutrient content, comparing to dietary reference intakes, and calculating nutritional information for recipes.
Nutrient Analysis
- class usda_fdc.analysis.analysis.NutrientAnalysis(food, nutrients=<factory>, dri_type=DriType.RDA, gender=Gender.MALE, serving_size=100.0, calories_per_serving=0.0, macronutrient_distribution=<factory>)[source]
Bases:
objectRepresents the nutrient analysis of a food.
- Parameters:
- food
The food being analyzed.
- Type:
- nutrients
The nutrient values.
- Type:
- dri_type
The type of DRI used for comparison.
- gender
The gender used for DRI comparison.
- nutrients: Dict[str, NutrientValue]
- get_nutrient(nutrient_id)[source]
Get a nutrient value by ID.
- Parameters:
nutrient_id (str) – The nutrient ID.
- Returns:
The nutrient value if available, None otherwise.
- Return type:
NutrientValue | None
- get_nutrients_by_group(group)[source]
Get nutrient values by group.
- Parameters:
group (str) – The nutrient group.
- Returns:
A dictionary of nutrient IDs to nutrient values.
- Return type:
- get_macronutrients()[source]
Get macronutrient values.
- Returns:
A dictionary of nutrient IDs to nutrient values.
- Return type:
- get_vitamins()[source]
Get vitamin values.
- Returns:
A dictionary of nutrient IDs to nutrient values.
- Return type:
- get_minerals()[source]
Get mineral values.
- Returns:
A dictionary of nutrient IDs to nutrient values.
- Return type:
- get_amino_acids()[source]
Get amino acid values.
- Returns:
A dictionary of nutrient IDs to nutrient values.
- Return type:
- class usda_fdc.analysis.analysis.NutrientValue(nutrient, amount, unit, dri_percent=None)[source]
Bases:
objectRepresents a nutrient value with its properties.
- nutrient
The nutrient.
- usda_fdc.analysis.analysis.analyze_food(food, dri_type=DriType.RDA, gender=Gender.MALE, serving_size=100.0)[source]
Analyze the nutrient content of a food.
- Parameters:
- Returns:
A NutrientAnalysis object.
- Return type:
- usda_fdc.analysis.analysis.analyze_foods(foods, dri_type=DriType.RDA, gender=Gender.MALE, serving_sizes=None)[source]
Analyze the nutrient content of multiple foods.
- Parameters:
- Returns:
A list of NutrientAnalysis objects.
- Return type:
Nutrients
- class usda_fdc.analysis.nutrients.Nutrient(id, name, display_name, unit, group, usda_id=None)[source]
Bases:
objectRepresents a nutrient with its properties.
- Parameters:
- unit
The unit used to measure the nutrient.
- Type:
usda_fdc.analysis.units.Unit
- unit: Unit
- usda_fdc.analysis.nutrients.NUTRIENTS = Dict[str, Nutrient]
Dictionary of all nutrients by ID.
- usda_fdc.analysis.nutrients.NUTRIENT_GROUPS = Dict[str, List[str]]
Dictionary of nutrient groups to lists of nutrient IDs.
Dietary Reference Intakes
- class usda_fdc.analysis.dri.DietaryReferenceIntakes(dri_type=DriType.RDA, gender=Gender.MALE)[source]
Bases:
objectProvides access to Dietary Reference Intakes (DRI) data.
- data
The loaded DRI data.
- metadata
Metadata about the DRI data.
- class usda_fdc.analysis.dri.DriType(value)[source]
Bases:
EnumTypes of Dietary Reference Intakes.
- RDA = 'rda'
- AI = 'ai'
- UL = 'ul'
- class usda_fdc.analysis.dri.Gender(value)[source]
Bases:
EnumGender options for DRI data.
- MALE = 'male'
- FEMALE = 'female'
Recipe Analysis
- class usda_fdc.analysis.recipe.Recipe(name, ingredients=<factory>, servings=1, instructions=None, total_weight_g=0.0)[source]
Bases:
objectRepresents a recipe with ingredients.
- Parameters:
- ingredients
The ingredients in the recipe.
- Type:
- ingredients: List[Ingredient]
- add_ingredient(ingredient)[source]
Add an ingredient to the recipe.
- Parameters:
ingredient (Ingredient) – The ingredient to add.
- Return type:
None
- class usda_fdc.analysis.recipe.Ingredient(food, amount, unit, weight_g)[source]
Bases:
objectRepresents a recipe ingredient.
- food
The food.
- Type:
- class usda_fdc.analysis.recipe.RecipeAnalysis(recipe, total_analysis, per_serving_analysis, ingredient_analyses=<factory>)[source]
Bases:
objectRepresents the nutrient analysis of a recipe.
- Parameters:
recipe (Recipe) –
total_analysis (NutrientAnalysis) –
per_serving_analysis (NutrientAnalysis) –
ingredient_analyses (List[NutrientAnalysis]) –
- recipe
The recipe being analyzed.
- total_analysis
The nutrient analysis of the entire recipe.
- per_serving_analysis
The nutrient analysis per serving.
- ingredient_analyses
The nutrient analyses of each ingredient.
- Type:
- total_analysis: NutrientAnalysis
- per_serving_analysis: NutrientAnalysis
- ingredient_analyses: List[NutrientAnalysis]
- usda_fdc.analysis.recipe.parse_ingredient(text, client, default_unit='g')[source]
Parse an ingredient from text.
- Parameters:
- Returns:
An Ingredient object if parsing succeeds, None otherwise.
- Return type:
Ingredient | None
- usda_fdc.analysis.recipe.create_recipe(name, ingredient_texts, client, servings=1, instructions=None)[source]
Create a recipe from ingredient texts.
Visualization
- usda_fdc.analysis.visualization.generate_macronutrient_chart_data(analysis)[source]
Generate data for a macronutrient distribution chart.
- Parameters:
analysis (NutrientAnalysis) – The nutrient analysis.
- Returns:
A dictionary with chart data.
- Return type:
- usda_fdc.analysis.visualization.generate_dri_chart_data(analysis, nutrient_ids=None, min_percent=1.0)[source]
Generate data for a DRI percentage chart.
- usda_fdc.analysis.visualization.generate_nutrient_comparison_chart_data(analyses, nutrient_id)[source]
Generate data for a nutrient comparison chart.
- usda_fdc.analysis.visualization.generate_nutrient_radar_chart_data(analysis, nutrient_ids)[source]
Generate data for a nutrient radar chart.
- usda_fdc.analysis.visualization.generate_html_report(analysis)[source]
Generate an HTML report for a nutrient analysis.
- Parameters:
analysis (NutrientAnalysis) – The nutrient analysis.
- Returns:
An HTML string.
- Return type: