nustack
ReferenceNu STDkv

refs.items

Virtuals item refs: typed leaf-value holders backed by virtuals storage.

Module nustd.kv.refs.items.

Virtuals item refs: typed leaf-value holders backed by virtuals storage.

ItemRef combines the shape ReactiveItemRef blueprint (slot-level CRUD + change observation) with PrimitiveRef (virtuals leaf navigation). Typed refs (IntRef, StrRef, ...) add the matching primitive Form so the value carries its full operator interface.

Reactivity is uniform: ReactiveItemForm.on_change() -> nu.core.reactive .OnPrimitiveChange` calls `ref._afetch_parent` + `ref._aaddress on the leaf, and the virtuals PrimitiveRef implements both -- no substrate-side override needed.

NameSortCallMeaning
BoolRefrefBoolRef(address, parent_ref=None, owner_shape=None)A bool leaf in KV storage, carrying the whole Bool logical surface.
BytesRefrefBytesRef(address, parent_ref=None, owner_shape=None)A bytes leaf in KV storage, carrying the whole Bytes operator surface.
FloatRefrefFloatRef(address, parent_ref=None, owner_shape=None)A float leaf in KV storage, carrying the whole Float operator surface.
IntRefrefIntRef(address, parent_ref=None, owner_shape=None)An int leaf in KV storage, carrying the whole Int operator surface.
ItemRefrefItemRef(address, value_type, value_value_type, parent_ref=None, owner_shape=None)An untyped leaf slot in KV storage: read it, set it, erase it, watch it.
StrRefrefStrRef(address, parent_ref=None, owner_shape=None)A str leaf in KV storage, carrying the whole Str operator surface.

BoolRef

A bool leaf in KV storage, carrying the whole Bool logical surface.

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

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

Notes

  • Stored as a plain bool, so nothing is translated on read or write.
  • An absent leaf reads as EMPTY, which is not False; test with exists or is_empty when the difference matters.

Example

class Flags(Shape):
    live = BoolRef.slot()
