Parse recipes from web pages that use JSON-LD structured data and output Markdown, LaTeX, and PDF.
Project description
Recipy
Recipy extracts recipes from web pages using JSON-LD and converts them into Python objects. It also supports generating Markdown, LaTeX, and PDFs.
from recipy.microdata import recipe_from_url
url = "https://www.allrecipes.com/recipe/14231/guacamole/"
recipe = recipe_from_url(url)
if recipe:
print(recipe.model_dump())
Installation
Install via pip
pip install python-recipy
Install texlive
for PDF Generation
- Ubuntu 24.04
sudo apt update
sudo apt install texlive
- Fedora 40
sudo dnf install texlive
- Arch Linux
sudo pacman -S texlive-most
Examples
Load Recipe from JSON
from recipy.microdata import recipe_from_json
json_data = '''
{
"name": "Chocolate Cake",
"recipeIngredient": ["2 cups flour", "1 cup sugar", "1/2 cup cocoa powder"],
"recipeInstructions": [
{"@type": "HowToStep", "text": "Preheat the oven to 350°F (175°C)."},
{"@type": "HowToStep", "text": "Mix dry ingredients."},
{"@type": "HowToStep", "text": "Add wet ingredients and mix until smooth."},
{"@type": "HowToStep", "text": "Pour batter into a greased pan and bake for 30 minutes."}
]
}
'''
recipe = recipe_from_json(json_data)
if recipe:
print(recipe.model_dump())
Parse Recipe from Markdown
from recipy.markdown import recipe_from_markdown
markdown_content = """
# Chocolate Cake
A simple and delicious chocolate cake recipe.
## Ingredients
### For the Cake
* 2 cups flour
* 1 cup sugar
* 1/2 cup cocoa powder
### For the Frosting
* 1/2 cup butter
* 1/4 cup cocoa powder
* 2 cups powdered sugar
## Instructions
### Making the Cake
1. Preheat the oven to 350°F (175°C).
2. Mix dry ingredients.
3. Add wet ingredients and mix until smooth.
4. Pour batter into a greased pan and bake for 30 minutes.
### Making the Frosting
1. Melt the butter.
2. Stir in cocoa powder.
3. Gradually add powdered sugar until smooth.
## Notes
Let the cake cool completely before frosting.
"""
recipe = recipe_from_markdown(markdown_content)
if recipe:
print(recipe.model_dump())
Markdown Structure
- The recipe title must be an H1 (
# Title
). - Ingredients must be under an H2 heading
## Ingredients
, with optional H3 subheadings for ingredient groups. - Instructions must be under an H2 heading
## Instructions
, with optional H3 subheadings for instruction groups. - Notes can be included under an H2 heading
## Notes
.
Convert Recipe to PDF
from recipy.pdf import recipe_to_pdf
from recipy.models import Recipe, IngredientGroup, InstructionGroup
recipe = Recipe(
title="Chocolate Cake",
ingredient_groups=[
IngredientGroup(name=None, ingredients=["2 cups flour", "1 cup sugar"])
],
instruction_groups=[
InstructionGroup(name=None, instructions=["Mix ingredients", "Bake for 30 minutes"])
]
)
pdf_content = recipe_to_pdf(recipe)
with open("recipe.pdf", "wb") as f:
f.write(pdf_content)
Convert Recipe to LaTeX
from recipy.latex import recipe_to_latex
from recipy.models import Recipe, IngredientGroup, InstructionGroup
recipe = Recipe(
title="Chocolate Cake",
ingredient_groups=[
IngredientGroup(name=None, ingredients=["2 cups flour", "1 cup sugar"])
],
instruction_groups=[
InstructionGroup(name=None, instructions=["Mix ingredients", "Bake for 30 minutes"])
]
)
latex_content = recipe_to_latex(recipe)
print(latex_content)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_recipy-0.1.0.tar.gz
(10.6 kB
view details)
Built Distribution
File details
Details for the file python_recipy-0.1.0.tar.gz
.
File metadata
- Download URL: python_recipy-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 431387418ae17cbf31868b61424a690844d6ee274c25a3667ee1023b724785d6 |
|
MD5 | 1d3cec630fd0b204adebf01ecbdb4c32 |
|
BLAKE2b-256 | bbec0854337f884d3f1351e46c0485a90020db4b5060bedf086539e2d9388f12 |
File details
Details for the file python_recipy-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: python_recipy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 510d1843d37b558b4e0e48713b8ef2fb85781df362b2a1d317c696d8f0e93eb9 |
|
MD5 | ad8467c447daceecce5d6fc3228799fc |
|
BLAKE2b-256 | d79dc308b51403517bfd58c8b0f8bce0525613643013d23b4f140369a408c2e0 |