nustack
ReferenceFabrics

nu.virtuals

KV-storage fabric adapter: virtual collections layered over any tkv backend (in-memory, LMDB, RocksDB, text). Views decompose containers into per-element storage; refs navigate the view hierarchy against a snapshot or transaction resolved from the Context. Persistent, paged, composable through view types. Aliased as nu.v.

Base

from nu.v import ViewRef, PrimitiveRef, Facet

NameSortSignatureEffectMeaning
ViewRefclassViewRef(address, *, view_type=None, parent_ref=None, owner_shape=None)read/writeref to a container view; navigates and returns a live faceted virtuals View
PrimitiveRefclassPrimitiveRef(address, *, value_type, parent_ref=None, owner_shape=None)read/writeref to a leaf value; navigates to the parent view and subscripts the address
FacetEnumFacet.NONE / LAZY / EAGERpureview facet applied on fetch; .lazy / .eager properties on ViewRef switch it

Items

from nu.v import ItemRef, IntRef, StrRef, FloatRef, BoolRef, BytesRef

NameSortSignatureEffectMeaning
ItemRefclassItemRef(address, *, value_type, value_value_type, parent_ref=None, owner_shape=None)read/writegeneric typed leaf-value holder on the virtuals substrate
IntRefclassIntRef(address, *, parent_ref=None, owner_shape=None)read/writevirtuals integer ref with full numeric interface (Int mixin); adds inc/dec
StrRefclassStrRef(address, *, parent_ref=None, owner_shape=None)read/writevirtuals string ref with full string interface (Str mixin)
FloatRefclassFloatRef(address, *, parent_ref=None, owner_shape=None)read/writevirtuals float ref with full numeric interface (Float mixin)
BoolRefclassBoolRef(address, *, parent_ref=None, owner_shape=None)read/writevirtuals boolean ref with full logical interface (Bool mixin)
BytesRefclassBytesRef(address, *, parent_ref=None, owner_shape=None)read/writevirtuals bytes ref with full bytes interface (Bytes mixin)

Dict

from nu.v import DictRef

NameSortSignatureEffectMeaning
DictRefclassDictRef(address, *, value_type, key_type, key_value_type, value_value_type, view_type, parent_ref=None, owner_shape=None)read/writekey-value mapping backed by a virtuals mapping view (default DictView)

Dict Shapes

from nu.v import ShapesDictRef

NameSortSignatureEffectMeaning
ShapesDictRefclassShapesDictRef(address, *, shape_type, key_type, key_value_type, view_type=None, parent_ref=None, owner_shape=None)read/writemapping of homogeneous shapes; key descent yields a substrate-backed ShapeRef

List

from nu.v import ListRef

NameSortSignatureEffectMeaning
ListRefclassListRef(address, *, item_type, item_value_type, view_type, parent_ref=None, owner_shape=None)read/writeordered element container backed by a virtuals sequence view (default ListView)

List Shapes

from nu.v import ShapesListRef

NameSortSignatureEffectMeaning
ShapesListRefclassShapesListRef(address, *, shape_type, view_type=None, parent_ref=None, owner_shape=None)read/writesequence of homogeneous shapes; index descent yields a substrate-backed ShapeRef

Set

from nu.v import SetRef

NameSortSignatureEffectMeaning
SetRefclassSetRef(address, *, item_type, view_type, parent_ref=None, owner_shape=None)read/writeunordered unique-element container backed by a virtuals set view (default SetView)

Shape

from nu.v import ShapeRef

NameSortSignatureEffectMeaning
ShapeRefclassShapeRef(address, *, shape_type, view_type=None, parent_ref=None, owner_shape=None)read/writestructured named-slot container backed by a mapping view; field descent yields each field's typed virtuals ref

Kh57

from nu.v import Kh57Ref, Kh57ShapesRef

Sparse int-keyed maps laid out under kh57-encoded child segments so range reservoir sampling runs with low read amplification. Keys are non-negative 57-bit ints; default view is Kh57View. Both add .sample(n, begin, end) and .range(begin, end) on top of the standard mapping surface.

NameSortSignatureEffectMeaning
Kh57RefclassKh57Ref(address, *, value_type, value_value_type, view_type=None, parent_ref=None, owner_shape=None)read/writesparse int-keyed mapping of primitive values with kh57 sampling
Kh57ShapesRefclassKh57ShapesRef(address, *, shape_type, view_type=None, parent_ref=None, owner_shape=None)read/writesparse int-keyed mapping of homogeneous shapes with kh57 sampling; key descent yields a ShapeRef

Stdlib

from nu.v import BasisPointRef, ComplexRef, DateRef, DatetimeRef, DecimalRef, FractionRef, PathRef, PercentageRef, TimeRef, TimedeltaRef, TimezoneRef, UUIDRef

Typed leaf refs for standard-library value types. Each overrides _lift / set to convert between the domain value and its on-disk form, and mixes in the matching nu.std Form for its operator interface, same pattern as IntRef.

