# This file is a starting point for using the USDA FoodData Central API # Information on using it is here: https://fdc.nal.usda.gov/api-guide import requests # If you're going to use this for a project, you should request your own API key # at the website above. API_KEY = "xG4UErJJWEeCL6mpSlGnlQg90AQgruGdcnpeQoPx" # Search for a particular food: # Use %20 instead of a space, if needed foodquery = "whole%20milk" MAX_RESULTS = 2 url = f"https://api.nal.usda.gov/fdc/v1/foods/search?api_key={API_KEY}&query={foodquery}&pageSize={MAX_RESULTS}" # Print the complete URL; you should be able to paste it into your web browser and see the result print(url) # Make the API request response = requests.get(url) # Convert the JSON response to a Python dict/list structure blob = response.json() # Now extract information from the response, using appropriate indexing food = blob["foods"][0] print(food["description"])