wright-core 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.pyo
4
+ dist/
5
+ site/
6
+ .venv/
7
+ .pytest_cache/
8
+ .ruff_cache/
9
+ .mypy_cache/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Will Dean
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,384 @@
1
+ Metadata-Version: 2.4
2
+ Name: wright-core
3
+ Version: 0.1.0
4
+ Summary: Multi-domain Python library for bill-of-materials planning, recipe costing, shopping list aggregation, unit conversion, allergen detection, and nutrition analysis. Works for food recipes, construction, brewing, and manufacturing.
5
+ Project-URL: Repository, https://github.com/3pm-baking/wright
6
+ Project-URL: Issues, https://github.com/3pm-baking/wright/issues
7
+ Project-URL: Documentation, https://wright.germanbakingasheville.com
8
+ Author-email: Will Dean <will@germanbakingasheville.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: allergen-detection,batch-production,bill-of-materials,bom,construction,costing,manufacturing,nutrition,planning,pricing,procurement,production,recipe,shopping-list,supply-chain,unit-conversion
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: pint>=0.25
24
+ Requires-Dist: pydantic<3.0.0,>=2.8.2
25
+ Requires-Dist: pyyaml>=6.0.3
26
+ Description-Content-Type: text/markdown
27
+
28
+ [![CI](https://github.com/3pm-baking/wright/actions/workflows/ci.yml/badge.svg)](https://github.com/3pm-baking/wright/actions/workflows/ci.yml)
29
+ [![docs](https://github.com/3pm-baking/wright/actions/workflows/docs.yml/badge.svg)](https://wright.germanbakingasheville.com)
30
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%20|%203.12%20|%203.13-blue)](https://www.python.org)
31
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
32
+
33
+ # wright
34
+
35
+ > **wright** /rīt/ — *noun*: a maker or builder. From Old English *wyrhta* (worker), as in *shipwright*, *wheelwright*, *playwright*. Here: a wright for your recipes, assemblies, and bills of materials.
36
+
37
+ <p align="center">
38
+ <a href="https://wright.germanbakingasheville.com">
39
+ <img src="https://raw.githubusercontent.com/3pm-baking/wright/main/docs/assets/wright-logo.png" width="200" alt="wright">
40
+ </a>
41
+ </p>
42
+
43
+ Pure Python library for production planning, cost calculation, shopping list
44
+ generation, allergen detection, nutrition analysis, and supply tracking.
45
+
46
+ Data-source agnostic. No I/O inside the core — models are plain Pydantic, the
47
+ `PurchasedItem` protocol accepts anything. Subclass to add your own fields.
48
+
49
+ **Domains**: food recipes, construction materials, brewing grain bills,
50
+ manufacturing BOMs — any domain where you need to aggregate named items with
51
+ quantities and units into a consolidated supply list with costs.
52
+
53
+ ```bash
54
+ pip install wright-core
55
+ ```
56
+
57
+ ## Recipes and ingredients
58
+
59
+ ```python
60
+ from wright import Recipe, Ingredient, RecipeComponent
61
+
62
+ cake = Recipe(
63
+ name="Lemon Cake",
64
+ components=[
65
+ RecipeComponent(
66
+ name="Batter",
67
+ ingredients=[
68
+ Ingredient(name="Flour", quantity=300, unit="g"),
69
+ Ingredient(name="Butter", quantity=200, unit="g"),
70
+ Ingredient(name="Lemon Juice", quantity=3, unit="tbsp"),
71
+ ],
72
+ )
73
+ ],
74
+ prep_time=30,
75
+ cook_time=45,
76
+ servings=12,
77
+ )
78
+
79
+ # Scale it
80
+ double_batch = cake * 2 # same as cake.size_up(2)
81
+ half_batch = cake * 0.5
82
+ ```
83
+
84
+ ## Costing
85
+
86
+ ```python
87
+ from decimal import Decimal
88
+ from wright import Purchase, calculate_recipe_cost
89
+
90
+ groceries = [
91
+ Purchase(name="Flour", quantity=1000, unit="g", price=Decimal("3.99")),
92
+ Purchase(name="Butter", quantity=500, unit="g", price=Decimal("5.49")),
93
+ Purchase(name="Lemon Juice", quantity=250, unit="ml", price=Decimal("1.99")),
94
+ ]
95
+
96
+ cost = calculate_recipe_cost(cake, groceries)
97
+ print(cost.total_cost_range.midpoint) # → 3.10
98
+ print(cost.cost_per_serving_range.midpoint) # → 0.26
99
+ ```
100
+
101
+ ## Planning a production run
102
+
103
+ ```python
104
+ from datetime import date
105
+ from wright import (
106
+ ProductionRun,
107
+ ProductionItem,
108
+ generate_shopping_list,
109
+ group_shopping_items,
110
+ calculate_shopping_list_cost,
111
+ analyze_menu,
112
+ DEFAULT_CATEGORY_RULES,
113
+ )
114
+
115
+ session = ProductionRun(
116
+ date=date(2026, 6, 20),
117
+ production=[ProductionItem(assembly="Lemon Cake", quantity=3)],
118
+ target_dates=[date(2026, 6, 20)],
119
+ )
120
+
121
+ shopping = generate_shopping_list(session, [cake])
122
+ ```
123
+
124
+ Group items by store aisle:
125
+
126
+ ```python
127
+ grouped = group_shopping_items(
128
+ shopping.all_items,
129
+ category_rules=DEFAULT_CATEGORY_RULES,
130
+ )
131
+ for group in grouped:
132
+ for item in group.items:
133
+ print(f" {item.name:<22s} {item.quantity:g} {item.unit}")
134
+ ```
135
+
136
+ ```
137
+ Dairy & Eggs ----------------------------------------------
138
+ Butter 600 g
139
+ Lemon Juice 9 tbsp
140
+
141
+ Dry Goods -------------------------------------------------
142
+ Flour 900 g
143
+ ```
144
+
145
+ Enrich with costs and analyze:
146
+
147
+ ```python
148
+ costs = calculate_shopping_list_cost(shopping, groceries)
149
+ total = sum(c.total_cost for c in costs if c.total_cost is not None)
150
+ # → Decimal('9.30')
151
+
152
+ menu = analyze_menu(
153
+ [ProductionItem(assembly="Lemon Cake", quantity=3)],
154
+ [cake],
155
+ groceries,
156
+ )
157
+ for item in menu.top_drivers:
158
+ print(f" {item.item.name}: ${item.total_cost} ({menu.cost_share(item):.0%})")
159
+ # → Butter: $3.29 (35%)
160
+ # → Flour: $2.39 (26%)
161
+ ```
162
+
163
+ [Full grocery list example](https://github.com/3pm-baking/wright/blob/9f4b0d1/examples/grocery_list.py) with 3 recipes, 16 grocery items, and formatted output.
164
+ [Meal prep planner](https://github.com/3pm-baking/wright/blob/e25becf/examples/meal_prep.py) — 5-day week, 2 cook sessions, macros per day.
165
+
166
+ ## Allergens and dietary badges
167
+
168
+ ```python
169
+ from wright import detect_allergens, detect_dietary_properties
170
+
171
+ allergens = detect_allergens(cake, allergy_map={"milk": "Dairy", "wheat": "Wheat"})
172
+ # → ["Dairy", "Gluten", "Eggs"]
173
+
174
+ badges = detect_dietary_properties(cake)
175
+ # → ["VEGAN", "DAIRY-FREE", "GLUTEN-FREE"]
176
+ ```
177
+
178
+ Supplement keyword detection with purchase data:
179
+
180
+ ```python
181
+ badges = detect_dietary_properties(
182
+ cake,
183
+ ingredient_properties=lambda ing: (
184
+ frozenset({"vegan", "gluten-free"}) if "gf" in ing.require_tags else frozenset()
185
+ ),
186
+ )
187
+ ```
188
+
189
+ ## Nutrition
190
+
191
+ ```python
192
+ from wright import calculate_recipe_macros, NutritionInfo, FoodRecord
193
+
194
+ registry = [
195
+ FoodRecord(
196
+ ingredient="Flour",
197
+ nutrition=NutritionInfo(protein_g=10, carbs_g=76, fat_g=1, kcal=364),
198
+ ),
199
+ FoodRecord(
200
+ ingredient="Butter",
201
+ nutrition=NutritionInfo(protein_g=0.9, carbs_g=0.1, fat_g=81, kcal=717),
202
+ ),
203
+ ]
204
+
205
+ macros = calculate_recipe_macros(cake, nutrition_registry=registry)
206
+ print(macros.per_serving.kcal)
207
+ ```
208
+
209
+ ## Supply tracking
210
+
211
+ ```python
212
+ from wright import Stock, SupplyItem
213
+
214
+ stock = Stock([SupplyItem(name="Flour", quantity=2000, unit="g")])
215
+ stock, deficit = stock.use([SupplyItem(name="Flour", quantity=900, unit="g")])
216
+ # deficit → [] — stock covers it
217
+ ```
218
+
219
+ ## Pricing
220
+
221
+ ```python
222
+ from wright import margin_price, multiplier_price
223
+
224
+ margin_price(Decimal("2.00"), 0.67) # → 6.06 (67% margin)
225
+ multiplier_price(Decimal("2.00"), 3) # → 6.00 (3× cost)
226
+ ```
227
+
228
+ ## Everything is injectable
229
+
230
+ ```python
231
+ from wright import chain, pinned_picker, cheapest_picker
232
+
233
+ # Compose pickers: pinned first, then cheapest
234
+ picker = chain(pinned_picker({"Butter": my_brand}), cheapest_picker)
235
+ items = calculate_shopping_list_cost(shopping, groceries, picker=picker)
236
+
237
+ # Custom volume display for metric users
238
+ shopping = generate_shopping_list(
239
+ session,
240
+ [cake],
241
+ display_normalizer=lambda q, u: ...,
242
+ )
243
+
244
+ # Custom name matcher
245
+ cost = calculate_recipe_cost(
246
+ cake,
247
+ groceries,
248
+ matcher=my_fuzzy_matcher,
249
+ )
250
+ ```
251
+
252
+ ## Non-food domains
253
+
254
+ ``Assembly``, ``Component``, and ``Material`` work for construction, brewing,
255
+ manufacturing, or any bill-of-materials domain. No dummy food fields needed:
256
+
257
+ ```python
258
+ from datetime import date
259
+ from decimal import Decimal
260
+ from wright import (
261
+ Assembly,
262
+ Component,
263
+ ProductionItem,
264
+ ProductionRun,
265
+ Purchase,
266
+ generate_shopping_list,
267
+ calculate_item_costs,
268
+ )
269
+
270
+ # ── Two home projects ──────────────────────────────────────────────────────
271
+
272
+ deck = Assembly(
273
+ name="Backyard Deck",
274
+ components=[
275
+ Component(
276
+ name="Framing",
277
+ materials=[
278
+ Material(name="2x6 Pressure-Treated", quantity=48, unit="ft"),
279
+ Material(name="Joist Hangers", quantity=16, unit="each"),
280
+ ],
281
+ ),
282
+ Component(
283
+ name="Surface",
284
+ materials=[
285
+ Material(name='5/4" Cedar Decking', quantity=160, unit="ft"),
286
+ Material(name='2" Stainless Screws', quantity=600, unit="each"),
287
+ ],
288
+ ),
289
+ ],
290
+ )
291
+
292
+ bed = Assembly(
293
+ name="Raised Garden Bed",
294
+ components=[
295
+ Component(
296
+ name="Frame",
297
+ materials=[
298
+ Material(name="2x8 Cedar", quantity=24, unit="ft"),
299
+ Material(name='3" Deck Screws', quantity=64, unit="each"),
300
+ ],
301
+ ),
302
+ ],
303
+ )
304
+
305
+ # ── Hardware store prices ──────────────────────────────────────────────────
306
+
307
+ prices = [
308
+ Purchase(
309
+ name="2x6 Pressure-Treated",
310
+ quantity=8,
311
+ unit="ft",
312
+ price=Decimal("12.97"),
313
+ store="Home Depot",
314
+ ),
315
+ Purchase(
316
+ name='2" Stainless Screws',
317
+ quantity=100,
318
+ unit="each",
319
+ price=Decimal("3.49"),
320
+ store="Home Depot",
321
+ ),
322
+ ]
323
+
324
+ # ── Cost one project ───────────────────────────────────────────────────────
325
+
326
+ deck_costs = calculate_item_costs(deck.all_materials, prices)
327
+ total = sum(c.total_cost for c in deck_costs if c.total_cost is not None)
328
+ print(f"Deck materials: ${total}")
329
+
330
+ # ── Plan a weekend build session ───────────────────────────────────────────
331
+
332
+ plan = ProductionRun(
333
+ date=date(2026, 6, 20),
334
+ production=[
335
+ ProductionItem(assembly="Backyard Deck", quantity=1),
336
+ ProductionItem(assembly="Raised Garden Bed", quantity=1),
337
+ ],
338
+ target_dates=[date(2026, 6, 20)],
339
+ )
340
+
341
+ shopping = generate_shopping_list(plan, [deck, bed])
342
+ for item in shopping.all_items:
343
+ print(f"{item.name}: {item.quantity:.0f} {item.unit}")
344
+
345
+ # ── Cross-reference with home inventory ───────────────────────────────────
346
+
347
+ from wright import Stock, SupplyItem
348
+
349
+ # What's already in the garage
350
+ garage_stock = Stock([
351
+ SupplyItem(name='2" Stainless Screws', quantity=100, unit="each"),
352
+ SupplyItem(name="Joist Hangers", quantity=8, unit="each"),
353
+ ])
354
+
355
+ # Deduct stock — get only what you still need to buy
356
+ garage_stock, buy_list = garage_stock.use(deck.all_materials)
357
+ for item in buy_list:
358
+ print(f"Buy: {item.name} — {item.quantity:.0f} {item.unit}")
359
+ # → Buy: 2x6 Pressure-Treated — 48 ft
360
+ # → Buy: Joist Hangers — 8 each (16 needed − 8 on hand)
361
+ # → Buy: 5/4" Cedar Decking — 160 ft
362
+ # → Buy: 2" Stainless Screws — 500 each (600 needed − 100 on hand)
363
+ ```
364
+
365
+ The same ``calculate_ingredient_cost()`` and ``Stock`` work across all domains.
366
+
367
+ ## Requirements
368
+
369
+ Python 3.11+. Dependencies: `pydantic>=2.8.2`, `pint>=0.25`, `pyyaml>=6.0.3`.
370
+
371
+ ## License
372
+
373
+ MIT. See [LICENSE](LICENSE).
374
+
375
+ <br>
376
+
377
+ <p align="center">
378
+ <img src="https://raw.githubusercontent.com/3pm-baking/wright/main/docs/assets/logo.png" width="120" alt="3pm German Baking">
379
+ </p>
380
+ <p align="center">
381
+ <a href="https://github.com/3pm-baking/wright">wright</a> is created and maintained by
382
+ <a href="https://germanbakingasheville.com">3pm German Baking, LLC</a>
383
+ a farmers market bakery in Asheville, NC.
384
+ </p>