Hello, nice to be back again, are you people ready for the next python project? In this latest project which will take maybe around half a month to complete, I will develop a python application that will show the nutrition and diet data for generic foods, packaged foods, and restaurant meals to the user. This application will use one of the free APIs from Rapid API to receive all the data that this project ever needs.

First of all, if you have not yet signed up for a free account at Rapid API, then just go ahead and do so. This site offers both the paid API and free API which the application developer can use in his or her own project. After you have signed up and signed into your account, search for this API: Edamam Food and Grocery Database.

About the food API:

Edamam provides access to a food and grocery database with over 750,000 basic foods, restaurant items, and consumer packaged foods – The foods in the Food API can be filtered by Diet and health filters generated by Edamam. All food database data is enriched with diet, allergy and health labeling, as calculated by Edamam based on the food’s ingredients. Peanut Free, Shellfish Free, Gluten-Free, Vegan and Vegetarian are some of the 20+ claims generated automatically. – For basic foods from the food database (flour, eggs, flour, etc.), Edamam returns data for calories, fats, carbohydrates, protein, cholesterol, sodium for a total of 28 nutrients. For UPC foods and fast foods data is return as listed on their nutrition label UPC or Barcode search – The Food Database API provides access to over 550,000 unique UPC codes. Low-cost solution – Edamam provides free Food API access with its basic plan for developers, startups and non-profits alike. – Enterprise customers are charged a very low monthly and per call fee based on usage. Custom packages are also available.

We will use the basic plan from the above-mentioned provider to develop our application for our own use, for those of you who are interested in the Enterprise version, you can ask the API provider for further information. I don’t know how much data will I get from the free version but we will see when we progress together!

In this chapter, I am just going to take it easy by following the python code provides by the API provider on their page to make a request and see what will I get from the API call. I have created a file to keep the API key and the API hostname so the program can read those two items later on.

import requests

# read the host and key from file then insert into a list
key_host = []
# since the file is there therefore no need to use the try and except block
f=open("key.txt", "r")
if f.mode == 'r':
    f_l = f.readlines()
    for line in f_l:
        key_host.append(line)
f.close()

url = "https://edamam-food-and-grocery-database.p.rapidapi.com/parser"

querystring = {"ingr":"orange"}

headers = {
    'x-rapidapi-host': key_host[0][:-1],
    'x-rapidapi-key': key_host[1]
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

Below is what we receive after the API call.

Part of the data we have received

I have also noticed that there are lots of URIs within the returning data that we can use to make further API call (perhaps?).

The above is just a simple program, I like to go from really easy to complicated, we build a little bit of stuff day by day, and we will get there slowly, don’t worry!

Click to rate this post!
[Total: 0 Average: 0]
Please follow and like us:

1 Comment

  1. Hey, you make a great job with https://kibiwebgeek.com. The article about Create a project which shows the nutrition and diet
    data for generic foods, packaged foods, and restaurant meals using python > Kibiwebgeek helps me and my friend Regena a lot in our Weight Loss.
    We have had a Custom Keto Diet plan from here: http://keto-diet.center You can have it too!
    Life is so beautiful, I am so happy! 🙂 Kiss you all!!!

Leave a Reply

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