nustack
ReferenceNu STDkv

refs.std

virtuals-substrate refs for standard-library value types.

Module nustd.kv.refs.std.

virtuals-substrate refs for standard-library value types.

Each ref is a typed leaf on the virtuals View substrate whose stored form differs from its domain type, so it overrides store (domain -> storage) and coerce (storage -> domain). The value interface comes from mixing in the matching nustd Form, exactly as IntRef mixes in Int.

  • Decimal / Fraction / complex / Path / UUID: str
  • date / datetime / time / timezone: str (ISO / offset)
  • BasisPoint: int (raw basis points)
  • Percentage: float (raw percentage)
  • timedelta: float (total seconds)
NameSortCallMeaning
BasisPointRefrefBasisPointRef(address, parent_ref=None, owner_shape=None)A BasisPoint leaf in KV storage, stored as the raw int count of bps.
ComplexRefrefComplexRef(address, parent_ref=None, owner_shape=None)A complex leaf in KV storage, stored as the str Python prints for it.
DateRefrefDateRef(address, parent_ref=None, owner_shape=None)A date leaf in KV storage, stored as an ISO YYYY-MM-DD str.
DatetimeRefrefDatetimeRef(address, parent_ref=None, owner_shape=None)A datetime leaf in KV storage, stored as an ISO str.
DecimalRefrefDecimalRef(address, parent_ref=None, owner_shape=None)A Decimal leaf in KV storage, kept exact by storing its str form.
FractionRefrefFractionRef(address, parent_ref=None, owner_shape=None)A Fraction leaf in KV storage, stored as its numerator/denominator str.
PathRefrefPathRef(address, parent_ref=None, owner_shape=None)A filesystem path leaf in KV storage, stored as its str form.
PercentageRefrefPercentageRef(address, parent_ref=None, owner_shape=None)A Percentage leaf in KV storage, stored as the raw float percentage.
TimeRefrefTimeRef(address, parent_ref=None, owner_shape=None)A time-of-day leaf in KV storage, stored as an ISO HH:MM:SS str.
TimedeltaRefrefTimedeltaRef(address, parent_ref=None, owner_shape=None)A timedelta leaf in KV storage, stored as a float count of seconds.
TimezoneRefrefTimezoneRef(address, parent_ref=None, owner_shape=None)A fixed-offset timezone leaf in KV storage, stored as its offset str.
UUIDRefrefUUIDRef(address, parent_ref=None, owner_shape=None)A UUID leaf in KV storage, stored as its canonical hyphenated str.

BasisPointRef

A BasisPoint leaf in KV storage, stored as the raw int count of bps.

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

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

Notes

  • Stored as an int, so a rate is exact and no float rounding creeps in between writes and reads.
  • Reads wrap the int back into a BasisPoint, so the conversions (to_pct, to_dec) and the fee helpers are there on the ref.
  • An absent leaf reads as EMPTY, not as zero bps.

Example

class Fee(Shape):
    taker = BasisPointRef.slot()
run(Fee.taker.set(25), ctx)

Methods

.set(value)

Write a BasisPoint to the leaf, serialized to its raw int.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[PyBasisPoint | int]a BasisPoint, an int count of bps, or an expression yielding either.

Notes

  • A plain value goes through int() before the write; an expression is wrapped in a ToInt. Either way a fractional input truncates toward zero rather than rounding.

Example

