Skip to content

Input / Output

Recipe I/O

Recipe serialization (JSON / YAML) and scaling.

dict_to_recipe(data)

Build a :class:Recipe from a plain dictionary.

Parameters:

Name Type Description Default
data Dict[str, Any]

The dictionary data (e.g., loaded from JSON).

required

Returns:

Type Description
Recipe

The reconstructed Recipe object.

load_recipe(path)

Load a recipe from a JSON or YAML file.

Parameters:

Name Type Description Default
path Union[str, Path]

Path to the recipe file.

required

Returns:

Type Description
Recipe

The loaded recipe object.

Raises:

Type Description
FileNotFoundError

If the file does not exist.

JSONDecodeError

If JSON parsing fails.

YAMLError

If YAML parsing fails.

recipe_to_dict(recipe)

Convert a :class:Recipe to a plain dictionary.

Parameters:

Name Type Description Default
recipe Recipe

The recipe object to serialize.

required

Returns:

Type Description
Dict[str, Any]

A dictionary representation suitable for JSON/YAML serialization.

save_recipe(recipe, path, fmt=None)

Serialize a recipe to a JSON or YAML file.

Parameters:

Name Type Description Default
recipe Recipe

The recipe to save.

required
path Union[str, Path]

Destination file path.

required
fmt Optional[str]

Format ('json' or 'yaml'). If None, inferred from extension.

None

scale_recipe(recipe, target_oil_weight)

Return a new recipe scaled to target_oil_weight (total oils).

Because oils are stored as percentages the ratios stay the same — only the batch size changes. Additive amounts (absolute grams) are scaled proportionally; percentage-based additives scale automatically.

Parameters:

Name Type Description Default
recipe Recipe

The original recipe to scale.

required
target_oil_weight float

The new target total oil weight in grams.

required

Returns:

Type Description
Recipe

A new Recipe object with scaled amounts.

Export

Export a calculated recipe to Markdown.

export_markdown(recipe, result, path)

Write the recipe card to a Markdown file.

Parameters:

Name Type Description Default
recipe Recipe

The definition of the recipe.

required
result RecipeResult

The calculated results.

required
path Union[str, Path]

Destination file path.

required

render_markdown(recipe, result)

Render a recipe + result as a Markdown string.

Generates a printable recipe card including checks, warnings, and detailed ingredient tables.

Parameters:

Name Type Description Default
recipe Recipe

The definition of the recipe.

required
result RecipeResult

The calculated results of the recipe.

required

Returns:

Type Description
str

The complete Markdown document.