context
The Context fabric: the in-memory `ctx.attrs` and fabric bindings.
Module nu.context.
The Context fabric: the in-memory ctx.attrs and fabric bindings.
A Fabric is an addressable space where Refs live; it resolves Refs and carries out the Interactions over them. The Context fabric has two axes:
- attrs - a flat, name-keyed store (
ctx.attrs) for short-lived primitives (loop counters, accumulators, markers). Ref:AttrRef; writes:SetCmd/Delete; existence:AttrExists. The read isAttrRefitself. - fabric - typed bindings (
ctx.bind/ctx.get) for every other ctx-bound thing: execution resources, storage handles, cluster handles, compute actors. Ref:FabricRef(read-only, self-yields); existence:FabricExists. Provisioning bracketsProvide/ProvideList/ProvideDictinstall fabrics into the Context for a body's duration. ProtocolsFabric(empty marker; every ctx-bound thing satisfies it) andFabricLifecycle(Fabric)(with optional setup / cleanup) describe the contract.
The read on the attrs axis is the Ref's dual role; only existence needs an
explicit query. Other concrete fabrics (virtuals, mem, ray, ...) follow the
same shape in their own dirs: concrete Refs plus the interactions that touch
that fabric. Nothing in nu.core touches a fabric - core is the pure Python
builtins.
attrs.interactions
Module nu.context.attrs.interactions.
Attr-fabric interactions: SetCmd, Delete, AttrExists, Let.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| AttrExists | scalar_query | AttrExists(ref) | Whether the address of its AttrRef is bound in ctx.attrs. |
| Delete | scalar_command | Delete(ref) | Removes the slot its Ref names from the fabric, through that Ref. |
| Let | bracket | Let(name, value, body=None) | Binds a name to a value in ctx.attrs for the body's duration. |
| SetCmd | scalar_command | SetCmd(ref, value) | Writes a value into the slot its Ref names, through that Ref. |
fabric.queries
Module nu.context.fabric.queries.
Fabric existence query.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| FabricExists | scalar_query | FabricExists(ref) | Whether the fabric type of its FabricRef is bound on the Context. |
fabric.lifecycle
Module nu.context.fabric.lifecycle.
Provide brackets: construct + bind fabrics for the body's duration.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| Provide | bracket | Provide(cls, kwargs=None, body=None, tag=None, tags=(), predicate=None, bind_as=None) | Constructs one fabric and binds it on the Context for the body's duration. |
| ProvideDict | bracket | ProvideDict(cls, specs, body=None, extra_tags=(), predicate=None, bind_as=None, parallel=False) | Constructs a fleet of one class and binds each member under its own key. |
| ProvideList | bracket | ProvideList(cls, specs, body=None, base_tag=0, extra_tags=(), predicate=None, bind_as=None) | Constructs a fleet of one class and binds each member under its index. |
| With | bracket | With(body=None) | Enters several lifecycle brackets around one body, tearing down in reverse. |
attrs.refs
Module nu.context.attrs.refs.
AttrRef and its typed variants.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| AnyAttrRef | ref | AnyAttrRef() | An AttrRef with the dynamic any interface. |
| AttrRef | ref | AttrRef(address) | A Ref into the ctx.attrs store, keyed by its resolved address. |
| BoolAttrRef | ref | BoolAttrRef() | An AttrRef with the full boolean interface. |
| BytesAttrRef | ref | BytesAttrRef() | An AttrRef with the full bytes interface. |
| DictAttrRef | ref | DictAttrRef() | An AttrRef with the full dict interface. |
| FloatAttrRef | ref | FloatAttrRef() | An AttrRef with the full float interface. |
| FrozenSetAttrRef | ref | FrozenSetAttrRef() | An AttrRef with the full frozenset interface. |
| IntAttrRef | ref | IntAttrRef() | An AttrRef with the full integer interface. |
| ListAttrRef | ref | ListAttrRef() | An AttrRef with the full list interface. |
| NoneAttrRef | ref | NoneAttrRef(source=None) | An AttrRef with the none interface. |
| SetAttrRef | ref | SetAttrRef() | An AttrRef with the full set interface. |
| StrAttrRef | ref | StrAttrRef() | An AttrRef with the full string interface. |
| TupleAttrRef | ref | TupleAttrRef() | An AttrRef with the full tuple interface. |
fabric.refs
Module nu.context.fabric.refs.
FabricRef: a Ref into a Context binding.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| FabricRef | ref | FabricRef(address=None) | A Ref into a Context binding, keyed by the fabric type it resolves to. |