Skip to content

API reference

Everything listed here is re-exported from the top-level cooklang package, so from cooklang import parse, Recipe works regardless of which submodule a name is defined in. The submodule pages below exist to group the API, not to describe an import path you have to use.

The whole surface at a glance

Group Names
Parsing parse, combine_ingredients, ParseError
Recipe model Recipe, Section, Step, Note, Block, TextItem, IngredientRef, CookwareRef, TimerRef, Item, Ingredient, Cookware, Timer, Quantity, Range, NameAndUrl, RecipeTime
Aisle configuration parse_aisle_config, AisleConfig, AisleCategory, AisleIngredient
Shopping lists parse_shopping_list, ShoppingList, RecipeItem, IngredientItem, ShoppingItem, ShoppingListError
Checked log parse_checked_log, checked_names, compact_checked_log, CheckEntry
Value helpers parse_value, format_value
Errors CooklangError, the base of ParseError and ShoppingListError

Every error raised about the input is a CooklangError, and so a ValueError. Passing an argument of the wrong type raises a plain TypeError instead, such as text must be str, not NoneType, because that is a bug in the calling code rather than bad input.

What each function gives you back

Call Returns
parse(text, *, scale=1.0) Recipe
combine_ingredients(ingredients, *, indices=None, aisle=None) dict[str, tuple[Quantity, ...]]
parse_aisle_config(text) AisleConfig
AisleConfig.categories tuple[AisleCategory, ...]
AisleConfig.category_for(name) str | None
AisleConfig.common_name_for(name) str
AisleConfig.group_by_category(names) dict[str | None, tuple[str, ...]]
AisleConfig(text), AisleConfig.from_text(text) AisleConfig
AisleConfig.apply_common_names(totals: Mapping[str, Iterable[Quantity]]) dict[str, tuple[Quantity, ...]]
parse_shopping_list(text) ShoppingList
ShoppingList.to_text() str
parse_checked_log(text) tuple[CheckEntry, ...]
checked_names(entries) tuple[str, ...]
compact_checked_log(entries, current_ingredients) tuple[CheckEntry, ...]
parse_value(text) int | float | str |Range
format_value(value) str

Package metadata

Python bindings for the official Cooklang parser.

This package wraps cooklang-rs, the reference Rust implementation of Cooklang, through bindings generated with UniFFI. It contains no parser logic of its own.

>>> import cooklang
>>> recipe = cooklang.parse("Chop the @onion{1}.")
>>> recipe.steps[0].text
'Chop the onion.'
>>> recipe.ingredients[0].name
'onion'

cooklang.__version__ is the version of these bindings. cooklang.UPSTREAM_VERSION is the cooklang-rs release they were generated from — see Relationship to cooklang-rs.

>>> import cooklang
>>> isinstance(cooklang.__version__, str)
True
>>> cooklang.UPSTREAM_VERSION
'0.18.7'