viam.resource.registry

Attributes

Resource

Classes

ResourceCreatorRegistration

An object representing a resource creator to be registered.

ResourceRegistration

An object representing a resource to be registered.

Registry

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 the Registry.

creator: viam.resource.types.ResourceCreator

A function that can create a resource given a mapping of dependencies (ResourceName to ResourceBase

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 the Registry.

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:
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 resource Subtype with the Registry

Parameters:
Raises:
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:

ResourceRegistration

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:
  • subtype (Subtype) – The Subtype of the resource

  • model (Model) – The Model of the resource

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

Parameters:
  • subtype (Subtype) – The Subtype of the resource

  • model (Model) – The Model of the resource

Returns:

The function to validate the resource

Return type:

Validator

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]