run(Flags.live.set(True), ctx)
run(Flags.live.not_(), 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
.set(value)SetCmdBuild a SetCmd.
.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.primitives.bool_.Bool:

CallBuildsMeaning
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
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.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.

BytesRef

A bytes leaf in KV storage, carrying the whole Bytes operator surface.

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

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

Notes

  • Stored as plain bytes, so nothing is translated on read or write.
  • The leaf a raw payload belongs in: no decoding happens on the way through, unlike the std refs that serialize a domain type.

Example

class Blob(Shape):
    raw = BytesRef.slot()
run(Blob.raw.set(b"payload"), ctx)
run(Blob.raw.hex_(), 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
.set(value)SetCmdBuild a SetCmd.
.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.primitives.bytes_.Bytes:

CallBuildsMeaning
a + bBytesConcatenation of self and other.
a[key]Bytes | IntByte at an index, or a sub-range by slice.
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.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.decode(encoding='utf-8')StrDecode self to a string using the given encoding.
.hex_()StrHex string of self, two digits per byte.
.upper()BytesSelf with ASCII letters uppercased.
.lower()BytesSelf with ASCII letters lowercased.
.strip(chars=None)BytesSelf with leading and trailing bytes removed.
.lstrip(chars=None)BytesSelf with leading bytes removed.
.rstrip(chars=None)BytesSelf with trailing bytes removed.
.split_bytes(sep=None, maxsplit=-1)ListSelf split into a List of Bytes on sep.
.find_bytes(sub, start=0, end=None)IntLowest index of sub in self, or -1 if absent.
.count_bytes(sub)IntNumber of non-overlapping occurrences of sub in self.
.startswith(prefix)BoolSelf starts with prefix.
.endswith(suffix)BoolSelf ends with suffix.
.replace(old, new, count=-1)BytesSelf with occurrences of old replaced by new.
.removeprefix(prefix)BytesSelf with prefix removed if present.
.removesuffix(suffix)BytesSelf with suffix removed if present.
.translate(table, delete=b'')BytesSelf translated through a 256-byte table, with bytes in delete dropped first.
.title()BytesSelf titlecased: each word's first cased byte upper, the rest lower.
.capitalize()BytesSelf with the first byte uppercased and the rest lowercased.
.swapcase()BytesSelf with uppercase and lowercase bytes swapped.
.rsplit_bytes(sep=None, maxsplit=-1)ListSelf split into a List of Bytes on sep, counting maxsplit from the right.
.splitlines(keepends=False)ListSelf split into a List of Bytes at line boundaries.
.partition(sep)TupleSelf split around the first occurrence of sep.
.rpartition(sep)TupleSelf split around the last occurrence of sep.
.rfind_bytes(sub, start=0, end=None)IntHighest index of sub in self, or -1 if absent.
.index_bytes(sub, start=0, end=None)IntLowest index of sub in self.
.rindex_bytes(sub, start=0, end=None)IntHighest index of sub in self.
.isascii()BoolSelf has only ASCII bytes.
.isdigit()BoolSelf has only ASCII digit bytes, and at least one.
.isalpha()BoolSelf has only ASCII letter bytes, and at least one.
.isalnum()BoolSelf has only ASCII alphanumeric bytes, and at least one.
.isspace()BoolSelf has only ASCII whitespace bytes, and at least one.
.istitle()BoolSelf is titlecased, with at least one cased byte.
.isupper()BoolSelf has all cased bytes uppercase, and at least one cased byte.
.islower()BoolSelf has all cased bytes lowercase, and at least one cased byte.
.center(width, fillbyte=b' ')BytesSelf centered in a field of width, padded with fillbyte.
.ljust(width, fillbyte=b' ')BytesSelf left-justified in a field of width, padded with fillbyte.
.rjust(width, fillbyte=b' ')BytesSelf right-justified in a field of width, padded with fillbyte.
.zfill(width)BytesSelf padded with leading zero bytes to width.
.expandtabs(tabsize=8)BytesSelf with tab bytes expanded to spaces.
.join(iterable)BytesSelf used as separator between the elements of iterable.

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.

FloatRef

A float leaf in KV storage, carrying the whole Float operator surface.

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

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

Notes

  • Stored as a plain float, so nothing is translated on read or write.
  • Reach for DecimalRef instead when the value is money or anything else that must round-trip exactly.

Example

class Order(Shape):
    price = FloatRef.slot()
run(Order.price.set(12.5), 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
.set(value)SetCmdBuild a SetCmd.
.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.primitives.float_.Float:

CallBuildsMeaning
a + bFloatSum of self and other.
a - bFloatSelf minus other.
a * bFloatProduct of self and other.
a / bFloatSelf divided by other.
a // bFloatSelf floor-divided by other.
a % bFloatSelf modulo other.
a ** bFloatSelf raised to the other power.
-aFloatNegation of self.
+aFloatSelf unchanged.
abs(a)FloatAbsolute value of self.
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.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.

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.

IntRef

An int leaf in KV storage, carrying the whole Int operator surface.

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

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

Notes

  • Stored as a plain int, so the stored form and the value form are the same and nothing is translated on the way in or out.
  • Arithmetic on the ref builds an expression over the stored value; writing the result back is what set, inc and dec do.

Example

class Counter(Shape):
    hits = IntRef.slot()
run(Counter.hits.set(0), ctx)
run(Counter.hits.inc(), ctx)

Methods

.inc(step=1)

Add step to the stored int and write the result back.

Builds None_.

Arguments

NameTypeDefaultMeaning
stepIntArg1how much to add. May be an expression, not just a literal.

Notes

  • Read-modify-write in one term, not a storage-level atomic increment; wrap it in a transaction when concurrent writers can touch the same leaf.
  • An absent leaf reads as EMPTY, so the addition collapses to INVALID and the write refuses to store a sentinel. Set the slot before incrementing it.

Example

run(Counter.hits.inc(), ctx)

.dec(step=1)

Subtract step from the stored int and write the result back.

Builds None_.

Arguments

NameTypeDefaultMeaning
stepIntArg1how much to subtract. May be an expression.

Notes

  • Same read-modify-write shape as inc, and the same refusal to store a sentinel when the leaf is absent.

Example

run(Counter.hits.dec(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
.set(value)SetCmdBuild a SetCmd.
.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.primitives.int_.Int:

CallBuildsMeaning
a + bInt | FloatSum of self and other.
a - bInt | FloatSelf minus other.
a * bInt | FloatProduct of self and other.
a / bFloatSelf divided by other.
a // bInt | FloatSelf floor-divided by other.
a % bInt | FloatSelf modulo other.
a ** bInt | FloatSelf raised to the other power.
-aIntNegation of self.
+aIntSelf unchanged.
abs(a)IntAbsolute value of self.
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.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.bitand(other)IntBitwise AND: self & other.
.bitor(other)IntBitwise OR: self | other.
a ^ bIntBitwise XOR: self ^ other.
.bitnot()IntBitwise NOT: ~self.
a << bIntLeft shift: self shifted left by other bits.
a >> bIntRight shift: self shifted right by other bits.

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.

ItemRef

An untyped leaf slot in KV storage: read it, set it, erase it, watch it.

ItemRef(address, value_type, value_value_type, parent_ref=None, owner_shape=None)

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

The value type and the Form its reads are wrapped in are both given at declaration time, so one class covers any leaf whose type is only known where the slot is written. A typed sibling (IntRef, StrRef, ...) is the same leaf with that pair fixed and the matching operator surface mixed in.

Notes

  • Carries no operator surface of its own; reach for a typed ref when the value should support arithmetic, comparison or string ops.
  • Reads yield EMPTY when the leaf is absent rather than raising.
  • on_change works with no substrate-side wiring, because the leaf navigation already exposes the parent view and the address.

Example

class Bag(Shape):
    payload = ItemRef.slot(str, Str)
run(Bag.payload.set("hello"), ctx)
run(Bag.payload, 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
.set(value)SetCmdBuild a SetCmd.
.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.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.

StrRef

A str leaf in KV storage, carrying the whole Str operator surface.

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

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

Notes

  • Stored as a plain str, so nothing is translated on read or write.
  • Doubles as a key source: a str leaf can be the address of another ref, and it is resolved when the path is walked.

Example

class Portfolio(Shape):
    name = StrRef.slot()
run(Portfolio.name.set("core"), ctx)
run(Portfolio.name.upper(), 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
.set(value)SetCmdBuild a SetCmd.
.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.primitives.str_.Str:

CallBuildsMeaning
a + bStrConcatenation of self and other.
a[key]StrCharacter at an int index, or substring for a slice.
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.
.and_(other)BoolLogical AND of self and other.
.or_(other)BoolLogical OR of self and other.
.not_()BoolLogical NOT of self.
.bool_()BoolCast self to Bool.
.upper()StrSelf converted to uppercase.
.lower()StrSelf converted to lowercase.
.title()StrSelf converted to title case.
.capitalize()StrSelf with only the first character capitalized.
.swapcase()StrSelf with uppercase and lowercase characters swapped.
.casefold()StrSelf folded for aggressive, caseless matching.
.strip(chars=None)StrSelf with leading and trailing characters removed.
.lstrip(chars=None)StrSelf with leading characters removed.
.rstrip(chars=None)StrSelf with trailing characters removed.
.split(sep=None, maxsplit=-1)ListSelf split into a list on sep, from the left.
.rsplit(sep=None, maxsplit=-1)ListSelf split into a list on sep, from the right.
.splitlines(keepends=False)ListSelf split into a list at line boundaries.
.partition(sep)TupleSelf split around the first occurrence of sep into a 3-tuple.
.rpartition(sep)TupleSelf split around the last occurrence of sep into a 3-tuple.
.find(sub, start=0, end=None)IntLowest index in self where sub is found, searching from the left.
.rfind(sub, start=0, end=None)IntHighest index in self where sub is found, searching from the right.
.index(sub, start=0, end=None)IntLowest index in self where sub is found, searching from the left.
.rindex(sub, start=0, end=None)IntHighest index in self where sub is found, searching from the right.
.count_substring(sub)IntCount of non-overlapping occurrences of sub in self.
.startswith(prefix)BoolWhether self starts with prefix.
.endswith(suffix)BoolWhether self ends with suffix.
.isdigit()BoolWhether every character in self is a digit.
.isalpha()BoolWhether every character in self is alphabetic.
.isalnum()BoolWhether every character in self is alphanumeric.
.isspace()BoolWhether every character in self is whitespace.
.isnumeric()BoolWhether every character in self is numeric.
.isdecimal()BoolWhether every character in self is a decimal character.
.isidentifier()BoolWhether self is a valid Python identifier.
.isprintable()BoolWhether every character in self is printable.
.istitle()BoolWhether self is titlecased.
.isupper()BoolWhether every cased character in self is uppercase.
.islower()BoolWhether every cased character in self is lowercase.
.isascii()BoolWhether every character in self is ASCII.
.center(width, fillchar=' ')StrSelf centered in a field of the given width.
.ljust(width, fillchar=' ')StrSelf left-justified in a field of the given width.
.rjust(width, fillchar=' ')StrSelf right-justified in a field of the given width.
.zfill(width)StrSelf padded with leading zeros to the given width.
.expandtabs(tabsize=8)StrSelf with tab characters expanded to spaces.
.replace(old, new, count=-1)StrSelf with occurrences of old replaced by new.
.removeprefix(prefix)StrSelf with the given prefix removed if present.
.removesuffix(suffix)StrSelf with the given suffix removed if present.
.translate(table)StrSelf with characters mapped through a translation table.
.format_map(mapping)StrSelf formatted with {field} placeholders filled from mapping.
.encode(encoding='utf-8')BytesSelf encoded to Bytes.
.join(iterable)StrElements of iterable joined together with self as separator.

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