viam-sdk 0.25.2__py3-none-linux_armv7l.whl → 0.62.0__py3-none-linux_armv7l.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of viam-sdk might be problematic. Click here for more details.

Files changed (328) hide show
  1. viam/app/_logs.py +3 -6
  2. viam/app/app_client.py +606 -262
  3. viam/app/billing_client.py +60 -18
  4. viam/app/data_client.py +1086 -315
  5. viam/app/ml_training_client.py +51 -48
  6. viam/app/provisioning_client.py +3 -5
  7. viam/app/viam_client.py +105 -11
  8. viam/components/arm/__init__.py +1 -25
  9. viam/components/arm/arm.py +21 -22
  10. viam/components/arm/client.py +27 -30
  11. viam/components/arm/service.py +3 -3
  12. viam/components/audio_in/__init__.py +24 -0
  13. viam/components/audio_in/audio_in.py +74 -0
  14. viam/components/audio_in/client.py +76 -0
  15. viam/components/audio_in/service.py +83 -0
  16. viam/components/audio_input/__init__.py +1 -1
  17. viam/components/audio_input/audio_input.py +4 -3
  18. viam/components/audio_input/client.py +19 -8
  19. viam/components/audio_input/service.py +10 -0
  20. viam/components/audio_out/__init__.py +21 -0
  21. viam/components/audio_out/audio_out.py +72 -0
  22. viam/components/audio_out/client.py +67 -0
  23. viam/components/audio_out/service.py +63 -0
  24. viam/components/base/__init__.py +2 -10
  25. viam/components/base/base.py +20 -20
  26. viam/components/base/client.py +27 -30
  27. viam/components/board/__init__.py +2 -25
  28. viam/components/board/board.py +39 -77
  29. viam/components/board/client.py +39 -73
  30. viam/components/button/__init__.py +10 -0
  31. viam/components/button/button.py +41 -0
  32. viam/components/button/client.py +52 -0
  33. viam/components/button/service.py +46 -0
  34. viam/components/camera/__init__.py +1 -1
  35. viam/components/camera/camera.py +31 -22
  36. viam/components/camera/client.py +30 -20
  37. viam/components/camera/service.py +14 -12
  38. viam/components/component_base.py +10 -7
  39. viam/components/encoder/__init__.py +1 -1
  40. viam/components/encoder/client.py +15 -16
  41. viam/components/encoder/encoder.py +9 -9
  42. viam/components/gantry/__init__.py +1 -13
  43. viam/components/gantry/client.py +41 -28
  44. viam/components/gantry/gantry.py +48 -17
  45. viam/components/gantry/service.py +21 -5
  46. viam/components/generic/__init__.py +1 -1
  47. viam/components/generic/client.py +11 -7
  48. viam/components/generic/generic.py +3 -3
  49. viam/components/gripper/__init__.py +3 -12
  50. viam/components/gripper/client.py +43 -20
  51. viam/components/gripper/gripper.py +87 -12
  52. viam/components/gripper/service.py +32 -3
  53. viam/components/input/__init__.py +1 -14
  54. viam/components/input/client.py +22 -23
  55. viam/components/input/input.py +18 -12
  56. viam/components/motor/__init__.py +1 -21
  57. viam/components/motor/client.py +36 -42
  58. viam/components/motor/motor.py +24 -24
  59. viam/components/movement_sensor/__init__.py +1 -1
  60. viam/components/movement_sensor/client.py +33 -40
  61. viam/components/movement_sensor/movement_sensor.py +12 -12
  62. viam/components/pose_tracker/__init__.py +1 -1
  63. viam/components/pose_tracker/client.py +9 -8
  64. viam/components/pose_tracker/pose_tracker.py +2 -2
  65. viam/components/power_sensor/__init__.py +1 -1
  66. viam/components/power_sensor/client.py +15 -18
  67. viam/components/power_sensor/power_sensor.py +12 -12
  68. viam/components/sensor/__init__.py +1 -1
  69. viam/components/sensor/client.py +9 -8
  70. viam/components/sensor/sensor.py +5 -5
  71. viam/components/servo/__init__.py +1 -13
  72. viam/components/servo/client.py +18 -18
  73. viam/components/servo/servo.py +12 -12
  74. viam/components/switch/__init__.py +10 -0
  75. viam/components/switch/client.py +83 -0
  76. viam/components/switch/service.py +72 -0
  77. viam/components/switch/switch.py +95 -0
  78. viam/gen/app/agent/v1/agent_pb2.py +40 -29
  79. viam/gen/app/agent/v1/agent_pb2.pyi +73 -11
  80. viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +45 -42
  81. viam/gen/app/data/v1/data_grpc.py +98 -2
  82. viam/gen/app/data/v1/data_pb2.py +238 -119
  83. viam/gen/app/data/v1/data_pb2.pyi +804 -34
  84. viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
  85. viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +57 -0
  86. viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +387 -0
  87. viam/gen/app/dataset/v1/dataset_grpc.py +10 -2
  88. viam/gen/app/dataset/v1/dataset_pb2.py +38 -31
  89. viam/gen/app/dataset/v1/dataset_pb2.pyi +36 -1
  90. viam/gen/app/datasync/v1/data_sync_grpc.py +1 -1
  91. viam/gen/app/datasync/v1/data_sync_pb2.py +61 -51
  92. viam/gen/app/datasync/v1/data_sync_pb2.pyi +52 -12
  93. viam/gen/app/mlinference/__init__.py +0 -0
  94. viam/gen/app/mlinference/v1/__init__.py +0 -0
  95. viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
  96. viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
  97. viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
  98. viam/gen/app/mltraining/v1/ml_training_grpc.py +18 -2
  99. viam/gen/app/mltraining/v1/ml_training_pb2.py +134 -101
  100. viam/gen/app/mltraining/v1/ml_training_pb2.pyi +193 -7
  101. viam/gen/app/packages/v1/packages_pb2.py +43 -40
  102. viam/gen/app/v1/app_grpc.py +290 -2
  103. viam/gen/app/v1/app_pb2.py +670 -453
  104. viam/gen/app/v1/app_pb2.pyi +3133 -947
  105. viam/gen/app/v1/billing_grpc.py +34 -2
  106. viam/gen/app/v1/billing_pb2.py +94 -35
  107. viam/gen/app/v1/billing_pb2.pyi +314 -61
  108. viam/gen/app/v1/end_user_pb2.py +50 -29
  109. viam/gen/app/v1/robot_pb2.py +120 -111
  110. viam/gen/app/v1/robot_pb2.pyi +137 -15
  111. viam/gen/common/v1/common_pb2.py +86 -66
  112. viam/gen/common/v1/common_pb2.pyi +184 -8
  113. viam/gen/component/arm/v1/arm_grpc.py +18 -2
  114. viam/gen/component/arm/v1/arm_pb2.py +68 -55
  115. viam/gen/component/arm/v1/arm_pb2.pyi +73 -3
  116. viam/gen/component/audioin/__init__.py +0 -0
  117. viam/gen/component/audioin/v1/__init__.py +0 -0
  118. viam/gen/component/audioin/v1/audioin_grpc.py +54 -0
  119. viam/gen/component/audioin/v1/audioin_pb2.py +34 -0
  120. viam/gen/component/audioin/v1/audioin_pb2.pyi +94 -0
  121. viam/gen/component/audioinput/v1/audioinput_pb2.py +35 -32
  122. viam/gen/component/audioout/__init__.py +0 -0
  123. viam/gen/component/audioout/v1/__init__.py +0 -0
  124. viam/gen/component/audioout/v1/audioout_grpc.py +54 -0
  125. viam/gen/component/audioout/v1/audioout_pb2.py +32 -0
  126. viam/gen/component/audioout/v1/audioout_pb2.pyi +47 -0
  127. viam/gen/component/base/v1/base_pb2.py +57 -54
  128. viam/gen/component/board/v1/board_pb2.py +93 -90
  129. viam/gen/component/button/__init__.py +0 -0
  130. viam/gen/component/button/v1/__init__.py +0 -0
  131. viam/gen/component/button/v1/button_grpc.py +38 -0
  132. viam/gen/component/button/v1/button_pb2.py +28 -0
  133. viam/gen/component/button/v1/button_pb2.pyi +39 -0
  134. viam/gen/component/camera/v1/camera_pb2.py +58 -55
  135. viam/gen/component/camera/v1/camera_pb2.pyi +31 -7
  136. viam/gen/component/encoder/v1/encoder_pb2.py +35 -32
  137. viam/gen/component/gantry/v1/gantry_grpc.py +9 -1
  138. viam/gen/component/gantry/v1/gantry_pb2.py +56 -51
  139. viam/gen/component/generic/v1/generic_pb2.py +15 -12
  140. viam/gen/component/gripper/v1/gripper_grpc.py +18 -2
  141. viam/gen/component/gripper/v1/gripper_pb2.py +48 -37
  142. viam/gen/component/gripper/v1/gripper_pb2.pyi +43 -1
  143. viam/gen/component/inputcontroller/v1/input_controller_pb2.py +45 -42
  144. viam/gen/component/motor/v1/motor_pb2.py +77 -74
  145. viam/gen/component/movementsensor/v1/movementsensor_pb2.py +69 -66
  146. viam/gen/component/posetracker/v1/pose_tracker_pb2.py +25 -22
  147. viam/gen/component/powersensor/v1/powersensor_pb2.py +33 -30
  148. viam/gen/component/sensor/v1/sensor_pb2.py +17 -14
  149. viam/gen/component/servo/v1/servo_pb2.py +41 -38
  150. viam/gen/component/switch/__init__.py +0 -0
  151. viam/gen/component/switch/v1/__init__.py +0 -0
  152. viam/gen/component/switch/v1/switch_grpc.py +54 -0
  153. viam/gen/component/switch/v1/switch_pb2.py +40 -0
  154. viam/gen/component/switch/v1/switch_pb2.pyi +116 -0
  155. viam/gen/component/testecho/v1/testecho_pb2.py +29 -26
  156. viam/gen/module/v1/module_pb2.py +36 -33
  157. viam/gen/module/v1/module_pb2.pyi +7 -2
  158. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +26 -23
  159. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +23 -20
  160. viam/gen/proto/rpc/v1/auth_pb2.py +27 -24
  161. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +35 -32
  162. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +62 -57
  163. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +18 -4
  164. viam/gen/provisioning/v1/provisioning_grpc.py +10 -2
  165. viam/gen/provisioning/v1/provisioning_pb2.py +38 -31
  166. viam/gen/provisioning/v1/provisioning_pb2.pyi +20 -2
  167. viam/gen/robot/v1/robot_grpc.py +61 -29
  168. viam/gen/robot/v1/robot_pb2.py +186 -155
  169. viam/gen/robot/v1/robot_pb2.pyi +278 -59
  170. viam/gen/service/datamanager/v1/data_manager_grpc.py +11 -2
  171. viam/gen/service/datamanager/v1/data_manager_pb2.py +27 -17
  172. viam/gen/service/datamanager/v1/data_manager_pb2.pyi +47 -1
  173. viam/gen/service/discovery/__init__.py +0 -0
  174. viam/gen/service/discovery/v1/__init__.py +0 -0
  175. viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
  176. viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
  177. viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
  178. viam/gen/service/generic/v1/generic_pb2.py +13 -10
  179. viam/gen/service/mlmodel/v1/mlmodel_pb2.py +75 -72
  180. viam/gen/service/motion/v1/motion_pb2.py +118 -85
  181. viam/gen/service/motion/v1/motion_pb2.pyi +130 -68
  182. viam/gen/service/navigation/v1/navigation_pb2.py +75 -72
  183. viam/gen/service/sensors/v1/sensors_pb2.py +59 -56
  184. viam/gen/service/shell/v1/shell_pb2.py +35 -32
  185. viam/gen/service/slam/v1/slam_pb2.py +43 -40
  186. viam/gen/service/slam/v1/slam_pb2.pyi +1 -1
  187. viam/gen/service/video/__init__.py +0 -0
  188. viam/gen/service/video/v1/__init__.py +0 -0
  189. viam/gen/service/video/v1/video_grpc.py +39 -0
  190. viam/gen/service/video/v1/video_pb2.py +29 -0
  191. viam/gen/service/video/v1/video_pb2.pyi +72 -0
  192. viam/gen/service/vision/v1/vision_pb2.py +60 -57
  193. viam/gen/service/vision/v1/vision_pb2.pyi +28 -3
  194. viam/gen/service/worldstatestore/__init__.py +0 -0
  195. viam/gen/service/worldstatestore/v1/__init__.py +0 -0
  196. viam/gen/service/worldstatestore/v1/world_state_store_grpc.py +55 -0
  197. viam/gen/service/worldstatestore/v1/world_state_store_pb2.py +39 -0
  198. viam/gen/service/worldstatestore/v1/world_state_store_pb2.pyi +171 -0
  199. viam/gen/stream/v1/stream_grpc.py +17 -1
  200. viam/gen/stream/v1/stream_pb2.py +34 -21
  201. viam/gen/stream/v1/stream_pb2.pyi +79 -1
  202. viam/gen/tagger/v1/tagger_pb2.py +9 -8
  203. viam/logging.py +77 -18
  204. viam/media/audio.py +28 -0
  205. viam/media/utils/pil/__init__.py +7 -3
  206. viam/media/video.py +80 -17
  207. viam/module/module.py +111 -38
  208. viam/module/resource_data_consumer.py +41 -0
  209. viam/module/service.py +9 -1
  210. viam/module/types.py +2 -4
  211. viam/proto/app/__init__.py +199 -0
  212. viam/proto/app/agent/__init__.py +5 -2
  213. viam/proto/app/billing.py +31 -4
  214. viam/proto/app/cloudslam/__init__.py +1 -0
  215. viam/proto/app/data/__init__.py +63 -0
  216. viam/proto/app/datapipelines/__init__.py +56 -0
  217. viam/proto/app/dataset/__init__.py +5 -0
  218. viam/proto/app/datasync/__init__.py +3 -0
  219. viam/proto/app/end_user.py +1 -0
  220. viam/proto/app/mlinference/__init__.py +15 -0
  221. viam/proto/app/mltraining/__init__.py +13 -0
  222. viam/proto/app/packages/__init__.py +1 -0
  223. viam/proto/app/robot.py +7 -0
  224. viam/proto/common/__init__.py +15 -0
  225. viam/proto/component/arm/__init__.py +7 -0
  226. viam/proto/component/audioin/__init__.py +16 -0
  227. viam/proto/component/audioinput/__init__.py +1 -0
  228. viam/proto/component/audioout/__init__.py +15 -0
  229. viam/proto/component/base/__init__.py +1 -0
  230. viam/proto/component/board/__init__.py +1 -0
  231. viam/proto/component/button/__init__.py +15 -0
  232. viam/proto/component/camera/__init__.py +1 -0
  233. viam/proto/component/encoder/__init__.py +1 -0
  234. viam/proto/component/gantry/__init__.py +1 -0
  235. viam/proto/component/generic/__init__.py +1 -0
  236. viam/proto/component/gripper/__init__.py +5 -0
  237. viam/proto/component/inputcontroller/__init__.py +1 -0
  238. viam/proto/component/motor/__init__.py +1 -0
  239. viam/proto/component/movementsensor/__init__.py +1 -0
  240. viam/proto/component/posetracker/__init__.py +1 -0
  241. viam/proto/component/powersensor/__init__.py +1 -0
  242. viam/proto/component/sensor/__init__.py +1 -0
  243. viam/proto/component/servo/__init__.py +1 -0
  244. viam/proto/component/switch/__init__.py +26 -0
  245. viam/proto/component/testecho/__init__.py +1 -0
  246. viam/proto/module/__init__.py +1 -0
  247. viam/proto/provisioning/__init__.py +5 -0
  248. viam/proto/robot/__init__.py +29 -8
  249. viam/proto/rpc/auth.py +1 -0
  250. viam/proto/rpc/examples/echo/__init__.py +1 -0
  251. viam/proto/rpc/examples/echoresource/__init__.py +1 -0
  252. viam/proto/rpc/webrtc/grpc.py +1 -0
  253. viam/proto/rpc/webrtc/signaling.py +3 -0
  254. viam/proto/service/datamanager/__init__.py +9 -1
  255. viam/proto/service/discovery/__init__.py +15 -0
  256. viam/proto/service/generic/__init__.py +1 -0
  257. viam/proto/service/mlmodel/__init__.py +1 -0
  258. viam/proto/service/motion/__init__.py +3 -0
  259. viam/proto/service/navigation/__init__.py +1 -0
  260. viam/proto/service/sensors/__init__.py +1 -0
  261. viam/proto/service/shell/__init__.py +1 -0
  262. viam/proto/service/slam/__init__.py +1 -0
  263. viam/proto/service/video/__init__.py +15 -0
  264. viam/proto/service/vision/__init__.py +1 -0
  265. viam/proto/service/worldstatestore/__init__.py +32 -0
  266. viam/proto/stream/__init__.py +11 -0
  267. viam/py.typed +0 -0
  268. viam/resource/base.py +12 -8
  269. viam/resource/easy_resource.py +24 -13
  270. viam/resource/manager.py +6 -5
  271. viam/resource/registry.py +39 -51
  272. viam/resource/rpc_client_base.py +33 -1
  273. viam/resource/types.py +13 -14
  274. viam/robot/client.py +190 -122
  275. viam/robot/service.py +2 -50
  276. viam/rpc/dial.py +54 -4
  277. viam/rpc/libviam_rust_utils.so +0 -0
  278. viam/rpc/server.py +25 -11
  279. viam/rpc/types.py +2 -4
  280. viam/services/discovery/__init__.py +12 -0
  281. viam/services/discovery/client.py +55 -0
  282. viam/services/discovery/discovery.py +52 -0
  283. viam/services/discovery/service.py +43 -0
  284. viam/services/generic/__init__.py +1 -1
  285. viam/services/generic/client.py +8 -5
  286. viam/services/generic/generic.py +2 -2
  287. viam/services/mlmodel/__init__.py +1 -1
  288. viam/services/mlmodel/client.py +17 -7
  289. viam/services/mlmodel/mlmodel.py +23 -12
  290. viam/services/mlmodel/service.py +5 -2
  291. viam/services/mlmodel/utils.py +11 -1
  292. viam/services/motion/__init__.py +2 -2
  293. viam/services/motion/client.py +32 -32
  294. viam/services/motion/motion.py +66 -62
  295. viam/services/navigation/__init__.py +1 -1
  296. viam/services/navigation/client.py +30 -20
  297. viam/services/navigation/navigation.py +23 -23
  298. viam/services/service_base.py +13 -9
  299. viam/services/service_client_base.py +3 -3
  300. viam/services/slam/__init__.py +1 -1
  301. viam/services/slam/client.py +15 -10
  302. viam/services/slam/slam.py +11 -11
  303. viam/services/vision/__init__.py +1 -1
  304. viam/services/vision/client.py +31 -24
  305. viam/services/vision/service.py +8 -8
  306. viam/services/vision/vision.py +36 -53
  307. viam/services/worldstatestore/__init__.py +18 -0
  308. viam/services/worldstatestore/client.py +94 -0
  309. viam/services/worldstatestore/service.py +55 -0
  310. viam/services/worldstatestore/worldstatestore.py +90 -0
  311. viam/sessions_client.py +115 -46
  312. viam/streams.py +3 -6
  313. viam/utils.py +44 -14
  314. viam/version_metadata.py +4 -0
  315. {viam_sdk-0.25.2.dist-info → viam_sdk-0.62.0.dist-info}/METADATA +27 -28
  316. viam_sdk-0.62.0.dist-info/RECORD +514 -0
  317. {viam_sdk-0.25.2.dist-info → viam_sdk-0.62.0.dist-info}/WHEEL +1 -1
  318. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_grpc.py +0 -27
  319. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.py +0 -18
  320. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.pyi +0 -45
  321. viam/proto/rpc/examples/fileupload/__init__.py +0 -18
  322. viam/services/sensors/__init__.py +0 -5
  323. viam/services/sensors/client.py +0 -65
  324. viam_sdk-0.25.2.dist-info/LICENSE +0 -202
  325. viam_sdk-0.25.2.dist-info/RECORD +0 -442
  326. /viam/gen/{proto/rpc/examples/fileupload → app/datapipelines}/__init__.py +0 -0
  327. /viam/gen/{proto/rpc/examples/fileupload → app/datapipelines}/v1/__init__.py +0 -0
  328. /LICENSE → /viam_sdk-0.62.0.dist-info/licenses/LICENSE +0 -0
