nustack
ReferenceNu STDkv

refs.primitives

virtuals-substrate refs for whole-blob compound values.

Module nustd.kv.refs.primitives.

virtuals-substrate refs for whole-blob compound values.

Unlike the decomposing container refs (ListRef / DictRef / SetRef, which fan a container out into per-element storage), these write the whole container as one opaque value via ItemPrimitiveSetCmd and read it back as a plain Python object. Each mixes in the matching collection Form, so the value still carries the full list / dict / tuple / set interface.

Use for opaque or heterogeneous containers that should round-trip whole rather than shape-decompose (log lines, raw account blobs, balance arrays, ...).

NameSortCallMeaning
PrimitiveDictRefrefPrimitiveDictRef(address, parent_ref=None, owner_shape=None)A dict leaf in KV storage, written and read back whole as one blob.
PrimitiveFrozenSetRefrefPrimitiveFrozenSetRef(address, parent_ref=None, owner_shape=None)A frozenset leaf in KV storage, written and read back whole as one blob.
PrimitiveListRefrefPrimitiveListRef(address, parent_ref=None, owner_shape=None)A list leaf in KV storage, written and read back whole as one blob.
PrimitiveSetRefrefPrimitiveSetRef(address, parent_ref=None, owner_shape=None)A set leaf in KV storage, written and read back whole as one blob.
PrimitiveTupleRefrefPrimitiveTupleRef(address, parent_ref=None, owner_shape=None)A tuple leaf in KV storage, written and read back whole as one blob.

PrimitiveDictRef

A dict leaf in KV storage, written and read back whole as one blob.

PrimitiveDictRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.PrimitiveDictRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as one opaque value, so the keys get no addresses of their own and cannot be reached or watched individually.
  • Reads come back as a real Python dict, nested contents included.
  • The write path is set with a whole dict. The key-level mutations inherited from the Dict surface (set_item, pop, update, ...) do not reach the stored blob and leave it as it was, without raising.
  • DictRef is the other choice: it decomposes into per-key storage and gives per-key navigation and change observation.

Example

class Bag(Shape):
    meta = PrimitiveDictRef.slot()
run(Bag.meta.set({"a": 1, "b": [2, 3]}), ctx)
run(Bag.meta, ctx)

Methods

.set(value)

Store the whole dict as one leaf value.

Builds object.

Arguments

NameTypeDefaultMeaning
valueArg[dict[K, V]]the dict to store. May be a literal or an expression.

Yields

Nothing. It is a command, run for the write.

Notes

  • Overrides the decomposing slot write, so the dict lands as one opaque value with no per-key children underneath it.
  • Replaces whatever was there; keys already stored are not merged in.

Example

run(Bag.meta.set({"a": 1}), ctx)

Inherited methods

From nu.domains.shape.forms.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.forms.item.MutableItemForm:

CallBuildsMeaning
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.forms.item.ItemForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.forms.collections.dict_.Dict:

CallBuildsMeaning
PrimitiveDictRef.create()Dict[K, V]Fresh empty dict.
PrimitiveDictRef.of(fields)Dict[str, V]Dict built from named field expressions.
a[key]Value at key.
.keys()DictKeys[K]Self's keys as a live view.
.values()DictValues[V]Self's values as a live view.
.items()DictItems[K, V]Self's key-value pairs as a live view.
a > bBoolSelf strictly greater than other.
a < bBoolSelf strictly less than other.
a >= bBoolSelf greater than or equal to other.
a <= bBoolSelf less than or equal to other.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.forms.collections.abc.mapping.MutableMappingForm:

CallBuildsMeaning
.set_item(key, value)AnySet the value at key, inserting the key if it's missing: mapping[key] = value.
.del_item(key)AnyDelete the entry at key: del mapping[key].
.update(other)AnyWrite other's entries into self, in place: mapping.update(other).
.pop(key, default=None)ValueResultTRemove key and yield its value, or default if key is missing.
.popitem()ValueResultTRemove and yield an arbitrary (key, value) pair: mapping.popitem().
.setdefault(key, default=None)ValueResultTValue at key, inserting default there first if key is missing.
.merge_update(other)CollectionResultTMerge other into self in place, and yield self: mapping |= other.
.clear()AnyRemove all entries: mapping.clear().

