django_socio_grpc.grpc_actions.actions

MyMixin(GRPCActionMixin, ): … @grpc_action(request=[], response=[]) … def MyDecoratedAction(self, request, context): … pass … … def MyAction(self, request, context): … pass … … def _dynamic_grpc_action_registry(service): … return { … “MyAction”: {request=[], request_name=service.req_name, response=[]} … } … … def _before_registration(service): … service.req_name = service.name

MyService(MyMixin): … @grpc_action(request=[], response=[]) … def MyServiceAction(self, request, context): … pass … … @grpc_action(request=[], response=[]) … def MySecondServiceAction(self, request, context): … pass … … def _before_registration(service): … service.req_name = “MyReqName”

GRPCAction registration lifecycle on class definition :

—> MyService parents and MyService _before_registration methods are called. with MyService as the argument. —> MyService parents and MyService _dynamic_grpc_action_registry methods are called with MyService as the argument and their returned dict is merged with decorated actions data from MyService abstract parents. This dict is then registered.

Module Contents

Classes

GRPCAction

GRPCActionMixin

Functions

register_action

Register action function_name of mixin and register them if they are decorated (so already a GRPCAction) or transform them into a GRPCAction before registering them

Data

logger

RequestResponseType

API

django_socio_grpc.grpc_actions.actions.logger

‘getLogger(…)’

django_socio_grpc.grpc_actions.actions.RequestResponseType

None

class django_socio_grpc.grpc_actions.actions.GRPCAction
function: collections.abc.Callable[[django_socio_grpc.services.Service, Any, django_socio_grpc.request_transformer.grpc_internal_proxy.GRPCInternalProxyContext], Any]

None

request: django_socio_grpc.grpc_actions.actions.RequestResponseType | None

None

response: django_socio_grpc.grpc_actions.actions.RequestResponseType | None

None

request_name: str | None

None

response_name: str | None

None

request_stream: bool

False

response_stream: bool

False

message_name_constructor_class: type[django_socio_grpc.protobuf.message_name_constructor.MessageNameConstructor]

None

use_generation_plugins: list[django_socio_grpc.protobuf.generation_plugin.BaseGenerationPlugin]

‘field(…)’

proto_rpc: django_socio_grpc.protobuf.proto_classes.ProtoRpc | None

‘field(…)’

__post_init__()
__set_name__(owner, name)

set name function is called automatically by python and allow us to retrieve the owner(Service) instance that we need for proto registration

__hash__()
__get__(obj, type=None)
__call__(*args, **kwargs)
get_action_params()
property request_message_name: str | None
property response_message_name: str | None
make_proto_rpc(action_name: str, service: type[django_socio_grpc.services.Service]) django_socio_grpc.protobuf.proto_classes.ProtoRpc
register(owner: type[django_socio_grpc.services.Service], action_name: str)
resolve_placeholders(service_class: type[django_socio_grpc.services.Service], action: str)

Iterate over the GRPCAction attributes and resolve all the placeholder instances

Classic placeholder usage :

@grpc_action(request=MyRequestPlaceholder, response=MyResponsePlaceholder) def MyAction(self, request, context): …

MyRequestPlaceholder and MyResponsePlaceholder are placeholder instances which are resolved with the current service by this method, allowing us to set dynamic attributes to the GRPCAction.

clone(**kwargs)

Clones the current GRPCAction instance overriding the given kwargs

django_socio_grpc.grpc_actions.actions.register_action(cls, action_name: str, name: str | None = None, **kwargs)

Register action function_name of mixin and register them if they are decorated (so already a GRPCAction) or transform them into a GRPCAction before registering them

class django_socio_grpc.grpc_actions.actions.GRPCActionMixin

Bases: abc.ABC

_decorated_grpc_action_registry: dict[str, dict[str, Any]]

None

Registry of grpc actions declared in the class

proto_service: django_socio_grpc.protobuf.proto_classes.ProtoService

None

abstract classmethod get_controller_name() str
classmethod before_registration(service_class=None)

Call all the service parents _before_registration methods

classmethod get_parents_action_registry(service)

Returns all the grpc action registries (decorated and dynamic) of all the parent mixin

classmethod get_class_action_registry(service)

Returns all the grpc action registries (decorated and dynamic) of the class

classmethod get_action_parents()

Returns all the GRPCActionMixin parents of the class in mro order

classmethod register_actions()

Call the _before_registration method of all the parents Then iterate over the action registry and register the grpc actions

_before_registration()

This should be overriden in your service or mixin if you want a specific behavior for a mixin Method called before gRPC actions registration

_dynamic_grpc_action_registry() dict[str, dict[str, Any]]

Dynamic gRPC action registry