viam/resource/registry.py CHANGED
@@ -1,26 +1,20 @@
1
1
  from dataclasses import dataclass
2
2
  from threading import Lock
3
- from typing import TYPE_CHECKING, Any, Callable, ClassVar, Coroutine, Dict, Generic, Mapping, Type, TypeVar
3
+ from typing import TYPE_CHECKING, Callable, ClassVar, Dict, Generic, Mapping, Type, TypeVar
4
4
 
5
- from google.protobuf.struct_pb2 import Struct
6
5
  from grpclib.client import Channel
7
6
 
8
7
  from viam.errors import DuplicateResourceError, ResourceNotFoundError, ValidationError
9
- from viam.proto.robot import Status
10
8
 
11
9
  from .base import ResourceBase
12
10
 
13
11
  if TYPE_CHECKING:
14
12
  from .rpc_service_base import ResourceRPCServiceBase
15
- from .types import Model, ResourceCreator, Subtype, Validator
13
+ from .types import API, Model, ResourceCreator, Validator
16
14
 
17
15
  Resource = TypeVar("Resource", bound=ResourceBase)
18
16
 
19
17
 
20
- async def default_create_status(resource: ResourceBase) -> Status:
21
- return Status(name=resource.get_resource_name(resource.name), status=Struct())
22
-
23
-
24
18
  @dataclass