From nu.forms.collections.abc.mapping.MappingForm:

CallBuildsMeaning
.get_item(key, default=None)ValueResultTValue at key, falling back to default: mapping.get_item(key, default).
.copy()CollectionResultTShallow copy of self: mapping.copy().
.reversed_keys()CollectionResultTKeys in reverse insertion order: reversed(mapping).
.reversed_values()CollectionResultTValues in reverse insertion order: reversed(mapping.values()).
.reversed_items()CollectionResultT(key, value) pairs in reverse insertion order: reversed(mapping.items()).
.merge(other)CollectionResultTSelf and other merged into a new mapping: mapping | other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

PrimitiveFrozenSetRef

A frozenset leaf in KV storage, written and read back whole as one blob.

PrimitiveFrozenSetRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.PrimitiveFrozenSetRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Reads come back as a real Python frozenset, so the type survives the round trip.
  • Carries the read-only set surface only: union, intersection and the rest yield new values and never touch storage.
  • Has no decomposing counterpart; a frozenset slot is always stored whole.

Example

class Bag(Shape):
    locked = PrimitiveFrozenSetRef.slot()
run(Bag.locked.set(frozenset({1, 2})), ctx)
run(Bag.locked, ctx)

Methods

.set(value)

Store the whole frozenset as one leaf value.

Builds object.

Arguments

NameTypeDefaultMeaning
valueArg[frozenset[T]]the frozenset to store. May be a literal or an expression.

Yields

Nothing. It is a command, run for the write.

Notes

  • Replaces whatever was there.

Example

run(Bag.locked.set(frozenset({1, 2})), ctx)

Inherited methods

From nu.domains.shape.forms.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.forms.item.MutableItemForm:

CallBuildsMeaning
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.forms.item.ItemForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.forms.collections.set_.FrozenSet:

CallBuildsMeaning
PrimitiveFrozenSetRef.create()FrozenSet[T]Build an empty frozenset.
PrimitiveFrozenSetRef.of(*items)FrozenSetBuild a frozenset from positional item expressions.
a > bBoolSelf is a proper superset of other.
a < bBoolSelf is a proper subset of other.
a >= bBoolSelf is a superset of other, or equal.
a <= bBoolSelf is a subset of other, or equal.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.forms.collections.abc.set_.SetLikeForm:

CallBuildsMeaning
.union(other)CollectionResultTUnion of self and other.
.intersection(other)CollectionResultTIntersection of self and other.
.difference(other)CollectionResultTElements of self that are not in other.
.symmetric_difference(other)CollectionResultTElements in exactly one of self and other, not both.
.issubset(other)BoolWhether every element of self is in other.
.issuperset(other)BoolWhether every element of other is in self.
.isdisjoint(other)BoolWhether self and other share no elements.
.copy()CollectionResultTShallow copy of self.
a | bCollectionResultTUnion: self | other.
a & bCollectionResultTIntersection: self & other.
a - bCollectionResultTDifference: self - other.
a ^ bCollectionResultTSymmetric difference: self ^ other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

PrimitiveListRef

A list leaf in KV storage, written and read back whole as one blob.

PrimitiveListRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.PrimitiveListRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Stored as one opaque value, so the elements get no addresses of their own and cannot be reached or watched individually.
  • Reads come back as a real Python list, so heterogeneous and nested contents round-trip as they were written.
  • The write path is set with a whole list. The element-level mutations inherited from the List surface (append, insert, del_at, ...) do not reach the stored blob and leave it as it was, without raising.
  • ListRef is the other choice: it decomposes into per-index storage and gives per-element navigation.

Example

class Bag(Shape):
    rows = PrimitiveListRef.slot()
run(Bag.rows.set([1, "two", {"three": 3}]), ctx)
run(Bag.rows, ctx)

Methods

.set(value)

Store the whole list as one leaf value.

Builds object.

