:py:mod:`viam.resource.registry` ================================ .. py:module:: viam.resource.registry Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: viam.resource.registry.ResourceCreatorRegistration viam.resource.registry.ResourceRegistration viam.resource.registry.Registry Functions ~~~~~~~~~ .. autoapisummary:: viam.resource.registry.default_create_status Attributes ~~~~~~~~~~ .. autoapisummary:: viam.resource.registry.Resource .. py:data:: Resource .. py:function:: default_create_status(resource: viam.resource.base.ResourceBase) -> viam.proto.robot.Status :async: .. py:class:: ResourceCreatorRegistration An object representing a resource creator to be registered. If creating a custom Resource creator, you should register the creator by creating a ``ResourceCreatorRegistration`` object and registering it to the ``Registry``. .. py:attribute:: creator :type: viam.resource.types.ResourceCreator A function that can create a resource given a mapping of dependencies (``ResourceName`` to ``ResourceBase`` .. py:attribute:: validator :type: viam.resource.types.Validator A function that can validate a resource and return implicit dependencies. If called without a validator function, default to a function returning an empty Sequence .. py:class:: ResourceRegistration Bases: :py:obj:`Generic`\ [\ :py:obj:`Resource`\ ] An object representing a resource to be registered. This object is generic over the ``ResourceBase``, and it includes various functionality for the resource, such as creating its RPC client or status. If creating a custom Resource type, you should register the resource by creating a ``ResourceRegistration`` object and registering it to the ``Registry``. .. py:attribute:: resource_type :type: Type[Resource] The type of the Resource to be registered .. py:attribute:: rpc_service :type: Type[viam.resource.rpc_service_base.ResourceRPCServiceBase] The type of the RPC service of the resource. This must extend from ``RPCServiceBase`` .. py:attribute:: create_rpc_client :type: Callable[[str, grpclib.client.Channel], Resource] A function that will create the RPC client for this resource .. py:attribute:: create_status :type: Callable[[Resource], Coroutine[Any, Any, viam.proto.robot.Status]] A function to create a Status object for this resource. If the resource does not provide a custom status type, the default implementation can be used. .. py:class:: Registry The global registry of robotic parts. **NB** The Registry should almost never be used directly The Registry keeps track of the types of Resources that are available on robots using this SDK. All the base resource types are pre-registered (e.g. Arm, Motor). If you create a new resource type that is not an extension of any of the existing base resource types, then you must register said resource using ``Registry.register(...)``. .. py:method:: register_subtype(registration: ResourceRegistration[Resource]) :classmethod: Register a Subtype with the Registry :param registration: Object containing registration data for the subtype :type registration: ResourceRegistration :raises DuplicateResourceError: Raised if the Subtype to register is already in the registry :raises ValidationError: Raised if registration is missing any necessary parameters .. py:method:: register_resource_creator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model, registration: ResourceCreatorRegistration) :classmethod: Register a specific ``Model`` and validator function for the specific resource ``Subtype`` with the Registry :param subtype: The Subtype of the resource :type subtype: Subtype :param model: The Model of the resource :type model: Model :param registration: The registration functions of the model :type registration: ResourceCreatorRegistration :raises DuplicateResourceError: Raised if the Subtype and Model pairing is already registered :raises ValidationError: Raised if registration does not have creator .. py:method:: lookup_subtype(subtype: viam.resource.types.Subtype) -> ResourceRegistration :classmethod: Lookup and retrieve a registered Subtype by its name :param subtype: The subtype of the resource :type subtype: str :raises ResourceNotFoundError: Raised if the Subtype is not registered :returns: The registration object of the resource :rtype: ResourceRegistration .. py:method:: lookup_resource_creator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model) -> viam.resource.types.ResourceCreator :classmethod: Lookup and retrieve a registered resource creator by its subtype and model :param subtype: The Subtype of the resource :type subtype: Subtype :param model: The Model of the resource :type model: Model :raises ResourceNotFoundError: Raised if the Subtype Model pairing is not registered :returns: The function to create the resource :rtype: ResourceCreator .. py:method:: lookup_validator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model) -> viam.resource.types.Validator :classmethod: Lookup and retrieve a registered validator function by its subtype and model. If there is none, return None :param subtype: The Subtype of the resource :type subtype: Subtype :param model: The Model of the resource :type model: Model :returns: The function to validate the resource :rtype: Validator .. py:method:: REGISTERED_SUBTYPES() -> Mapping[viam.resource.types.Subtype, ResourceRegistration] :classmethod: The dictionary of all registered resources - Key: Subtype of the resource - Value: The registration object for the resource :returns: All registered resources :rtype: Mapping[Subtype, ResourceRegistration] .. py:method:: REGISTERED_RESOURCE_CREATORS() -> Mapping[str, ResourceCreatorRegistration] :classmethod: The dictionary of all registered resources - Key: subtype/model - Value: The ResourceCreatorRegistration for the resource :returns: All registered resources :rtype: Mapping[str, ResourceCreatorRegistration]