The ingredient manipulation module provides tools for creating, modifying, and analyzing virtual ingredients in TomatoPy.
from tomatopy import Ingredient
# Create a basic ingredient
tomato = Ingredient(
name="tomato",
amount=1,
unit="whole",
properties={
"ripeness": 0.8,
"water_content": 0.95,
"sugar_content": 0.03
}
)
from tomatopy import Tomato, Garlic, Basil
# Create specialized ingredients
san_marzano = Tomato(
ripeness=0.8,
variety="San Marzano",
weight=150
)
fresh_garlic = Garlic(
cloves=3,
freshness=0.9,
size="medium"
)
sweet_basil = Basil(
leaves=10,
freshness=0.95,
variety="Genovese"
)
# Update ingredient properties
tomato.properties["ripeness"] = 0.9
tomato.properties["water_content"] = 0.92
# Batch update properties
tomato.update_properties({
"ripeness": 0.9,
"water_content": 0.92,
"sugar_content": 0.04
})
# Convert between units
tomato.convert_to_imperial() # Converts metric to imperial
tomato.convert_volume("ml", "cups") # Converts between volume units
# Get measurements in different units
print(tomato.get_weight("g")) # 150
print(tomato.get_weight("oz")) # 5.29
# Get physical properties
print(tomato.get_density()) # 1.02 g/ml
print(tomato.get_volume()) # 147 ml
print(tomato.get_surface_area()) # 150 cm²
# Analyze chemical properties
print(tomato.get_ph()) # 4.5
print(tomato.get_water_content()) # 0.95
print(tomato.get_sugar_content()) # 0.03
# Cut ingredients
diced_tomato = tomato.cut(
method="dice",
size="medium",
consistency="uniform"
)
# Chop ingredients
chopped_garlic = fresh_garlic.chop(
fineness="medium",
method="mince"
)
# Combine ingredients
mixture = tomato.combine(
fresh_garlic,
sweet_basil,
method="mix",
consistency="chunky"
)
# Check ingredient freshness
if tomato.is_fresh():
print("Ingredient is fresh")
else:
print("Ingredient may be past its prime")
# Get freshness score
freshness_score = tomato.get_freshness_score() # 0.85
# Assess ingredient quality
quality_report = tomato.assess_quality()
print(quality_report.overall_score) # 0.92
print(quality_report.recommendations) # ["Consider using within 2 days"]
try:
# Attempt invalid operation
tomato.cut(method="invalid_method")
except IngredientError as e:
print(f"Error: {e}") # "Invalid cutting method"
try:
# Attempt invalid property update
tomato.update_properties({"invalid_property": 1.0})
except PropertyError as e:
print(f"Error: {e}") # "Invalid property name"
Always Check Ingredient State
if tomato.state == "fresh":
# Proceed with operation
Use Type Hints
from typing import Dict, Any
def create_ingredient(
name: str,
properties: Dict[str, Any]
) -> Ingredient:
return Ingredient(name=name, properties=properties)
Handle Unit Conversions Carefully
# Always specify units explicitly
weight_grams = tomato.get_weight("g")
weight_ounces = tomato.get_weight("oz")
Ingredient
: Base class for all ingredients
Tomato
: Specialized tomato ingredient
Garlic
: Specialized garlic ingredient
Basil
: Specialized basil ingredient
__init__(name, amount, unit, properties)
update_properties(properties)
convert_to_imperial()
convert_volume(from_unit, to_unit)
get_density()
get_volume()
get_surface_area()
get_ph()
get_water_content()
get_sugar_content()
cut(method, size, consistency)
chop(fineness, method)
combine(*ingredients, method, consistency)
is_fresh()
get_freshness_score()
assess_quality()
Cooking Operations - Learn about cooking methods
Pizza Creation System - Create delicious pizzas
API Reference - Explore the full API