Arguments

NameTypeDefaultMeaning
valueArg[list[T]]the list to store. May be a literal or an expression.

Yields

Nothing. It is a command, run for the write.

Notes

  • Overrides the decomposing slot write, so the list lands as one opaque value with no per-index children underneath it.
  • Replaces whatever was there; there is no merge with the value already stored.

Example

run(Bag.rows.set([1, "two"]), ctx)

Inherited methods

From nu.domains.shape.forms.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.forms.item.MutableItemForm:

CallBuildsMeaning
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.forms.item.ItemForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.forms.collections.list_.List:

CallBuildsMeaning
PrimitiveListRef.create()List[T]Yield a fresh empty list.
PrimitiveListRef.of(items)ListYield a list from positional item expressions.
a[key]Element at an int index, or subsequence for a slice.
a + bList[T]Concatenation of self and other.
a * bList[T]Self repeated n times.
a[key] = valueAnySubscript write: self[index] = value.
a > bBoolSelf strictly greater than other, element-by-element.
a < bBoolSelf strictly less than other, element-by-element.
a >= bBoolSelf greater than or equal to other, element-by-element.
a <= bBoolSelf less than or equal to other, element-by-element.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.forms.collections.abc.sequence.MutableSequenceForm:

CallBuildsMeaning
.append(value)AnyAppend value to the end of self.
.extend(other)AnyExtend self with the elements of other, in order.
.insert(index, value)AnyInsert value at index, shifting later elements right.
.pop(index=-1)ElementResultTRemove and return the element at index.
.del_at(index)AnyRemove the element at index.
.remove(value)AnyRemove the first occurrence of value.
.reverse()AnyReverse self in place.
.sort()AnySort self in place, ascending, using the elements' natural order.
.copy()CollectionResultTShallow copy of self: a new sequence with the same elements.
.clear()AnyRemove every element from self.

From nu.forms.collections.abc.sequence.SequenceForm:

CallBuildsMeaning
.first_elem()ElementResultTFirst element of self.
.last_elem()ElementResultTLast element of self.
.index(value)IntLowest index in self where value is found, searching from the left.
.count(value)IntCount of occurrences of value in self.
.reversed()CollectionResultTSelf walked back to front, as a stream.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.forms.collections.abc.sliceable.SliceableForm:

CallBuildsMeaning
.slice(start, stop, step=None)ResultTSlice of self from start to stop, stepping by step.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

PrimitiveSetRef

A set leaf in KV storage, written and read back whole as one blob.

PrimitiveSetRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.PrimitiveSetRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Reads come back as a real Python set, so membership and the set operators work on the value as they would in Python.
  • The write path is set with a whole set. The element-level mutations inherited from the Set surface (add, discard, update, ...) do not reach the stored blob and leave it as it was, without raising.
  • SetRef is the other choice: it decomposes into per-element storage and gives change observation.

Example

class Bag(Shape):
    members = PrimitiveSetRef.slot()
run(Bag.members.set({1, 2, 3}), ctx)
run(Bag.members, ctx)

Methods

.set(value)

Store the whole set as one leaf value.

Builds object.

Arguments

NameTypeDefaultMeaning
valueArg[set[T]]the set to store. May be a literal or an expression.

Yields

Nothing. It is a command, run for the write.

Notes

  • Replaces whatever was there; it is not a union with the set already stored.

Example

run(Bag.members.set({1, 2}), ctx)

Inherited methods

From nu.domains.shape.forms.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.forms.item.MutableItemForm:

CallBuildsMeaning
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.forms.item.ItemForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.forms.collections.set_.Set:

CallBuildsMeaning
PrimitiveSetRef.create()Set[T]Build a fresh empty set.
PrimitiveSetRef.of(*items)SetBuild a set from positional item expressions.
a > bBoolSelf is a proper superset of other.
a < bBoolSelf is a proper subset of other.
a >= bBoolSelf is a superset of other, or equal.
a <= bBoolSelf is a subset of other, or equal.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.forms.collections.abc.set_.MutableSetForm:

