On this page
Spellbinder full chain๏
๐ก Intermediate ยท Lesson 02
Every link in the fluent chain, one binder reused across registrations: existence (explicit and shorthand), permissions, spellframe grouping, binding names, and constructor kwargs.
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/02_spellbinder_full_chain.py
py -3.14t UX_and_AIX_experiences/02_intermediate/02_spellbinder_full_chain.py
Public surface๏
md.SpellBinder full chain, md.Existence, spellframes
Code๏
1"""
2TIER: intermediate (02)
3GOAL: Every link in the fluent chain, one binder reused across
4 registrations: existence (explicit and shorthand), permissions,
5 spellframe grouping, binding names, and constructor kwargs.
6SURFACE EXERCISED: md.SpellBinder full chain, md.Existence, spellframes
7"""
8import melder as md
9
10
11class HttpClient:
12 def __init__(self, base_url: str = "", timeout: int = 0) -> None:
13 self.base_url = base_url
14 self.timeout = timeout
15
16 def close(self) -> None:
17 pass
18
19
20class RetryPolicy:
21 pass
22
23
24def main() -> None:
25 book = md.Spellbook()
26 binder = md.SpellBinder(book)
27
28 # one full sentence: frame + name + kwargs + lifecycle + permissions
29 binder.bind(HttpClient) \
30 .with_existence(md.Existence.unique) \
31 .with_permissions("create") \
32 .under_spellframe("network") \
33 .named("payments-api") \
34 .with_kwargs(disposal_method_names=["close"]) \
35 .finalize()
36
37 # binder resets after finalize - next sentence starts clean
38 binder.bind(RetryPolicy).as_unique_per_conduit().under_spellframe(
39 "network").finalize()
40
41 conduit = book.conjure()
42 client = conduit.meld(
43 spell=HttpClient, spellframe="network", binding_name="payments-api",
44 override={"base_url": "https://pay.example", "timeout": 30},
45 )
46 assert client.base_url == "https://pay.example" and client.timeout == 30
47 print("ctor config via override:", client.base_url)
48 # NOTE: with_kwargs passes BIND parameters (here: disposal list);
49 # Constructor arguments ride override= at meld time.
50
51 child = conduit.create_lesser_conduit()
52 policy_root = conduit.meld(spell=RetryPolicy, spellframe="network")
53 policy_child = child.meld(spell=RetryPolicy, spellframe="network")
54 assert policy_root is not policy_child
55 print("per-conduit policy under a spellframe: one per scope")
56
57
58if __name__ == "__main__":
59 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.