recipemd.data module

Defines the RecipeMD data structures, provides parser, serializer and recipe scaling functions.

class recipemd.data.RecipeParser[source]

Bases: object

current: Node = None
parents: List[Node] = None
parse(src)[source]
Parameters

src (str) –

Return type

Recipe

static parse_amount(amount_str)[source]
Parameters

amount_str (str) –

Return type

Amount

recipe: Optional[Recipe] = None
src: Optional[str] = None
class recipemd.data.RecipeSerializer[source]

Bases: object

serialize(recipe, *, rounding=None)[source]
Parameters
  • recipe (Recipe) –

  • rounding (Optional[int]) –

Return type

str

recipemd.data.multiply_recipe(recipe, multiplier)[source]

Multiplies a recipe by the given multiplier

Creates a new recipe where the factor of yield and ingredient is changed according to the multiplier

Parameters
  • recipe (Recipe) –

  • multiplier (Decimal) –

Return type

Recipe

recipemd.data.get_recipe_with_yield(recipe, required_yield)[source]

Scale the given recipe to a required yield

Raises StopIteration if no yield with a matching unit can be found.

Parameters
Return type

Recipe

class recipemd.data.Recipe(ingredients: List[ForwardRef('Ingredient')] = <factory>, ingredient_groups: List[ForwardRef('IngredientGroup')] = <factory>, title: Union[str, NoneType] = None, description: Union[str, NoneType] = None, yields: List[recipemd.data.Amount] = <factory>, tags: List[str] = <factory>, instructions: Union[str, NoneType] = None)[source]

Bases: recipemd.data.IngredientList

Parameters
  • ingredients (List[Ingredient]) –

  • ingredient_groups (List[IngredientGroup]) –

  • title (Optional[str]) –

  • description (Optional[str]) –

  • yields (List[Amount]) –

  • tags (List[str]) –

  • instructions (Optional[str]) –

description: Optional[str] = None
classmethod from_json(s, *, encoding=None, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)
Parameters
  • cls (Type[~A]) –

  • s (Union[str, bytes, bytearray]) –

Return type

~A

instructions: Optional[str] = None
tags: List[str] = None
title: Optional[str] = None
to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)
Parameters
  • skipkeys (bool) –

  • ensure_ascii (bool) –

  • check_circular (bool) –

  • allow_nan (bool) –

  • indent (Union[int, str, None]) –

  • separators (Optional[Tuple[str, str]]) –

  • default (Optional[Callable]) –

  • sort_keys (bool) –

Return type

str

yields: List[Amount] = None
class recipemd.data.Ingredient(name: str, amount: Union[recipemd.data.Amount, NoneType] = None, link: Union[str, NoneType] = None)[source]

Bases: object

Parameters
  • name (str) –

  • amount (Optional[Amount]) –

  • link (Optional[str]) –

amount: Optional[recipemd.data.Amount] = None
classmethod from_json(s, *, encoding=None, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)
Parameters
  • cls (Type[~A]) –

  • s (Union[str, bytes, bytearray]) –

Return type

~A

name: str = None
to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)
Parameters
  • skipkeys (bool) –

  • ensure_ascii (bool) –

  • check_circular (bool) –

  • allow_nan (bool) –

  • indent (Union[int, str, None]) –

  • separators (Optional[Tuple[str, str]]) –

  • default (Optional[Callable]) –

  • sort_keys (bool) –

Return type

str

class recipemd.data.IngredientGroup(ingredients: List[ForwardRef('Ingredient')] = <factory>, ingredient_groups: List[ForwardRef('IngredientGroup')] = <factory>, title: Union[str, NoneType] = None)[source]

Bases: recipemd.data.IngredientList

Parameters
classmethod from_json(s, *, encoding=None, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)
Parameters
  • cls (Type[~A]) –

  • s (Union[str, bytes, bytearray]) –

Return type

~A

title: Optional[str] = None
to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)
Parameters
  • skipkeys (bool) –

  • ensure_ascii (bool) –

  • check_circular (bool) –

  • allow_nan (bool) –

  • indent (Union[int, str, None]) –

  • separators (Optional[Tuple[str, str]]) –

  • default (Optional[Callable]) –

  • sort_keys (bool) –

Return type

str

class recipemd.data.Amount(factor: Union[decimal.Decimal, NoneType] = None, unit: Union[str, NoneType] = None)[source]

Bases: object

Parameters
  • factor (Optional[Decimal]) –

  • unit (Optional[str]) –

factor: Optional[decimal.Decimal] = None
classmethod from_json(s, *, encoding=None, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw)
Parameters
  • cls (Type[~A]) –

  • s (Union[str, bytes, bytearray]) –

Return type

~A

to_json(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, indent=None, separators=None, default=None, sort_keys=False, **kw)
Parameters
  • skipkeys (bool) –

  • ensure_ascii (bool) –

  • check_circular (bool) –

  • allow_nan (bool) –

  • indent (Union[int, str, None]) –

  • separators (Optional[Tuple[str, str]]) –

  • default (Optional[Callable]) –

  • sort_keys (bool) –

Return type

str

unit: Optional[str] = None