pip install nutritionix-client==1.0.0.dev1
# import inside your project
from nutritionix.nutritionix import NutritionixClient
nutritionix = NutritionixClient(
application_id='YOUR_APP_ID',
api_key='YOUR_API_KEY',
# debug=True, # defaults to False
)
"""
This will perform a search. The object passed into this function
can contain all the perameters the API accepts in the `POST /v2/search` endpoint
"""
nutritionix.search(q='salad', limit=10, offset=0, search_nutrient='calories')
"""
This will perform a search. The object passed into this function
can contain all the perameters the API accepts in the `GET /v2/search/brands` endpoint
type: (1:restaurant, 2:cpg, 3:usda/nutritionix) defaults to undefined
"""
nutritionix.brand_search(q='just salad', limit=10, offset=0, type=1)
# this will locate a brand by its id
nutritionix.brand(id='bV')
# this will locate an item by its id or by a search `resource_id`
nutritionix.item(id='zgcjnYV')
"""
The natural endpoint allows you to translate plain text into a full spectrum analysis.
gram_weight: An {Integer} that will be used as a multiplier when calculating `total.nutrients`
"""
ingredients = """
1 tbsp sugar
16 fl oz water
1/2 lemon
"""
nutritionix.natural(q=ingredients, gram_weight=20)
#allow users the convenience of "as you type" suggestions.
nutritionix.autocomplete(q='greek y')