NameSortSignatureEffectMeaning
DecimalRefclassDecimalRef(address, *, parent_ref=None, owner_shape=None)read/writeDecimal ref, stored as str
FractionRefclassFractionRef(address, *, parent_ref=None, owner_shape=None)read/writeFraction ref, stored as str
ComplexRefclassComplexRef(address, *, parent_ref=None, owner_shape=None)read/writecomplex ref, stored as str
BasisPointRefclassBasisPointRef(address, *, parent_ref=None, owner_shape=None)read/writebasis-point ref, stored as raw int
PercentageRefclassPercentageRef(address, *, parent_ref=None, owner_shape=None)read/writepercentage ref, stored as raw float
DateRefclassDateRef(address, *, parent_ref=None, owner_shape=None)read/writedate ref, stored as ISO str
DatetimeRefclassDatetimeRef(address, *, parent_ref=None, owner_shape=None)read/writedatetime ref, stored as ISO str
TimeRefclassTimeRef(address, *, parent_ref=None, owner_shape=None)read/writetime ref, stored as ISO str
TimedeltaRefclassTimedeltaRef(address, *, parent_ref=None, owner_shape=None)read/writetimedelta ref, stored as total seconds (float)
TimezoneRefclassTimezoneRef(address, *, parent_ref=None, owner_shape=None)read/writetimezone ref, stored as offset str
PathRefclassPathRef(address, *, parent_ref=None, owner_shape=None)read/writePath ref, stored as str
UUIDRefclassUUIDRef(address, *, parent_ref=None, owner_shape=None)read/writeUUID ref, stored as str

Primitive blobs

from nu.v import PrimitiveDictRef, PrimitiveListRef, PrimitiveSetRef, PrimitiveFrozenSetRef, PrimitiveTupleRef

Whole-blob compound refs: the container is written as one opaque value via ItemPrimitiveSetCmd and read back as a plain Python object. Use for heterogeneous or opaque containers that should round-trip whole rather than shape-decompose. Each mixes in the matching collection Form so the value still carries its full interface.

NameSortSignatureEffectMeaning
PrimitiveListRefclassPrimitiveListRef(address, *, parent_ref=None, owner_shape=None)read/writelist stored as a single primitive blob
PrimitiveDictRefclassPrimitiveDictRef(address, *, parent_ref=None, owner_shape=None)read/writedict stored as a single primitive blob
PrimitiveTupleRefclassPrimitiveTupleRef(address, *, parent_ref=None, owner_shape=None)read/writetuple stored as a single primitive blob
PrimitiveSetRefclassPrimitiveSetRef(address, *, parent_ref=None, owner_shape=None)read/writeset stored as a single primitive blob
PrimitiveFrozenSetRefclassPrimitiveFrozenSetRef(address, *, parent_ref=None, owner_shape=None)read/writefrozenset stored as a single primitive blob

Atomicity

from nu.v import Atomic, Snapshot, Transaction, RetryOnConflict, CONFLICT_ERRORS

Bracket the body to open a read-only snapshot or a write transaction on the resolved Navigator, scoped into the ctx for the body's duration. Snapshots close on exit; transactions commit on clean exit, abort on error.

NameSortSignatureEffectMeaning
AtomicfnAtomic(*children, scope=None)purepicks Transaction if the body has any tracked write, else Snapshot
SnapshotFormSnapshot(*children, scope=None)READread-only snapshot boundary; scopes SnapshotProtocol under scope into ctx
TransactionFormTransaction(*children, scope=None)WRITEwrite transaction boundary; scopes TransactionProtocol under scope into ctx
RetryOnConflictFormRetryOnConflict(body, *, max_attempts=5, delay=0.1, backoff=2.0, jitter=0.5, ...)RESOLVERetry preset for StorageTransactionConflictError and StorageLockTimeoutError only
CONFLICT_ERRORStuple(StorageTransactionConflictError, StorageLockTimeoutError)purethe two error types RetryOnConflict retries on by default

Item interactions

from nu.v import InitItemCmd, ItemPrimitiveGetUnsafe, ItemPrimitiveSetCmd, ItemPrimitiveSetUnsafeCmd, ItemPrimitiveSetUnsafeParentSkipCmd, ItemPrimitiveDeleteUnsafeCmd

Optimization internals for tree deformers, not user-facing APIs. The Unsafe variants require virtuals views with UnsafePrimitiveOpsBase in MRO. The leaf ref rides at children[0].

NameSortSignatureEffectMeaning
InitItemCmdScalarCommandInitItemCmd(ref)WRITEmaterialize the container chain by fetching the view
ItemPrimitiveGetUnsafeScalarQueryItemPrimitiveGetUnsafe(ref)READleaf read via _unsafe_primitive_read (single ctx.get)
ItemPrimitiveSetCmdScalarCommandItemPrimitiveSetCmd(ref, value)WRITEstore a value via _primitive_write, bypassing container type checks
ItemPrimitiveSetUnsafeCmdScalarCommandItemPrimitiveSetUnsafeCmd(ref, value)WRITEleaf write via _unsafe_primitive_write(ensure_exists=True)
ItemPrimitiveSetUnsafeParentSkipCmdScalarCommandItemPrimitiveSetUnsafeParentSkipCmd(ref, value)WRITEleaf write via _unsafe_primitive_write() (full parent skip)
ItemPrimitiveDeleteUnsafeCmdScalarCommandItemPrimitiveDeleteUnsafeCmd(ref)WRITEleaf delete via _unsafe_primitive_delete

