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_api(registration: ResourceRegistration[Resource])[source]

Register a API with the Registry

Parameters:

registration (ResourceRegistration) – Object containing registration data for the API

Raises:
classmethod register_resource_creator(api: viam.resource.types.API, model: viam.resource.types.Model, registration: ResourceCreatorRegistration)[source]

Register a specific Model and validator function for the specific resource API with the Registry

Parameters:
Raises:
classmethod lookup_api(api: viam.resource.types.API) ResourceRegistration[source]

Lookup and retrieve a registered API by its name

Parameters:

api (str) – The API of the resource

Raises:

ResourceNotFoundError – Raised if the API is not registered

Returns:

The registration object of the resource

Return type:

ResourceRegistration

classmethod lookup_resource_creator(api: viam.resource.types.API, model: viam.resource.types.Model) viam.resource.types.ResourceCreator[source]

Lookup and retrieve a registered resource creator by its API and model

Parameters:
  • api (API) – The API of the resource

  • model (Model) – The Model of the resource

Raises:

ResourceNotFoundError – Raised if the API Model pairing is not registered

Returns:

The function to create the resource

Return type:

ResourceCreator

classmethod lookup_validator(api: viam.resource.types.API, model: viam.resource.types.Model) viam.resource.types.Validator[source]

Lookup and retrieve a registered validator function by its API and model. If there is none, return None

Parameters:
  • api (API) – The API of the resource

  • model (Model) – The Model of the resource

Returns:

The function to validate the resource

Return type:

Validator

classmethod REGISTERED_APIS() Mapping[viam.resource.types.API, ResourceRegistration][source]

The dictionary of all registered resources - Key: API of the resource - Value: The registration object for the resource

Returns:

All registered resources

Return type:

Mapping[API, ResourceRegistration]

classmethod REGISTERED_RESOURCE_CREATORS() Mapping[str, ResourceCreatorRegistration][source]

The dictionary of all registered resources - Key: API/model - Value: The ResourceCreatorRegistration for the resource

Returns:

All registered resources

Return type:

Mapping[str, ResourceCreatorRegistration]