run(Fee.taker.set(25), 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 nustd.fin.forms.BasisPoint:

CallBuildsMeaning
BasisPointRef.of(value)BasisPointA basis-point count from a raw int: BasisPoint(500).
BasisPointRef.from_pct(pct)BasisPointFrom a percentage: BasisPoint.from_pct(5.0) -> 500 bps.
BasisPointRef.from_dec(dec)BasisPointFrom a decimal ratio: BasisPoint.from_dec(0.05) -> 500 bps.
.to_pct()FloatThe percentage (500 bps -> 5.0).
.to_dec()FloatThe decimal ratio (500 bps -> 0.05).
.to_int()IntThe raw basis-point count.
.apply(amount)FloatThis many basis points of amount.
.add_to(amount)Floatamount grown by these basis points.
.sub_from(amount)Floatamount reduced by these basis points.
a + bBasisPoint
a - bBasisPoint
a * bBasisPoint
a / bBasisPoint
a // bBasisPoint
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two basis-point counts are equal.
.ne(other)BoolWhether two basis-point counts differ.

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.

ComplexRef

A complex leaf in KV storage, stored as the str Python prints for it.

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

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

Notes

  • Stored as str because a KV leaf holds one scalar; the pair is kept in the one text rather than in two slots.
  • Reads parse back to a complex, so real, imag and the arithmetic all work on the value.
  • An absent leaf reads as EMPTY.

Example

class Wave(Shape):
    amplitude = ComplexRef.slot()
run(Wave.amplitude.set(complex(1, 2)), ctx)

Methods

.set(value)

Write a complex to the leaf, serialized to its str form.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[complex | str]a complex, a str spelling one, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr so the conversion happens at run time.

Example

run(Wave.amplitude.set(complex(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 nustd.cmath.forms.complex:

CallBuildsMeaning
ComplexRef.of(real=0, imag=0)complexBuild a complex number: complex(real, imag).
.real()FloatThe real part.
.imag()FloatThe imaginary part.
.conjugate()complexThe complex conjugate (negates the imaginary part).
a + bcomplex
a - bcomplex
a * bcomplex
a / bcomplex
a ** bcomplex
-acomplex
+acomplex
abs(a)Float
.eq(other)BoolWhether two complex numbers are equal.
.ne(other)BoolWhether two complex numbers differ.

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.

DateRef

A date leaf in KV storage, stored as an ISO YYYY-MM-DD str.

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

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

Notes

  • ISO on disk, so stored dates sort lexicographically in the same order they sort chronologically.
  • Reads parse back to a date, so the field accessors and the arithmetic work on the value.
  • An absent leaf reads as EMPTY.

Example

class Order(Shape):
    booked = DateRef.slot()
run(Order.booked.set(date(2026, 1, 31)), ctx)

Methods

.set(value)

Write a date to the leaf, serialized to an ISO str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[date | str]a date, an ISO str, or an expression yielding either.

Notes

  • A plain date is written with isoformat; anything else plain is stringified, and an expression is wrapped in a ToStr.
  • A datetime passed here is a date subclass, so it writes its full ISO form, and reading that leaf back raises. Use DatetimeRef for a moment in time.

Example

run(Order.booked.set(date(2026, 1, 31)), 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 nustd.datetime.forms.date:

CallBuildsMeaning
DateRef.of(year, month, day)dateBuild a date: date(year, month, day).
DateRef.today()dateToday's date: date.today().
DateRef.from_iso(value)dateParse an ISO date string: date.fromisoformat(s).
DateRef.from_ordinal(value)dateFrom a proleptic Gregorian ordinal: date.fromordinal(n).
DateRef.from_timestamp(value)dateFrom a POSIX timestamp: date.fromtimestamp(t).
.year()IntThe year.
.month()IntThe month (1..12).
.day()IntThe day of the month (1..31).
.weekday()IntThe day of week, Monday=0.
.isoweekday()IntThe day of week, Monday=1.
.toordinal()IntThe proleptic Gregorian ordinal.
.isoformat()StrThe date as an ISO string (YYYY-MM-DD).
.ctime()StrThe date as a C-style string.
.strftime(fmt)StrFormat the date with a strftime pattern.
.replace(year=None, month=None, day=None)dateA copy with the given components replaced.
a + bdate
a - bdate | timedelta
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two dates are equal.
.ne(other)BoolWhether two dates differ.

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.

DatetimeRef

A datetime leaf in KV storage, stored as an ISO str.

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

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

Notes

  • ISO on disk, tz offset included when the datetime carries one; a naive datetime stays naive through the round trip.
  • A leaf holding a number instead of a str is read as a POSIX timestamp and comes back as an aware UTC datetime, which is how a slot written by something outside Nu still reads.
  • An absent leaf reads as EMPTY.

Example

class Order(Shape):
    filled_at = DatetimeRef.slot()
run(Order.filled_at.set(datetime.now(UTC)), ctx)

Methods

.set(value)

Write a datetime to the leaf, serialized to an ISO str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[datetime | str]a datetime, an ISO str, or an expression yielding either.

Notes

  • A plain datetime is written with isoformat; anything else plain is stringified, and an expression is wrapped in a ToStr.
  • Nothing is normalized to UTC on the way in, so the offset the value carried is the offset stored.

Example

run(Order.filled_at.set(datetime.now(UTC)), 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 nustd.datetime.forms.datetime:

CallBuildsMeaning
DatetimeRef.of(year, month, day, hour=0, minute=0, second=0, microsecond=0)datetimeBuild a datetime: datetime(year, month, day, hour, ...).
DatetimeRef.now(tz=None)datetimeThe current local (or tz) datetime: datetime.now(tz).
DatetimeRef.from_iso(value)datetimeParse an ISO datetime string: datetime.fromisoformat(s).
DatetimeRef.from_timestamp(value, tz=None)datetimeFrom a POSIX timestamp: datetime.fromtimestamp(ts, tz).
DatetimeRef.combine(date_value, time_value)datetimeCombine a date and a time: datetime.combine(date, time).
.year()IntThe year.
.month()IntThe month (1..12).
.day()IntThe day of the month (1..31).
.hour()IntThe hour (0..23).
.minute()IntThe minute (0..59).
.second()IntThe second (0..59).
.microsecond()IntThe microsecond (0..999999).
.weekday()IntThe day of week, Monday=0.
.isoweekday()IntThe day of week, Monday=1.
.timestamp()FloatThe POSIX timestamp.
.isoformat()StrThe datetime as an ISO string.
.strftime(fmt)StrFormat the datetime with a strftime pattern.
.date()dateThe date part.
.time()timeThe time part.
.replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None)datetimeA copy with the given components replaced.
a + bdatetime
a - bdatetime | timedelta
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two datetimes are equal.
.ne(other)BoolWhether two datetimes differ.

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.

DecimalRef

A Decimal leaf in KV storage, kept exact by storing its str form.

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

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

Notes

  • Stored as str, so the value round-trips digit for digit; that is the whole reason to pick this over FloatRef for money.
  • Reads parse back to a Decimal, so the arithmetic on the ref is decimal arithmetic, not float arithmetic.
  • An absent leaf reads as EMPTY, not as zero.

Example

class Order(Shape):
    price = DecimalRef.slot()
run(Order.price.set(Decimal("19.99")), ctx)

Methods

.set(value)

Write a Decimal to the leaf, serialized to its str form.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[Decimal | str]a Decimal, a str spelling one, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr so the conversion happens at run time.
  • The str is whatever str() gives, so it parses back exactly.

Example

run(Order.price.set(Decimal("19.99")), 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 nustd.decimal.forms.Decimal:

CallBuildsMeaning
DecimalRef.of(value)DecimalBuild a decimal from a string or int, exactly: Decimal(str(value)).
DecimalRef.from_float(value)DecimalFrom a binary float: Decimal.from_float(f) (carries float error).
a + bDecimal
a - bDecimal
a * bDecimal
a / bDecimal
a // bDecimal
a % bDecimal
a ** bDecimal
-aDecimal
abs(a)Decimal
+aDecimal
.quantize(exp)DecimalRound to the exponent of exp (e.g. Decimal.of("0.01")).
.normalize()DecimalA canonical form with trailing zeros removed.
.to_integral_value()DecimalThe value rounded to the nearest integer, kept as a Decimal.
.sqrt()DecimalThe square root.
.exp()DecimalThe exponential, e ** self.
.ln()DecimalThe natural logarithm.
.log10()DecimalThe base-10 logarithm.
.compare(other)DecimalDecimal('-1') / '0' / '1' for self <, ==, > other.
.copy_abs()DecimalThe absolute value (context-free, no rounding).
.copy_negate()DecimalThe negation (context-free, no rounding).
.adjusted()IntThe adjusted exponent after shifting out the coefficient's digits.
.as_integer_ratio()TupleThe exact value as a (numerator, denominator) pair of ints.
.is_finite()BoolWhether the value is finite (not infinite, not NaN).
.is_infinite()BoolWhether the value is positive or negative infinity.
.is_nan()BoolWhether the value is a NaN (quiet or signaling).
.is_zero()BoolWhether the value is zero (positive or negative).
.is_signed()BoolWhether the sign bit is set (negative, including -0).
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two decimals are equal in value.
.ne(other)BoolWhether two decimals differ in value.

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.

FractionRef

A Fraction leaf in KV storage, stored as its numerator/denominator str.

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

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

Notes

  • Stored as str, so the ratio survives exactly instead of being flattened to a float.
  • Reads parse back to a Fraction, already in lowest terms because that is what Fraction does with the str.
  • An absent leaf reads as EMPTY.

Example

class Split(Shape):
    share = FractionRef.slot()
run(Split.share.set(Fraction(1, 3)), ctx)

Methods

.set(value)

Write a Fraction to the leaf, serialized to its str form.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[Fraction | str]a Fraction, a str spelling one, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr so the conversion happens at run time.

Example

run(Split.share.set(Fraction(1, 3)), 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 nustd.fractions.forms.Fraction:

CallBuildsMeaning
FractionRef.of(numerator, denominator=1)FractionBuild a fraction from numerator and denominator: Fraction(n, d).
FractionRef.from_float(value)FractionThe exact fraction equal to a float: Fraction.from_float(f).
FractionRef.from_decimal(value)FractionThe exact fraction equal to a Decimal: Fraction.from_decimal(d).
FractionRef.from_str(value)FractionParse a fraction string: Fraction(s) (e.g. "3/4", "1.5").
.numerator()IntThe numerator (in lowest terms).
.denominator()IntThe denominator (in lowest terms, always positive).
.limit_denominator(max_denominator=1000000)FractionThe closest fraction with denominator at most max_denominator.
.as_integer_ratio()TupleThe (numerator, denominator) pair as a tuple.
a + bFraction
a - bFraction
a * bFraction
a / bFraction
a // bFraction
a % bFraction
a ** bFraction
-aFraction
abs(a)Fraction
+aFraction
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two fractions are equal.
.ne(other)BoolWhether two fractions differ.

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.

PathRef

A filesystem path leaf in KV storage, stored as its str form.

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

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

Notes

  • Reads come back as a PurePath, so the path surface is the pure one: parts, parents, suffixes, joins. Nothing here touches a filesystem.
  • Stored as written, so a path written on one platform reads back with that platform's separators.
  • An absent leaf reads as EMPTY.

Example

class Job(Shape):
    outdir = PathRef.slot()
run(Job.outdir.set(PurePath("/var/log")), ctx)

Methods

.set(value)

Write a path to the leaf, serialized to str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[PurePath | str]a path, a str, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr.

Example

run(Job.outdir.set(PurePath("/var/log")), 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 nustd.pathlib.forms.Path:

CallBuildsMeaning
PathRef.of()PathBuild a path from segments: PurePath(*segments).
PathRef.cwd()PathThe current working directory: Path.cwd().
PathRef.home()PathThe user's home directory: Path.home().
.name()StrThe final component (filename).
.stem()StrThe final component without its suffix.
.suffix()StrThe file extension of the final component (including the dot).
.suffixes()ListAll file extensions of the final component.
.parts()TupleThe path's components as a tuple.
.parent()PathThe logical parent of the path.
.root()StrThe root (e.g. / on POSIX).
.anchor()StrThe concatenation of drive and root.
.drive()StrThe drive (empty on POSIX).
.with_name(name)PathA copy with the final component's name replaced.
.with_stem(stem)PathA copy with the final component's stem replaced.
.with_suffix(suffix)PathA copy with the final component's suffix replaced.
.joinpath()PathJoin one or more components onto the path.
.relative_to(other)PathThe path relative to other.
a / bPathJoin with /: Path.of("a") / "b".
.as_posix()StrThe path as a string with forward slashes.
.as_uri()StrThe path as a file:// URI (requires an absolute path).
.match(pattern)BoolWhether the path matches a glob pattern.
.is_absolute()BoolWhether the path is absolute.
.is_relative_to(other)BoolWhether the path is relative to other.
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two paths are equal.
.ne(other)BoolWhether two paths differ.

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.

PercentageRef

A Percentage leaf in KV storage, stored as the raw float percentage.

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

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

Notes

  • Stored as the percentage itself, not as a fraction: 12.5 percent is 12.5 on disk, not 0.125.
  • Reads wrap the float back into a Percentage, so the conversions (to_dec, to_bps) and the apply helpers are on the ref.
  • Float storage, so it carries float rounding; BasisPointRef is the exact one.

Example

class Fee(Shape):
    slippage = PercentageRef.slot()
run(Fee.slippage.set(0.5), ctx)

Methods

.set(value)

Write a Percentage to the leaf, serialized to its raw float.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[PyPercentage | float]a Percentage, a raw float percentage, or an expression yielding either.

Notes

  • A plain value goes through float() before the write; an expression is wrapped in a ToFloat.
  • The number written is the percentage, so pass 12.5 for 12.5 percent.

Example

run(Fee.slippage.set(0.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
.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 nustd.fin.forms.Percentage:

CallBuildsMeaning
PercentageRef.of(value)PercentageA percentage from a raw value: Percentage(75.5).
PercentageRef.from_dec(dec)PercentageFrom a decimal ratio: Percentage.from_dec(0.755) -> 75.5%.
PercentageRef.from_bps(bps)PercentageFrom basis points: Percentage.from_bps(7550) -> 75.5%.
PercentageRef.from_ratio(numerator, denominator)PercentageFrom a ratio: Percentage.from_ratio(3, 4) -> 75%.
.to_dec()FloatThe decimal ratio (75.5% -> 0.755).
.to_bps()IntThe basis points (75.5% -> 7550).
.to_float()FloatThe raw percentage value.
.apply(amount)FloatThis percentage of amount.
.add_to(amount)Floatamount grown by this percentage.
.sub_from(amount)Floatamount reduced by this percentage.
.is_valid(min_val=0.0, max_val=100.0)BoolWhether the value falls within [min_val, max_val].
.clamp(min_val=0.0, max_val=100.0)PercentageThis percentage clamped to [min_val, max_val].
a + bPercentage
a - bPercentage
a * bPercentage
a / bPercentage
-aPercentage
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two percentages are equal.
.ne(other)BoolWhether two percentages differ.

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.

TimeRef

A time-of-day leaf in KV storage, stored as an ISO HH:MM:SS str.

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

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

Notes

  • A wall-clock time with no date attached, so nothing about it orders across days.
  • Reads parse back to a time, keeping any tz offset the str carried.
  • An absent leaf reads as EMPTY.

Example

class Window(Shape):
    opens = TimeRef.slot()
run(Window.opens.set(time(9, 30)), ctx)

Methods

.set(value)

Write a time to the leaf, serialized to an ISO str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[time | str]a time, an ISO str, or an expression yielding either.

Notes

  • A plain time is written with isoformat; anything else plain is stringified, and an expression is wrapped in a ToStr.

Example

run(Window.opens.set(time(9, 30)), 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 nustd.datetime.forms.time:

CallBuildsMeaning
TimeRef.of(hour=0, minute=0, second=0, microsecond=0)timeBuild a time: time(hour, minute, second, microsecond).
TimeRef.from_iso(value)timeParse an ISO time string: time.fromisoformat(s).
.hour()IntThe hour (0..23).
.minute()IntThe minute (0..59).
.second()IntThe second (0..59).
.microsecond()IntThe microsecond (0..999999).
.isoformat()StrThe time as an ISO string.
.strftime(fmt)StrFormat the time with a strftime pattern.
.replace(hour=None, minute=None, second=None, microsecond=None)timeA copy with the given components replaced.
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two times are equal.
.ne(other)BoolWhether two times differ.

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.

TimedeltaRef

A timedelta leaf in KV storage, stored as a float count of seconds.

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

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

Notes

  • One number on disk, so stored durations compare and sort as numbers without being parsed first.
  • Reads rebuild the timedelta from that count, so days, seconds and the arithmetic are on the value.
  • An absent leaf reads as EMPTY, not as a zero duration.

Example

class Job(Shape):
    timeout = TimedeltaRef.slot()
run(Job.timeout.set(timedelta(minutes=5)), ctx)

Methods

.set(value)

Write a timedelta to the leaf, serialized to total seconds.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[timedelta | float]a timedelta, a float count of seconds, or an expression yielding either.

Notes

  • A plain timedelta goes through total_seconds; a plain number through float(); an expression is wrapped in a TimedeltaTotalSeconds, so it must yield a timedelta.

Example

run(Job.timeout.set(timedelta(minutes=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
.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 nustd.datetime.forms.timedelta:

CallBuildsMeaning
TimedeltaRef.of(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)timedeltaBuild a timedelta from its components: timedelta(...).
.days()IntThe whole-days component.
.seconds()IntThe seconds component (0..86399).
.microseconds()IntThe microseconds component (0..999999).
.total_seconds()FloatThe total duration in seconds.
a + btimedelta
a - btimedelta
a * btimedelta
a / btimedelta | Float
a // btimedelta
a % btimedelta
-atimedelta
abs(a)timedelta
+atimedelta
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two spans are equal.
.ne(other)BoolWhether two spans differ.

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.

TimezoneRef

A fixed-offset timezone leaf in KV storage, stored as its offset str.

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

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

Notes

  • Holds a fixed offset only, spelled the way str(timezone) spells it: UTC or UTC+05:30.
  • A named zone is not what this slot stores: writing a ZoneInfo stores its name, and reading that leaf back raises.
  • An absent leaf reads as EMPTY.

Example

class Desk(Shape):
    zone = TimezoneRef.slot()
run(Desk.zone.set(timezone(timedelta(hours=4))), ctx)

Methods

.set(value)

Write a timezone to the leaf, serialized to its offset str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[timezone | str]a timezone, an offset str, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr.
  • Only the UTC and UTC±HH:MM spellings read back, so write a fixed-offset timezone here and nothing else.

Example

run(Desk.zone.set(timezone(timedelta(hours=4))), 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 nustd.datetime.forms.timezone:

CallBuildsMeaning
TimezoneRef.of(offset, name=None)timezoneBuild a fixed-offset zone: timezone(offset, name).
TimezoneRef.utc()timezoneThe UTC zone: timezone.utc.
.utcoffset(dt=None)timedeltaThe offset from UTC as a timedelta.
.tzname(dt=None)StrThe zone's name.
.dst(dt=None)None_Daylight-saving adjustment (always None for a fixed offset).
.eq(other)BoolWhether two zones are equal.
.ne(other)BoolWhether two zones differ.

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.

UUIDRef

A UUID leaf in KV storage, stored as its canonical hyphenated str.

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

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

Notes

  • Str on disk rather than 16 raw bytes, so the stored value is readable in a dump and matches what other systems expect.
  • Reads parse back to a UUID, so version, int_ and hex are on the ref.
  • An absent leaf reads as EMPTY.

Example

class Session(Shape):
    token = UUIDRef.slot()
run(Session.token.set(uuid4()), ctx)

Methods

.set(value)

Write a UUID to the leaf, serialized to str.

Builds SetCmd.

Arguments

NameTypeDefaultMeaning
valueArg[UUID | str]a UUID, a str spelling one, or an expression yielding either.

Notes

  • A plain value is stringified before the write; an expression is wrapped in a ToStr.
  • Any spelling UUID() accepts reads back, so a str without hyphens still parses; it is stored as given.

Example

run(Session.token.set(uuid4()), 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 nustd.uuid.forms.UUID:

CallBuildsMeaning
UUIDRef.from_str(value)UUIDParse a hex string (with or without hyphens) into a UUID.
UUIDRef.from_bytes(value)UUIDBuild a UUID from 16 bytes.
UUIDRef.from_int(value)UUIDBuild a UUID from a 128-bit integer.
.version()IntThe version number (1, 3, 4, or 5).
.variant()StrThe variant.
.time()IntThe 60-bit timestamp (version 1).
.clock_seq()IntThe 14-bit clock sequence (version 1).
.node()IntThe 48-bit node (version 1).
.hex()StrThe UUID as a 32-character hex string.
.urn()StrThe UUID as a URN (urn:uuid:...).
.bytes()BytesThe UUID as 16 bytes.
.bytes_le()BytesThe UUID as 16 bytes, little-endian.
.int_()IntThe UUID as a 128-bit integer.
a > bBool
a < bBool
a >= bBool
a <= bBool
.eq(other)BoolWhether two UUIDs are equal.
.ne(other)BoolWhether two UUIDs differ.

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