Collection interactions

from nu.v import ScanPrimitivesUnsafe, ClearPrimitivesUnsafeCmd

Optimization internals for container views with UnsafePrimitiveOpsBase in MRO. The container view ref rides at children[0].

NameSortSignatureEffectMeaning
ScanPrimitivesUnsafeScalarQueryScanPrimitivesUnsafe(ref)READscan all direct primitive child values via _unsafe_primitive_scan_values
ClearPrimitivesUnsafeCmdScalarCommandClearPrimitivesUnsafeCmd(ref)WRITEclear all primitive children via _unsafe_primitive_clear

Kh57 interactions

from nu.v import Kh57Sample, Kh57Range

Range reservoir sampling atoms over a Kh57View. Both are deterministic given the view's salt and a seeded rng. The container view ref rides at children[0]; parameters live at slots 1..3.

NameSortSignatureEffectMeaning
Kh57SampleScalarQueryKh57Sample(ref, n, begin=None, end=None, *, rng=None)READup to n (int_key, value) samples from [begin, end), stable under out-of-range appends
Kh57RangeScalarQueryKh57Range(ref, begin, end)READlist of (int_key, value) pairs in [begin, end), ascending int-key order

Storage presets (imperative)

from nu.v import memory_storage, rocksdb_storage, rocksdb_storage_redis, text_storage

Context managers that yield a ready StorageProtocol for hand-wired Contexts. Persistence and codec picked per preset; each pairs a matching publisher.

NameSortSignatureEffectMeaning
memory_storagefnmemory_storage()purein-memory storage, no-op codec, in-memory publisher; ephemeral
text_storagefntext_storage(path)pureJSON text storage at path, text codec, in-memory publisher
rocksdb_storagefnrocksdb_storage(path, read_only=False, secondary_path=None, secondary_refresh_interval=0.01)pureRocksDB at path, binary codec, in-memory publisher
rocksdb_storage_redisfnrocksdb_storage_redis(path, ..., redis_url="redis://localhost:6379", channel_prefix="__every__")pureRocksDB at path, binary codec, Redis publisher for cross-process notifications

from nu.v import memory_navigator, lmdb_navigator, lmdb_navigator_redis, rocksdb_navigator, rocksdb_navigator_redis, text_navigator, inmem_observer, redis_observer

Each factory returns a single With(...) bracket that peers Provides the whole Codec + Transport + Publisher + Observer + Storage + Navigator stack. tags= folds onto Storage and Navigator bindings so a shard can pick its storage.

NameSortSignatureEffectMeaning
memory_navigatorfnmemory_navigator(*, tags=())purein-mem full stack: NoOpCodec + InMemory Transport/Publisher/Observer/Storage + Navigator
text_navigatorfntext_navigator(path, *, tags=(), read_only=False, log_operations=False)puretext (JSON) storage full stack; in-mem transport/publisher/observer
lmdb_navigatorfnlmdb_navigator(path, *, tags=(), read_only=False, map_size=10GiB, max_readers=126, subdir=True, sync=True)pureLMDB full stack; in-mem transport/publisher/observer
lmdb_navigator_redisfnlmdb_navigator_redis(path, *, tags=(), ..., redis_url="redis://localhost:6379", channel_prefix="nu")pureLMDB storage + Redis publisher/observer for cross-process notifications
rocksdb_navigatorfnrocksdb_navigator(path, *, tags=(), read_only=False, secondary_path=None, secondary_refresh_interval=0.01, disable_wal=False, options=None)pureRocksDB full stack; in-mem transport/publisher/observer
rocksdb_navigator_redisfnrocksdb_navigator_redis(path, *, tags=(), ..., redis_url="redis://localhost:6379", channel_prefix="__every__")pureRocksDB + Redis publisher/observer for cross-process notifications
inmem_observerfninmem_observer()pureTransport + Observer only; consume same-process notifications without owning storage
redis_observerfnredis_observer(redis_url="redis://localhost:6379", channel_prefix="nu")pureRedis Observer only; cross-process read-only subscriber

Paths

from nu.v import ViewPathSer, ValuePathSer

Tuple subclasses used as serializable navigation paths, registered as invisibles value types so paths pickle by value rather than proxy element-by-element.

NameSortSignatureEffectMeaning
ViewPathSerclassViewPathSer((addr, view_type), ...)pureserializable path to a view; sequence of (address, view_type) segments
ValuePathSerclassValuePathSer((addr, marker), ..., (addr, value_type))pureserializable path to a value; view segments plus a final (address, value_type)

Tree passes

from nu.v import auto_flow_atomic, inline_refs

NameSortSignatureEffectMeaning
auto_flow_atomicfnauto_flow_atomic(tree, scope=None)purebottom-up wrap non-Flow children of every Flow: Transaction if any write in scope, else Snapshot
inline_refsfninline_refs(tree)pureretired no-op; runtime path resolution superseded ref flattening

On this page