Description: This project uses EDAMAM's Nutrition Analysis API to collect data on 30 nutrients found in a sample recipe (sent to the API through a POST request). Information collected of each nutrient include their labels (descriptive names), quantities, and units. Collected data was saved to a CSV file.
Language(s): Python
Package(s): Requests, JSON, Pandas
Software: Jupyter Notebooks
Motivation: This project was created to demonstrate skills in collecting data from APIs that require authentication and POST requests.
The main file for this project is located in the root of this repository named EDAMAM API Data Collection.ipynb. If you have Jupyter Notebooks installed, you can download the .ipynb file and view it there. If not, you can view the project using Google Colaboratory here.
Note: Executing all cells in the project file will create a CSV file of collected data.
EDAMAM has several APIs that developers can use including a Food Database Lookup, Recipe Search, and Meal Recommendation Engine. A full list of the APIs they offer can be found in their API Developer Portal.
The API used in this project was the Nutrition Analysis API which takes in unstructured recipe text and returns information on the various nutrients contained in the food.
Documentation for the EDAMAM Nutrition Analysis API can be found here.
Note: EDAMAM requires developers to use their personal App IDs and App Keys received upon registration. There is a limit to how many requests can be made in a certain period of time. If you want to use EDAMAM's APIs yourself, please register and use your own ID and Key rather than using mine. Thank you.
Note: Data was collected on 12/28/21.
Python's Requests module was used to send a POST request to the EDAMAM Nutrition Analysis API. The POST request contained the required header, as well as a dictionary of parameters (app_id and app_key) needed for authentication.
Lastly, the request required a JSON of the recipe being submitted to the API. It was constructed in the following format:
The two components of the body JSON were a recipe title, and "unstructured text" containing all ingredients of the recipe with their respective quantities.
The POST request was sent to the API route and the JSON response sent back contained data on total nutrient quantities as well as nutrient quantites in relation to % Daily Value. For this project, data was collected on the total quantities of each nutrient.
Each nutrient in the JSON response had a label, quantity, and unit. A for-loop was used to collect these fields for all provided nutrients.
Python's Pandas module was used to compile the lists of data containing nutrient labels, quantities, and units into a Data Frame. The first few rows looked like this:
That data was then saved as a CSV file (see EDAMAM_API_Nutrient_Data.csv).