nustack
ReferenceFabrics

nu.service

Service fabric: exposes a plain Python object as a Nu Service, so its methods become first-class Nu interactions on the tree. The fabric owns one target instance, bound on ctx via Provide and tagged by the Service class; MethodRefs on the Service pick the canonical Nu kind (query / action / command, scalar or stream) each endpoint compiles into.

Fabric

from nu.service import ServiceFabric

NameSortSignatureEffectMeaning
ServiceFabricclassServiceFabric(*, target)read/writeholds one Python target; resolves an endpoint by getattr(target, name) and calls it

Bind

from nu.service import bind

NameSortSignatureEffectMeaning
bindfunctionbind(service_cls, *, target)pureProvide a ServiceFabric wrapping target, tagged by the Service class

Refs

from nu.service import QueryRef, StreamQueryRef, ActionRef, StreamActionRef, CommandRef

One MethodRef class per canonical Nu kind. .method(name=None, **defaults) packages the Ref as a Method declaration on the Service class; name picks the attribute on target (defaults to the descriptor's field name). Calling the ref with kwargs constructs the matching interaction.

NameSortSignatureEffectMeaning
QueryRefclassQueryRef.method(name=None, **defaults) / QueryRef(**kwargs)pureread-only scalar endpoint; call yields a ServiceQuery
StreamQueryRefclassStreamQueryRef.method(name=None, **defaults) / StreamQueryRef(**kwargs)pureread-only stream endpoint; call yields a ServiceStreamQuery
ActionRefclassActionRef.method(name=None, **defaults) / ActionRef(**kwargs)read/writemutating scalar endpoint; call yields a ServiceAction
StreamActionRefclassStreamActionRef.method(name=None, **defaults) / StreamActionRef(**kwargs)read/writemutating stream endpoint; call yields a ServiceStreamAction
CommandRefclassCommandRef.method(name=None, **defaults) / CommandRef(**kwargs)read/writemutating void endpoint; call yields a ServiceCommand

Interactions

from nu.service import ServiceQuery, ServiceStreamQuery, ServiceAction, ServiceStreamAction, ServiceCommand

Five interactions, one per canonical Nu kind. The mutating three carry _mutates = {0}, marking the endpoint (child 0) as WRITE.

NameSortSignatureEffectMeaning
ServiceQueryScalarQueryServiceQuery(ref, kwargs)purepure scalar read; yields the method's return value
ServiceStreamQueryStreamQueryServiceStreamQuery(ref, kwargs)purepure stream read; yields items from the returned iterable
ServiceActionScalarActionServiceAction(ref, kwargs)read/writemutating scalar call; yields the return value, marks endpoint WRITE
ServiceStreamActionStreamActionServiceStreamAction(ref, kwargs)read/writemutating stream call; yields items, marks endpoint WRITE
ServiceCommandCommandServiceCommand(ref, kwargs)read/writemutating void call; yields nothing, marks endpoint WRITE

On this page