Grams-per-cup densities for 18 common baking ingredients, and exact cup / tablespoon / teaspoon / millilitre to gram conversion built on them. Standard library only.
import cup_density as cd
cd.to_grams(1, "cup", "all purpose flour") # 120.0
cd.to_grams(2, "tbsp", "butter") # 28.38
cd.from_grams(50, "tbsp", "granulated_sugar") # 4.0 tablespoons
cd.convert(1, "cup", "honey", "granulated_sugar") # 1.7 cups weigh the same
cd.ingredients("flour")python -m cup_density 3 tbsp cocoa_powder
python -m cup_density list- 1 US cup = 236.588 mL; 16 tablespoons per cup; 3 teaspoons per tablespoon.
- Water is 236.588 g per cup by definition of the millilitre-gram equivalence used here.
- The other 17 densities are the conventions used by the ingredientcalc D package (all-purpose flour 120 g, granulated sugar 200 g, butter 227 g, honey 340 g per cup, and so on). Flour, sugar and cocoa figures assume the ingredient is spooned into the cup and levelled; a dipped or packed cup holds noticeably more. Treat them as kitchen conventions, not lab measurements.
For a browser version with more ingredients that works in both directions, see Ingredient Calculator's grams-to-tablespoons converter.
Code MIT. The density table is CC0 / public domain.