Skip to content

blackbull.grpc.registry

blackbull.grpc.registry

gRPC method registration.

Response streaming is inferred from async-generator functions; request streaming from request_iter, request_iterator, requests or request_stream. Use explicit flags when a decorator hides these forms. Handler messages are bytes; raise GrpcError or call context.abort for non-OK status.

GrpcMethod

Bases: NamedTuple

Registered handler with request and response streaming flags.

client_streaming receives an async message iterator; streaming returns one. The four flag combinations select unary, server, client or bidirectional calls.

GrpcServiceRegistry

Holds the path -> GrpcMethod table for gRPC methods.

add_method(path, handler, *, streaming=None, client_streaming=None)

Register handler for the fully-qualified method path (/package.Service/Method or package.Service/Method).

Both streaming axes default to None, meaning auto-detection — see GrpcMethod for what each axis is. Pass a bool to override it for a handler whose nature a wrapper hides. Forcing streaming False on an async-generator function is a contradiction and raises ValueError.

add_service(service, methods)

Register every method_name -> handler in methods under the fully-qualified service name (e.g. "helloworld.Greeter").

Each handler's streaming-ness is auto-detected individually.

lookup(path)

Return the handler for path, or None if unregistered.

Backwards-compatible accessor (returns just the callable); use lookup_method when the streaming flag is needed.

lookup_method(path)

Return the GrpcMethod for path, or None if unregistered.

method(path, *, streaming=None, client_streaming=None)

Decorator form of add_method.

methods()

Return all registered method paths, in registration order.