Documentation

Recipe Converter

class recipeconverter.RecipeConverter[source]

Bases: object

Convert ingredients and recipes from volumetric to mass units. Includes commonly used baking ingredients such as flour, sugar, etc.

OUNCE_TO_GRAM = 28.3495
POUND_TO_GRAM = 453.592
convert_recipe(recipe: str, multiplier=1.0) → str[source]

Convert a multi-line recipe from volumetric units to mass units

Parameters:
  • recipe (str) – Input recipe
  • multiplier (float, optional) – Recipe scale factor. Defaults to 1.0.
Returns:

Output recipe

Return type:

str

convert_recipe_from_url(url: str, multiplier=1.0) → tuple[source]

Convert recipe from URL, if supported

Parameters:
  • url (str) – Recipe URL
  • multiplier (float, optional) – Recipe scale factor. Defaults to 1.0.
Returns:

Output recipe tuple (recipe_scrapers.allrecipes.AllRecipes): Recipe scraper object

Return type:

tuple (str)

convert_volume_to_mass(line: str, multiplier=1.0) → str[source]

Convert ingredient line from volume to mass.

Also converts imperial weight to metric (ie. ounce or pounds)

Parameters:
  • line (str) – ie. “1 cup flour”
  • multiplier (float, optional) – Scale factor to multiply ingredient by
Returns:

Converted line, ie. “120.0 g flour

Return type:

str

static extract_from_line(line: str) → tuple[source]

Extract components from ingredient line

Parameters:line (str) – Input line, ie. “1 1/2 cup brown sugar”
Returns:Amount (ie. “1 1/2”) tuple (str): Unit (ie. “cup”), or “” if no units (ie. “1 banana”) tuple (str): Ingredient (ie. “brown sugar”)
Return type:tuple (str)
get_ingredient_conversion(ingredient: str, unit: str) → float[source]

Get conversion factor for the given ingredient

Parameters:
  • ingredient (str) – ie. Flour, sugar, etc.
  • unit (str) – Cup, tablespoon, or teaspoon
Returns:

Conversion factor from unit to grams

Return type:

float

recipeconverter.import_conversions(filename) → list[source]

Import ingredient conversion table

Returns:List of dicts (ingredient, cup, tablespoon, teaspoon)
Return type:list

Utilities

recipeconverter.utils.fraction_to_float(fraction: str) → float[source]

Convert string representation of a fraction to float.

Also supports unicode characters.

Parameters:fraction (str) – String representation of fraction, ie. “3/4”, “1 1/2”, etc.
Returns:Converted fraction
Return type:float
recipeconverter.utils.string_to_float(input: str) → float[source]

Convert string to float, if possible

Parameters:input (str) – Input string (ie. “1.5”)
Returns:Casted value (ie. 1.5), or None if conversion was not possible
Return type:float