viam.resource.registry
Attributes
Classes
An object representing a resource creator to be registered. |
|
An object representing a resource to be registered. |
|
The global registry of robotic parts. |
Module Contents
- viam.resource.registry.Resource
- class viam.resource.registry.ResourceCreatorRegistration[source]
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 theRegistry
.- creator: viam.resource.types.ResourceCreator
A function that can create a resource given a mapping of dependencies (
ResourceName
toResourceBase
- validator: 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
- class viam.resource.registry.ResourceRegistration[source]
Bases:
Generic
[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 theRegistry
.- resource_type: Type[Resource]
The type of the Resource to be registered
- rpc_service: Type[viam.resource.rpc_service_base.ResourceRPCServiceBase]
The type of the RPC service of the resource. This must extend from
RPCServiceBase
- create_rpc_client: Callable[[str, grpclib.client.Channel], Resource]
A function that will create the RPC client for this resource
- class viam.resource.registry.Registry[source]
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 (for example 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(...)
.- classmethod register_subtype(registration: ResourceRegistration[Resource])[source]
Register a Subtype with the Registry
- Parameters:
registration (ResourceRegistration) – Object containing registration data for the subtype
- Raises:
DuplicateResourceError – Raised if the Subtype to register is already in the registry
ValidationError – Raised if registration is missing any necessary parameters
- classmethod register_resource_creator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model, registration: ResourceCreatorRegistration)[source]
Register a specific
Model
and validator function for the specific resourceSubtype
with the Registry- Parameters:
subtype (Subtype) – The Subtype of the resource
model (Model) – The Model of the resource
registration (ResourceCreatorRegistration) – The registration functions of the model
- Raises:
DuplicateResourceError – Raised if the Subtype and Model pairing is already registered
ValidationError – Raised if registration does not have creator
- classmethod lookup_subtype(subtype: viam.resource.types.Subtype) ResourceRegistration [source]
Lookup and retrieve a registered Subtype by its name
- Parameters:
subtype (str) – The subtype of the resource
- Raises:
ResourceNotFoundError – Raised if the Subtype is not registered
- Returns:
The registration object of the resource
- Return type:
- classmethod lookup_resource_creator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model) viam.resource.types.ResourceCreator [source]
Lookup and retrieve a registered resource creator by its subtype and model
- Parameters:
- Raises:
ResourceNotFoundError – Raised if the Subtype Model pairing is not registered
- Returns:
The function to create the resource
- Return type:
ResourceCreator
- classmethod lookup_validator(subtype: viam.resource.types.Subtype, model: viam.resource.types.Model) viam.resource.types.Validator [source]
Lookup and retrieve a registered validator function by its subtype and model. If there is none, return None
- classmethod REGISTERED_SUBTYPES() Mapping[viam.resource.types.Subtype, ResourceRegistration] [source]
The dictionary of all registered resources - Key: Subtype of the resource - Value: The registration object for the resource
- Returns:
All registered resources
- Return type:
Mapping[Subtype, ResourceRegistration]
- classmethod REGISTERED_RESOURCE_CREATORS() Mapping[str, ResourceCreatorRegistration] [source]
The dictionary of all registered resources - Key: subtype/model - Value: The ResourceCreatorRegistration for the resource
- Returns:
All registered resources
- Return type:
Mapping[str, ResourceCreatorRegistration]