Skip to main content

version license

Python library for Yummly API

NOTE: This library and its author are not affliated with Yummly.

Installation

pip install yummly

Dependencies

  • requests >= 1.1.0

Usage

Use yummly.Client to create a client object to interact with the Yummly API.

The client accepts api_id, api_key, and timeout as init parameters:

from yummly import Client

# default option values
TIMEOUT = 5.0
RETRIES = 0

client = Client(api_id=YOUR_API_ID, api_key=YOUR_API_KEY, timeout=TIMEOUT, retries=RETRIES)

search = client.search('green eggs and ham')
match = search.matches[0]

recipe = client.recipe(match.id)

Search Recipes

API endpoint: api.yummly.com/v1/api/recipes?<params>

Search for recipes meeting certain criteria:

results = yummly.search('bacon')

print('Total Matches:', results.totalMatchCount)
for match in results.matches:
    print('Recipe ID:', match.id)
    print('Recipe:', match.recipeName)
    print('Rating:', match.rating)
    print('Total Time (mins):', match.totalTimeInSeconds / 60.0)
    print('----------------------------------------------------')

Limit your results to a maximum:

# return the first 10 results
results = yummly.search('chicken marsala', maxResults=10)

Offset the results for pagination:

# return 2nd page of results
results = yummly.search('pulled pork', maxResults=10, start=10)

Provide search parameters:

params = {
    'q': 'pork chops',
    'start': 0,
    'maxResult': 40,
    'requirePicutres': True,
    'allowedIngredient[]': ['salt', 'pepper'],
    'excludedIngredient[]': ['cumin', 'paprika'],
    'maxTotalTimeInSeconds': 3600,
    'facetField[]': ['ingredient', 'diet'],
    'flavor.meaty.min': 0.5,
    'flavor.meaty.max': 1,
    'flavor.sweet.min': 0,
    'flavor.sweet.max': 0.5,
    'nutrition.FAT.min': 0,
    'nutrition.FAT.max': 15
}

results = yummly.search(**params)

For a full list of supported search parameters, see section The Search Recipes Call located at: https://developer.yummly.com/intro

Example search response: https://developer.yummly.com/wiki/search-recipes-response-sample

Get Recipe

API endpoint: api.yummly.com/v1/api/recipe/<recipe_id>

Fetch a recipe by its recipe ID:

recipe = yummly.recipe(recipe_id)

print('Recipe ID:', recipe.id)
print('Recipe:', recipe.name)
print('Rating:', recipe.rating)
print('Total Time:', recipe.totalTime)
print('Yields:', recipe.yields)
print('Ingredients:')
for ingred in recipe.ingredientLines:
    print(ingred)

Example recipe response: https://developer.yummly.com/wiki/get-recipe-response-sample

NOTE: Yummly’s Get-Recipe response includes yield as a field name. However, yield is a keyword in Python so this has been renamed to yields.

Search metadata

API endpoint: api.yummly.com/v1/api/metadata/<metadata_key>

Yummly provides a metadata endpoint that returns the possible values for allowed/excluded ingredient, diet, allergy, and other search parameters:

METADATA_KEYS = [
    'ingredient',
    'holiday',
    'diet',
    'allergy',
    'technique',
    'cuisine',
    'course',
    'source',
    'brand',
    'restriction'
]

ingredients = client.metadata('ingredient')
diets = client.metadata('diet')
sources = client.metadata('source')

NOTE: Yummly’s raw API returns this data as a JSONP response which yummly.py parses off and then converts to a list containing instances of the corresponding metadata class.

API Model Classes

All underlying API model classes are in yummly/models.py. The base class used for all models is a modified dict class with attribute-style access (i.e. both obj.foo and obj['foo'] are valid accessor methods).

A derived dict class was chosen to accommodate painless conversion to JSON which is a fairly common requirement when using yummly.py as an API proxy to feed your applications (e.g. a web app with yummly.py running on your server instead of directly using the Yummly API on the frontend).

Testing

Tests are located in tests/. They can be executed using pytest from the root directory using makefile or pytest.

# using makefile
make test

# using pytest directly
py.test yummly

NOTE: Running the test suite will use real API calls which will count against your call limit. Currently, 22 API calls are made when running the tests.

Test Config File

A test config file is required to run the tests. Create tests/config.json with the following properties:

{
    "api_id": "YOUR_API_ID",
    "api_key": "YOUR_API_KEY"
}

This file will be loaded automatically when the tests are run.

License

This software is licensed under the MIT License.

TODO

  • Provide helpers for complex search parameters like nutrition, flavors, and metadata

Release files for yummly 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yummly 0.5.0
File Size Uploaded
yummly-0.5.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yummly 0.5.0
File Interpreter ABI Platform
yummly-0.5.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.3 kB

Release files / yummly-0.5.0.tar.gz

Download URL yummly-0.5.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70c7583800670a77345efa517da335286dbaeeaaa1bf48bca13e76270674b9ac
BLAKE2b-256 checksum
How to use checksums
6163a42d6b89f475a6a41235b6600a15c302e72717704a10f0a2b948311f1c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / yummly-0.5.0-py2.py3-none-any.whl

Download URL yummly-0.5.0-py2.py3-none-any.whl
Size 11.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b7677348ff95191e2ff047113fef91c2a8e401e4ef1cd5cc4220367b0bcf2ff4
BLAKE2b-256 checksum
How to use checksums
4366a7112392f94826d3abb361ca3316585e9a6ccd445690e7e00b60e05d9dee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

1 release file

0.4.0

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page