25
19
  class ResourceCreatorRegistration:
26
20
  """An object representing a resource creator to be registered.
@@ -33,7 +27,7 @@ class ResourceCreatorRegistration:
33
27
  """A function that can create a resource given a mapping of dependencies (``ResourceName`` to ``ResourceBase``
34
28
  """
35
29
 
36
- validator: "Validator" = lambda x: []
30
+ validator: "Validator" = lambda x: ([], [])
37
31
  """A function that can validate a resource and return implicit dependencies.
38
32
 
39
33
  If called without a validator function, default to a function returning an empty Sequence
@@ -63,12 +57,6 @@ class ResourceRegistration(Generic[Resource]):
63
57
  """A function that will create the RPC client for this resource
64
58
  """
65
59
 
66
- create_status: Callable[[Resource], Coroutine[Any, Any, Status]] = default_create_status
67
- """A function to create a Status object for this resource.
68
-
69
- If the resource does not provide a custom status type, the default implementation can be used.
70
- """
71
-
72
60
 
73
61
  class Registry:
74
62
  """The global registry of robotic parts.
@@ -82,44 +70,44 @@ class Registry:
82
70
  resource using ``Registry.register(...)``.
83
71
  """
84
72
 
85
- _SUBTYPES: ClassVar[Dict["Subtype", ResourceRegistration]] = {}
73
+ _APIS: ClassVar[Dict["API", ResourceRegistration]] = {}
86
74
  _RESOURCES: ClassVar[Dict[str, ResourceCreatorRegistration]] = {}
87
75
  _lock: ClassVar[Lock] = Lock()
88
76
 
89
77
  @classmethod
90
- def register_subtype(cls, registration: ResourceRegistration[Resource]):
91
- """Register a Subtype with the Registry
78
+ def register_api(cls, registration: ResourceRegistration[Resource]):
79
+ """Register a API with the Registry
92
80
 
93
81
  Args:
94
- registration (ResourceRegistration): Object containing registration data for the subtype
82
+ registration (ResourceRegistration): Object containing registration data for the API
95
83
 
96
84
  Raises:
97
- DuplicateResourceError: Raised if the Subtype to register is already in the registry
85
+ DuplicateResourceError: Raised if the API to register is already in the registry
98
86
  ValidationError: Raised if registration is missing any necessary parameters
99
87
  """
100
88
  with cls._lock:
101
- if registration.resource_type.SUBTYPE in cls._SUBTYPES:
102
- raise DuplicateResourceError(str(registration.resource_type.SUBTYPE))
89
+ if registration.resource_type.API in cls._APIS:
90
+ raise DuplicateResourceError(str(registration.resource_type.API))
103
91
 
104
92
  if registration.resource_type and registration.rpc_service and registration.create_rpc_client:
105
- cls._SUBTYPES[registration.resource_type.SUBTYPE] = registration
93
+ cls._APIS[registration.resource_type.API] = registration
106
94
  else:
107
95
  raise ValidationError("Passed resource registration does not have correct parameters")
108
96
 
109
97
  @classmethod
110
- def register_resource_creator(cls, subtype: "Subtype", model: "Model", registration: ResourceCreatorRegistration):
111
- """Register a specific ``Model`` and validator function for the specific resource ``Subtype`` with the Registry
98
+ def register_resource_creator(cls, api: "API", model: "Model", registration: ResourceCreatorRegistration):
99
+ """Register a specific ``Model`` and validator function for the specific resource ``API`` with the Registry
112
100
 
113
101
  Args:
114
- subtype (Subtype): The Subtype of the resource
102
+ api (API): The API of the resource
115
103
  model (Model): The Model of the resource
116
104
  registration (ResourceCreatorRegistration): The registration functions of the model
117
105
 
118
106
  Raises:
119
- DuplicateResourceError: Raised if the Subtype and Model pairing is already registered
107
+ DuplicateResourceError: Raised if the API and Model pairing is already registered
120
108
  ValidationError: Raised if registration does not have creator
121
109
  """
122
- key = f"{subtype}/{model}"
110
+ key = f"{api}/{model}"
123
111
  with cls._lock:
124
112
  if key in cls._RESOURCES:
125
113
  raise DuplicateResourceError(key)
@@ -130,78 +118,78 @@ class Registry:
130
118
  raise ValidationError("A creator function was not provided")
131
119
 
132
120
  @classmethod
133
- def lookup_subtype(cls, subtype: "Subtype") -> ResourceRegistration:
134
- """Lookup and retrieve a registered Subtype by its name
121
+ def lookup_api(cls, api: "API") -> ResourceRegistration:
122
+ """Lookup and retrieve a registered API by its name
135
123
 
136
124
  Args:
137
- subtype (str): The subtype of the resource
125
+ api (str): The API of the resource
138
126
 
139
127
  Raises:
140
- ResourceNotFoundError: Raised if the Subtype is not registered
128
+ ResourceNotFoundError: Raised if the API is not registered
141
129
 
142
130
  Returns:
143
131
  ResourceRegistration: The registration object of the resource
144
132
  """
145
133
  with cls._lock:
146
134
  try:
147
- return cls._SUBTYPES[subtype]
135
+ return cls._APIS[api]
148
136
  except KeyError:
149
- raise ResourceNotFoundError(subtype.resource_type, subtype.resource_subtype)
137
+ raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
150
138
 
151
139
  @classmethod
152
- def lookup_resource_creator(cls, subtype: "Subtype", model: "Model") -> "ResourceCreator":
153
- """Lookup and retrieve a registered resource creator by its subtype and model
140
+ def lookup_resource_creator(cls, api: "API", model: "Model") -> "ResourceCreator":
141
+ """Lookup and retrieve a registered resource creator by its API and model
154
142
 
155
143
  Args:
156
- subtype (Subtype): The Subtype of the resource
144
+ api (API): The API of the resource
157
145
  model (Model): The Model of the resource
158
146
 
159
147
  Raises:
160
- ResourceNotFoundError: Raised if the Subtype Model pairing is not registered
148
+ ResourceNotFoundError: Raised if the API Model pairing is not registered
161
149
 
162
150
  Returns:
163
151
  ResourceCreator: The function to create the resource
164
152
  """
165
153
  with cls._lock:
166
154
  try:
167
- return cls._RESOURCES[f"{subtype}/{model}"].creator
155
+ return cls._RESOURCES[f"{api}/{model}"].creator
168
156
  except KeyError:
169
- raise ResourceNotFoundError(subtype.resource_type, subtype.resource_subtype)
157
+ raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
170
158
 
171
159
  @classmethod
172
- def lookup_validator(cls, subtype: "Subtype", model: "Model") -> "Validator":
173
- """Lookup and retrieve a registered validator function by its subtype and model. If there is none, return None
160
+ def lookup_validator(cls, api: "API", model: "Model") -> "Validator":
161
+ """Lookup and retrieve a registered validator function by its API and model. If there is none, return None
174
162
 
175
163
  Args:
176
- subtype (Subtype): The Subtype of the resource
164
+ api (API): The API of the resource
177
165
  model (Model): The Model of the resource
178
166
 
179
167
  Returns:
180
168
  Validator: The function to validate the resource
181
169
  """
182
170
  try:
183
- return cls._RESOURCES[f"{subtype}/{model}"].validator
171
+ return cls._RESOURCES[f"{api}/{model}"].validator
184
172
  except AttributeError:
185
- return lambda x: []
173
+ return lambda x: ([], [])
186
174
  except KeyError:
187
- raise ResourceNotFoundError(subtype.resource_type, subtype.resource_subtype)
175
+ raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
188
176
 
189
177
  @classmethod
190
- def REGISTERED_SUBTYPES(cls) -> Mapping["Subtype", ResourceRegistration]:
178
+ def REGISTERED_APIS(cls) -> Mapping["API", ResourceRegistration]:
191
179
  """The dictionary of all registered resources
192
- - Key: Subtype of the resource
180
+ - Key: API of the resource
193
181
  - Value: The registration object for the resource
194
182
 
195
183
  Returns:
196
- Mapping[Subtype, ResourceRegistration]: All registered resources
184
+ Mapping[API, ResourceRegistration]: All registered resources
197
185
  """
198
186
  with cls._lock:
199
- return cls._SUBTYPES.copy()
187
+ return cls._APIS.copy()
200
188
 
201
189
  @classmethod
202
190
  def REGISTERED_RESOURCE_CREATORS(cls) -> Mapping[str, "ResourceCreatorRegistration"]:
203
191
  """The dictionary of all registered resources
204
- - Key: subtype/model
192
+ - Key: API/model
205
193
  - Value: The ResourceCreatorRegistration for the resource
206
194
 
207
195
  Returns:
@@ -1,4 +1,6 @@
1
- from typing import Any, Protocol, runtime_checkable
1
+ from random import choice
2
+ from string import ascii_lowercase
3
+ from typing import Any, Dict, Protocol, runtime_checkable
2
4
 
3
5
  from grpclib.client import Channel
4
6
 
@@ -12,6 +14,36 @@ class ResourceRPCClientBase(Protocol):
12
14
  Resource RPC clients must inherit from this class
13
15
  """
14
16
 
17
+ class Metadata:
18
+ metadata: Dict[str, str] = {}
19
+
20
+ def enable_debug_logging(self, key: str = ""):
21
+ """Enables server-side debug logging for resource methods.
22
+
23
+ Args:
24
+ key (str): The key to associate debug logs with. If not provided, will default to a randomly generated string value.
25
+ """
26
+ if key == "":
27
+ key = "".join(choice(ascii_lowercase) for i in range(6))
28
+ self.metadata["dtname"] = key
29
+
30
+ def disable_debug_logging(self):
31
+ """Disables server-side debug logging for resource methods."""
32
+ del self.metadata["dtname"]
33
+
34
+ def add_metadata(self, key: str, value: str):
35
+ """Adds a key-value pair to the metadata"""
36
+ self.metadata[key] = value
37
+
38
+ def delete_metadata(self, key: str):
39
+ """Removes a key-value pair from the metadata by key"""
40
+ del self.metadata[key]
41
+
42
+ @property
43
+ def proto(self):
44
+ """Returns metadata in a gRPC-appropriate form"""
45
+ return [(k, v) for k, v in self.metadata.items()]
46
+
15
47
  channel: Channel
16
48
  client: Any
17
49
 
viam/resource/types.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import re
2
2
  import sys
3
- from typing import TYPE_CHECKING, Callable, ClassVar, Mapping, Optional, Protocol, Sequence, runtime_checkable
3
+ from typing import TYPE_CHECKING, Callable, ClassVar, Mapping, Optional, Protocol, Sequence, Tuple, runtime_checkable
4
4
 
5
5
  if sys.version_info >= (3, 10):
6
6
  from typing import TypeAlias
@@ -20,7 +20,7 @@ RESOURCE_TYPE_COMPONENT = "component"
20
20
  RESOURCE_TYPE_SERVICE = "service"
21
21
 
22
22
 
23
- class Subtype:
23
+ class API:
24
24
  """Represents a known component/service (resource) API"""
25
25
 
26
26
  namespace: str
@@ -41,45 +41,45 @@ class Subtype:
41
41
  return f"{self.namespace}:{self.resource_type}:{self.resource_subtype}"
42
42
 
43
43
  def __repr__(self) -> str:
44
- return f"<viam.resource.types.Subtype {str(self)} at {hex(id(self))}>"
44
+ return f"<viam.resource.types.API {str(self)} at {hex(id(self))}>"
45
45
 
46
46
  def __hash__(self) -> int:
47
47
  return hash(str(self))
48
48
 
49
49
  def __eq__(self, other: object) -> bool:
50
- if isinstance(other, Subtype):
50
+ if isinstance(other, API):
51
51
  return str(self) == str(other)
52
52
  return False
53
53
 
54
54
  @classmethod
55
55
  def from_resource_name(cls, resource_name: ResourceName) -> Self:
56
- """Convert a ```ResourceName``` into a ```Subtype```
56
+ """Convert a ```ResourceName``` into a ```API```
57
57
 
58
58
  Args:
59
59
  resource_name (viam.proto.common.ResourceName): The ResourceName to convert
60
60
 
61
61
  Returns:
62
- Self: A new Subtype
62
+ Self: A new API
63
63
  """
64
64
  return cls(resource_name.namespace, resource_name.type, resource_name.subtype)
65
65
 
66
66
  @classmethod
67
67
  def from_string(cls, string: str) -> Self:
68
- """Create a ```Subtype``` from its string representation (namespace:resource_type:resource_subtype)
68
+ """Create a ```API``` from its string representation (namespace:resource_type:resource_subtype)
69
69
 
70
70
  Args:
71
- string (str): The Subtype as a string
71
+ string (str): The API as a string
72
72
 
73
73
  Raises:
74
- ValueError: Raised if the string does not represent a valid Subtype
74
+ ValueError: Raised if the string does not represent a valid API
75
75
 
76
76
  Returns:
77
- Self: A new Subtype
77
+ Self: A new API
78
78
  """
79
79
  regex = re.compile(r"^([\w-]+):([\w-]+):([\w-]+)$")
80
80
  match = regex.match(string)
81
81
  if not match:
82
- raise ValueError(f"{string} is not a valid Subtype")
82
+ raise ValueError(f"{string} is not a valid API")
83
83
  return cls(match.group(1), match.group(2), match.group(3))
84
84
 
85
85
 
@@ -203,12 +203,11 @@ def resource_name_from_string(string: str) -> ResourceName:
203
203
 
204
204
 
205
205
  ResourceCreator: TypeAlias = Callable[[ComponentConfig, Mapping[ResourceName, "ResourceBase"]], "ResourceBase"]
206
- Validator: TypeAlias = Callable[[ComponentConfig], Sequence[str]]
206
+ Validator: TypeAlias = Callable[[ComponentConfig], Tuple[Sequence[str], Sequence[str]]]
207
207
 
208
208
 
209
209
  @runtime_checkable
210
210
  class SupportsGetGeometries(Protocol):
211
211
  """The SupportsGetGeometries protocol defines the requirements for a resource to call get_geometries."""
212
212
 
213
- async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None) -> GetGeometriesResponse:
214
- ...
213
+ async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None, **kwargs) -> GetGeometriesResponse: ...