GitHub

API reference for Rpc.

An RPC with a payload P, succeeding with S or failing with E, wrapped by the middleware M (MT repeats it, so handlers can read both what it provides and its tag). Tag is its tag, a Literal when make is given one, so a group listing its tags can check its handlers.

Functions

__init__

__init__(tag, payload_schema, success_schema, error_schema, defect_schema, annotations=Context.empty(), middlewares=()) -> None
ParameterTypeDescription
tagstr
payload_schemaTop
success_schemaTop
error_schemaTop
defect_schemaTop
annotationsContext[Any] = Context.empty()
middlewarestuple[AnyMiddleware, ...] = ()

middleware

middleware[T: RpcMiddleware[Any, Any, Any]](middleware) -> Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]

This RPC wrapped by middleware: its handler may fail with the middleware's error and needs what it provides; a client may fail with it too.

ParameterTypeDescription
middlewaretype[T]

Returns Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]

def middleware[T: RpcMiddleware[Any, Any, Any]](
    self, middleware: type[T], /
) -> Rpc[P_co, S_co, E_co, M_co | T, MT_co | T, Tag_co]:
    """This RPC wrapped by ``middleware``: its handler may fail with the
    middleware's error and needs what it provides; a client may fail
    with it too."""
    return self.with_middleware(middleware)

set_success

set_success[S1](schema) -> Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]
ParameterTypeDescription
schemaCodec[S1, Any, Never, Never]

Returns Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]

def set_success[S1](
    self, schema: Codec[S1, Any, Never, Never], /
) -> Rpc[P_co, S1, E_co, M_co, MT_co, Tag_co]:
    return replace(self, success_schema=schema.__codec__())  # pyright: ignore[reportReturnType]

set_error

set_error[E1](schema) -> Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]
ParameterTypeDescription
schemaCodec[E1, Any, Never, Never]

Returns Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]

def set_error[E1](
    self, schema: Codec[E1, Any, Never, Never], /
) -> Rpc[P_co, S_co, E1, M_co, MT_co, Tag_co]:
    return replace(self, error_schema=schema.__codec__())  # pyright: ignore[reportReturnType]

set_payload

set_payload[P1](schema) -> Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]
ParameterTypeDescription
schemaCodec[P1, Any, Never, Never]

Returns Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]

def set_payload[P1](
    self, schema: Codec[P1, Any, Never, Never], /
) -> Rpc[P1, S_co, E_co, M_co, MT_co, Tag_co]:
    return replace(self, payload_schema=schema.__codec__())  # pyright: ignore[reportReturnType]

prefix

prefix(prefix) -> Rpc[P_co, S_co, E_co, M_co, MT_co]

This RPC with prefix before its tag (typed str: Python can't join Literal types).

ParameterTypeDescription
prefixstr

Returns Rpc[P_co, S_co, E_co, M_co, MT_co]

def prefix(self, prefix: str) -> Rpc[P_co, S_co, E_co, M_co, MT_co]:
    """This RPC with ``prefix`` before its tag (typed ``str``: Python can't
    join ``Literal`` types)."""
    return replace(self, tag=prefix + self.tag)

annotate

annotate[A, T](tag, value) -> Self
ParameterTypeDescription
tagTagLike[A, T]
valueA

Returns Self

def annotate[A, T](self, tag: TagLike[A, T], value: A) -> Self:
    return replace(self, annotations=self.annotations.add(tag, value))

annotate_merge

annotate_merge(annotations) -> Self
ParameterTypeDescription
annotationsContext[Any]

Returns Self

def annotate_merge(self, annotations: Context[Any]) -> Self:
    return replace(self, annotations=self.annotations.merge(annotations))

with_middleware

with_middleware(middleware) -> Self

This RPC wrapped by middleware (untyped: middleware types it).

ParameterTypeDescription
middlewareAnyMiddleware

Returns Self

def with_middleware(self, middleware: AnyMiddleware) -> Self:
    """This RPC wrapped by ``middleware`` (untyped: ``middleware`` types it)."""
    if middleware in self.middlewares:
        return self
    return replace(self, middlewares=(*self.middlewares, middleware))

pipe

pipe[B](f) -> B
ParameterTypeDescription
fCallable[[Self], B]

Returns B

def pipe[B](self, f: Callable[[Self], B], /) -> B:
    return f(self)