On this page
Beginner capstone๏
๐ข Beginner ยท Lesson 40
Build and use a small application across separate Python modules: ordinary objects, one bootstrap, a TYPE_CHECKING consumer, constructor injection, shared resources, fresh handlers, and explicit cleanup. Each bind manages its own transaction; no outer book lock is needed.
Before you run๏
Use the Beginner guide for prerequisite concepts. Run from a checkout with Melder installed and Python 3.14 free-threading selected. The collection download includes the level's local helper modules.
Run the saved script๏
python UX_and_AIX_experiences/01_beginner/40_beginner_capstone.py
py -3.14t UX_and_AIX_experiences/01_beginner/40_beginner_capstone.py
Public surface๏
md.Spellbook.bind/conjure, md.Conduit.meld/cleanup, unique/many, constructor injection, disposal_method_names
Code๏
1"""
2TIER: beginner (40) - capstone
3GOAL: Build and use a small application across separate Python modules:
4 ordinary objects, one bootstrap, a TYPE_CHECKING consumer, constructor
5 injection, shared resources, fresh handlers, and explicit cleanup.
6 Each bind manages its own transaction; no outer book lock is needed.
7SURFACE EXERCISED: md.Spellbook.bind/conjure, md.Conduit.meld/cleanup,
8 unique/many, constructor injection, disposal_method_names
9"""
10from typing import TYPE_CHECKING
11
12from capstone_application import run_application
13from capstone_bootstrap import build_application
14
15if TYPE_CHECKING:
16 from capstone_models import DbPool
17
18
19def main() -> None:
20 """Start the graph, use it, and guarantee shutdown around the application call."""
21 book, conduit = build_application()
22 try:
23 pool: DbPool = conduit.meld(spell="DbPool")
24 messages = run_application(conduit)
25 assert messages == [
26 "orders-service: order 101 = coffee",
27 "orders-service: order 102 = tea",
28 "orders-service: order 103 = cocoa",
29 ]
30 for message in messages:
31 print(message)
32 finally:
33 try:
34 conduit.cleanup()
35 finally:
36 book.cleanup()
37
38 assert pool.closed and pool.query_count == 3
39 print("pool closed:", pool.closed)
40 print("capstone complete: bootstrapped, typed, injected, used, cleaned")
41
42
43if __name__ == "__main__":
44 main()
Check the outcome๏
The script contains its own assertions or demonstrated refusal paths. Run it to evaluate those checks against your installed version. The code above is taken directly from the saved file; no run output is invented here.