Ayten Yesim Semchenko, Ph.D.

Behavioral Statistician/Researcher

Menu
  • About me
  • Academic Publications
  • Education
  • Games
  • Python and Bash Diaries
  • Contact
Menu

Getting a nutrition analysis via EDAMAM’s API

Posted on April 2, 2022April 2, 2022 by Yesim Semchenko

Hello!

I recently came across EDAMAM and found out that it offers a free API for developers (not unlimited though) for nutritional analysis! After signing up, you create an app, and get an app id and app key. By using those along with the endpoint, it is possible to find out the nutritional analysis of what you eat. Yes, there are plenty of apps outside allowing you to do that, so this is just one of the options:)

APP_ID = ' '
APP_KEY = ' '

api_endpoint = 'https://api.edamam.com/api/nutrition-details'
url = api_endpoint + '?app_id=' + APP_ID + '&app_key=' + APP_KEY

headers = {'Content-Type' : 'application/json'}

For example, let us try an almond milk recipe (which I just made up):

recipe = {'title': 'Almond Milk',
         'ingr': ['50g raw almonds', '100ml water', '3g sea salt']}

r = requests.post(url, headers = headers, json = recipe)

To see all the keys in the resulting json:

almondmilk_info.keys()

The output:

dict_keys(['uri', 'yield', 'calories', 'totalWeight', 'dietLabels', 
'healthLabels', 'cautions', 'totalNutrients', 'totalDaily', 'totalNutrientsKCal'])

We see that one of the keys is totalNutrients which I find interesting. Now, I will put that into a data frame and transpose it to make it more readable.

almondmilk_nutr = pd.DataFrame(almondmilk_info['totalNutrients']).transpose()
almondmilk_nutr

Here is how the output looks like:

We can also check the healthLabels key:

almondmilk_nutr_health = pd.DataFrame(almondmilk_info['healthLabels'])
almondmilk_nutr_health.columns = ['health_labels']
almondmilk_nutr_health

The resulting data frame:

Have fun!

Note: I have no affiliation with this website, I just use their free API very happily

Category: Uncategorized

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • October 2022 (1)
  • May 2022 (1)
  • April 2022 (1)
  • December 2021 (1)
  • September 2021 (2)
  • December 2020 (1)
  • June 2020 (1)
  • October 2019 (2)
  • August 2019 (1)
  • July 2019 (3)
  • June 2019 (3)
© 2025 Ayten Yesim Semchenko, Ph.D. | Powered by Minimalist Blog WordPress Theme