Pyfood API
Pyfood is a simple Python package to process food, in different languages. At the core of Pyfood is the concept of a shelf
embedded in a given region
, a certain month_id
and optionally a source
language.
You can load a shelf embedded in France in January with the following Python snippet:
from pyfood.utils import Shelf
shelf = Shelf(region='France', month_id=0)
Pyfood supports the following language by default UN
(Universal), which includes DE
(German), EN
(English), ES
(Spanish). FR
(French), IT
(Italian), PT
(Portuguese). Pyfood works in the following region by default EU
(Europe), which includes France
, Germany
, Italy
, Portugal
, Spain
, United Kingdom
. Support for Canada
, Israel
, Japan
and Senegal
is also provided.
Pyfood Shelf
- class pyfood.utils.Shelf(region: str = 'EU', lang_source: str = 'un', month_id: int = 0)[source]
Shelf object embedded in a given region, month_id and optionally source language
- __init__(region: str = 'EU', lang_source: str = 'un', month_id: int = 0)[source]
Instantiates a shelf from a context (region, lang_source, month_id).
- get_food_info(food_name: str) Tuple [source]
Returns food id, taxon and seasonality.
- Parameters
food_name (str) – Food name in self.lang_source
- Returns
food_name (str) – Food name in self.lang_source
fid (float) – Food id in self.lang_source
taxon (str) – Food taxon (fruits: 001, vegetables: 002, …, mushrooms: 005)
score (float) – Food score in self.region and self.month_id
- get_seasonal_food(key: str = '001') List[str] [source]
Returns what food is in season
- Parameters
key (str) – taxon code (fruits: 001, vegetables: 002, …, mushrooms: 005)
- Returns
seasonal_food: Food in seasons in self.region, self.month_id and self.lang_source
- Return type
list
- process_ingredients(food_list: List[str], qty_list: Optional[List[str]] = None, unit_list: Optional[List[str]] = None, lang_dest: Optional[str] = None, revisit: bool = False, infer_nutri: bool = False, serving: int = 1)[source]
Labels a list of ingredients, e.g., from a recipe or a basket of food, and saves attributes / labels in self.tags
- Parameters
food_list (list) – List of food name in self.lang_source
qty_list (list) – List of quantities or None
unit_list (list) – List of units or None
lang_dest (str) – Target language, default self.lang_source
revisit (bool) – Infer Recipe2BetterRecipe, default False
infer_nutri (bool) – Infer nutrition scores, default False
serving (int) – Number of portions, default 1.
- Returns
tags – Extracted ingredients (ingredients_by_taxon, HS, revisited), predicted nutrition (allergies, energy, macro, minerals, vitamines) and labels (vege, vegan, seasonality)
- Return type
dict
- text2food(food_name: str = 'apple', threshold: float = 0.0) Tuple [source]
Retrieves ingredient from vocabulary using tdfidf and cosine_similarity. Returns food id, taxon and seasonality.
- Parameters
food_name (str) – (Noisy) food name in self.lang_source
- Returns
food_name (str) – Food name in self.lang_source
fid (float) – Food id in self.lang_source
taxon (str) – Food taxon (fruits: 001, vegetables: 002, …, mushrooms: 005)
score (float) – Food score in self.region and self.month_id