On this page
Spellbinder fluent basics๏
๐ก Intermediate ยท Lesson 10
The fluent registration hand - SpellBinder reads like a sentence: bind(X).as_unique().named("primary").finalize(). finalize() returns the spell id string and resets the binder for the next registration.
Before you run๏
Use the Intermediate 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/02_intermediate/10_spellbinder_fluent_basics.py
py -3.14t UX_and_AIX_experiences/02_intermediate/10_spellbinder_fluent_basics.py
Public surface๏
md.SpellBinder, md.Spellbook, finalize() -> str
Code๏
1"""
2TIER: intermediate (10)
3GOAL: The fluent registration hand - SpellBinder reads like a sentence:
4 bind(X).as_unique().named("primary").finalize(). finalize() returns
5 the spell id string and resets the binder for the next registration.
6SURFACE EXERCISED: md.SpellBinder, md.Spellbook, finalize() -> str
7"""
8import melder as md
9
10
11class TelemetrySink:
12 pass
13
14
15class AuditTrail:
16 pass
17
18
19def main() -> None:
20 book = md.Spellbook()
21 binder = md.SpellBinder(book)
22
23 sink_id = binder.bind(TelemetrySink).as_unique().named("sink").finalize()
24 audit_id = binder.bind(AuditTrail).as_many().finalize()
25 assert isinstance(sink_id, str) and isinstance(audit_id, str)
26 print("fluent binds returned spell ids:", sink_id[:8], audit_id[:8])
27
28 conduit = book.conjure()
29 sink_a = conduit.meld(spell=TelemetrySink, binding_name="sink")
30 sink_b = conduit.meld(spell=TelemetrySink, binding_name="sink")
31 audit_a = conduit.meld(spell=AuditTrail)
32 audit_b = conduit.meld(spell=AuditTrail)
33 assert sink_a is sink_b and audit_a is not audit_b
34 print("fluent lifecycles held: unique sink, many audit trails")
35
36
37if __name__ == "__main__":
38 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.