CallBuildsMeaning
.add(value)AnyAdd value to self.
.remove(value)AnyRemove value from self.
.discard(value)AnyRemove value from self if present.
.pop()ElementResultTRemove and return an arbitrary element from self.
.clear()AnyRemove every element from self.
.update(other)AnyAdd every element of other to self.
.intersection_update(other)AnyKeep only the elements of self also found in other.
.difference_update(other)AnyRemove every element of other from self.
.symmetric_difference_update(other)AnyKeep the elements in exactly one of self and other.

From nu.forms.collections.abc.set_.SetLikeForm:

CallBuildsMeaning
.union(other)CollectionResultTUnion of self and other.
.intersection(other)CollectionResultTIntersection of self and other.
.difference(other)CollectionResultTElements of self that are not in other.
.symmetric_difference(other)CollectionResultTElements in exactly one of self and other, not both.
.issubset(other)BoolWhether every element of self is in other.
.issuperset(other)BoolWhether every element of other is in self.
.isdisjoint(other)BoolWhether self and other share no elements.
.copy()CollectionResultTShallow copy of self.
a | bCollectionResultTUnion: self | other.
a & bCollectionResultTIntersection: self & other.
a - bCollectionResultTDifference: self - other.
a ^ bCollectionResultTSymmetric difference: self ^ other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

PrimitiveTupleRef

A tuple leaf in KV storage, written and read back whole as one blob.

PrimitiveTupleRef(address, parent_ref=None, owner_shape=None)

Path nustd.kv.PrimitiveTupleRef. Kind Ref, sort ref, cardinality scalar.

Notes

  • Reads come back as a real Python tuple, so the type survives the round trip rather than degrading to a list.
  • Has no decomposing counterpart: a tuple slot is always stored whole.
  • Elements get no addresses of their own, so nothing under it can be reached or watched individually.

Example

class Bag(Shape):
    pair = PrimitiveTupleRef.slot()
run(Bag.pair.set((1, "two")), ctx)
run(Bag.pair, ctx)

Methods

.set(value)

Store the whole tuple as one leaf value.

Builds object.

Arguments

NameTypeDefaultMeaning
valueArg[tuple]the tuple to store. May be a literal or an expression.

Yields

Nothing. It is a command, run for the write.

Notes

  • Replaces whatever was there.

Example

run(Bag.pair.set((1, "two")), ctx)

Inherited methods

From nu.domains.shape.forms.item.ReactiveItemForm:

CallBuildsMeaning
.on_change()OnPrimitiveChangeSubscribe to changes on this leaf.

From nu.domains.shape.forms.item.MutableItemForm:

CallBuildsMeaning
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the leaf is currently missing.

From nu.domains.shape.forms.item.ItemForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.forms.collections.tuple_.Tuple:

CallBuildsMeaning
PrimitiveTupleRef.create()Tuple[Unpack[Ts]]Empty tuple.
PrimitiveTupleRef.of(items)TupleTuple built from positional item expressions.
a + bTupleConcatenation of self and other.
a * bTupleSelf repeated n times.
a > bBoolSelf strictly greater than other, lexicographically.
a < bBoolSelf strictly less than other, lexicographically.
a >= bBoolSelf greater than or equal to other, lexicographically.
a <= bBoolSelf less than or equal to other, lexicographically.
a == bBoolSelf equal to other by value.
a != bBoolSelf not equal to other by value.
.is_(other)BoolIdentity comparison: self is other.

From nu.forms.collections.abc.sequence.SequenceForm:

CallBuildsMeaning
a[key]ElementResultT | CollectionResultTElement at an int index, or subsequence for a slice.
.first_elem()ElementResultTFirst element of self.
.last_elem()ElementResultTLast element of self.
.index(value)IntLowest index in self where value is found, searching from the left.
.count(value)IntCount of occurrences of value in self.
.reversed()CollectionResultTSelf walked back to front, as a stream.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.forms.collections.abc.sliceable.SliceableForm:

CallBuildsMeaning
.slice(start, stop, step=None)ResultTSlice of self from start to stop, stepping by step.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

On this page