viam-sdk 0.3.0__py3-none-linux_armv6l.whl → 0.66.0__py3-none-linux_armv6l.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 (452) hide show
  1. viam/__init__.py +29 -2
  2. viam/app/_logs.py +34 -0
  3. viam/app/app_client.py +2696 -0
  4. viam/app/billing_client.py +185 -0
  5. viam/app/data_client.py +2231 -0
  6. viam/app/ml_training_client.py +249 -0
  7. viam/app/provisioning_client.py +93 -0
  8. viam/app/viam_client.py +275 -0
  9. viam/components/arm/__init__.py +3 -26
  10. viam/components/arm/arm.py +123 -8
  11. viam/components/arm/client.py +37 -24
  12. viam/components/arm/service.py +35 -32
  13. viam/components/audio_in/__init__.py +24 -0
  14. viam/components/audio_in/audio_in.py +74 -0
  15. viam/components/audio_in/client.py +76 -0
  16. viam/components/audio_in/service.py +83 -0
  17. viam/components/audio_out/__init__.py +21 -0
  18. viam/components/audio_out/audio_out.py +72 -0
  19. viam/components/audio_out/client.py +67 -0
  20. viam/components/audio_out/service.py +63 -0
  21. viam/components/base/__init__.py +6 -11
  22. viam/components/base/base.py +134 -8
  23. viam/components/base/client.py +51 -23
  24. viam/components/base/service.py +33 -30
  25. viam/components/board/__init__.py +3 -12
  26. viam/components/board/board.py +247 -91
  27. viam/components/board/client.py +149 -83
  28. viam/components/board/service.py +63 -33
  29. viam/components/button/__init__.py +10 -0
  30. viam/components/button/button.py +41 -0
  31. viam/components/button/client.py +52 -0
  32. viam/components/button/service.py +46 -0
  33. viam/components/camera/__init__.py +3 -3
  34. viam/components/camera/camera.py +62 -27
  35. viam/components/camera/client.py +59 -27
  36. viam/components/camera/service.py +42 -65
  37. viam/components/component_base.py +28 -5
  38. viam/components/encoder/__init__.py +1 -1
  39. viam/components/encoder/client.py +25 -14
  40. viam/components/encoder/encoder.py +48 -10
  41. viam/components/encoder/service.py +14 -18
  42. viam/components/gantry/__init__.py +1 -13
  43. viam/components/gantry/client.py +80 -25
  44. viam/components/gantry/gantry.py +123 -9
  45. viam/components/gantry/service.py +51 -29
  46. viam/components/generic/__init__.py +1 -1
  47. viam/components/generic/client.py +21 -8
  48. viam/components/generic/generic.py +10 -2
  49. viam/components/generic/service.py +12 -7
  50. viam/components/gripper/__init__.py +3 -13
  51. viam/components/gripper/client.py +69 -21
  52. viam/components/gripper/gripper.py +123 -3
  53. viam/components/gripper/service.py +44 -22
  54. viam/components/input/__init__.py +1 -14
  55. viam/components/input/client.py +55 -23
  56. viam/components/input/input.py +106 -3
  57. viam/components/input/service.py +16 -21
  58. viam/components/motor/__init__.py +1 -21
  59. viam/components/motor/client.py +56 -33
  60. viam/components/motor/motor.py +127 -4
  61. viam/components/motor/service.py +33 -44
  62. viam/components/movement_sensor/__init__.py +1 -1
  63. viam/components/movement_sensor/client.py +102 -45
  64. viam/components/movement_sensor/movement_sensor.py +130 -61
  65. viam/components/movement_sensor/service.py +38 -41
  66. viam/components/pose_tracker/__init__.py +1 -1
  67. viam/components/pose_tracker/client.py +18 -7
  68. viam/components/pose_tracker/pose_tracker.py +4 -2
  69. viam/components/pose_tracker/service.py +12 -10
  70. viam/components/power_sensor/__init__.py +17 -0
  71. viam/components/power_sensor/client.py +86 -0
  72. viam/components/power_sensor/power_sensor.py +104 -0
  73. viam/components/power_sensor/service.py +72 -0
  74. viam/components/sensor/__init__.py +2 -1
  75. viam/components/sensor/client.py +26 -10
  76. viam/components/sensor/sensor.py +22 -4
  77. viam/components/sensor/service.py +20 -11
  78. viam/components/servo/__init__.py +1 -13
  79. viam/components/servo/client.py +47 -21
  80. viam/components/servo/service.py +15 -22
  81. viam/components/servo/servo.py +61 -2
  82. viam/components/switch/__init__.py +10 -0
  83. viam/components/switch/client.py +83 -0
  84. viam/components/switch/service.py +72 -0
  85. viam/components/switch/switch.py +98 -0
  86. viam/errors.py +10 -0
  87. viam/gen/app/agent/v1/agent_grpc.py +29 -0
  88. viam/gen/app/agent/v1/agent_pb2.py +47 -0
  89. viam/gen/app/agent/v1/agent_pb2.pyi +280 -0
  90. viam/gen/app/cloudslam/v1/__init__.py +0 -0
  91. viam/gen/app/cloudslam/v1/cloud_slam_grpc.py +70 -0
  92. viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +54 -0
  93. viam/gen/app/cloudslam/v1/cloud_slam_pb2.pyi +384 -0
  94. viam/gen/app/data/v1/data_grpc.py +197 -8
  95. viam/gen/app/data/v1/data_pb2.py +238 -99
  96. viam/gen/app/data/v1/data_pb2.pyi +1222 -259
  97. viam/gen/app/datapipelines/__init__.py +0 -0
  98. viam/gen/app/datapipelines/v1/__init__.py +0 -0
  99. viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
  100. viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +57 -0
  101. viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +387 -0
  102. viam/gen/app/dataset/__init__.py +0 -0
  103. viam/gen/app/dataset/v1/__init__.py +0 -0
  104. viam/gen/app/dataset/v1/dataset_grpc.py +68 -0
  105. viam/gen/app/dataset/v1/dataset_pb2.py +44 -0
  106. viam/gen/app/dataset/v1/dataset_pb2.pyi +214 -0
  107. viam/gen/app/datasync/v1/data_sync_grpc.py +21 -4
  108. viam/gen/app/datasync/v1/data_sync_pb2.py +62 -128
  109. viam/gen/app/datasync/v1/data_sync_pb2.pyi +156 -199
  110. viam/gen/app/mlinference/__init__.py +0 -0
  111. viam/gen/app/mlinference/v1/__init__.py +0 -0
  112. viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
  113. viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
  114. viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
  115. viam/gen/app/mltraining/v1/ml_training_grpc.py +51 -3
  116. viam/gen/app/mltraining/v1/ml_training_pb2.py +135 -58
  117. viam/gen/app/mltraining/v1/ml_training_pb2.pyi +328 -39
  118. viam/gen/app/packages/v1/packages_grpc.py +15 -1
  119. viam/gen/app/packages/v1/packages_pb2.py +44 -64
  120. viam/gen/app/packages/v1/packages_pb2.pyi +75 -85
  121. viam/gen/app/v1/app_grpc.py +644 -3
  122. viam/gen/app/v1/app_pb2.py +695 -295
  123. viam/gen/app/v1/app_pb2.pyi +4488 -635
  124. viam/gen/app/v1/billing_grpc.py +53 -11
  125. viam/gen/app/v1/billing_pb2.py +94 -39
  126. viam/gen/app/v1/billing_pb2.pyi +391 -191
  127. viam/gen/app/v1/end_user_grpc.py +59 -0
  128. viam/gen/app/v1/end_user_pb2.py +55 -0
  129. viam/gen/app/v1/end_user_pb2.pyi +181 -0
  130. viam/gen/app/v1/robot_grpc.py +16 -1
  131. viam/gen/app/v1/robot_pb2.py +122 -94
  132. viam/gen/app/v1/robot_pb2.pyi +463 -123
  133. viam/gen/common/v1/common_pb2.py +87 -58
  134. viam/gen/common/v1/common_pb2.pyi +456 -149
  135. viam/gen/component/arm/v1/arm_grpc.py +58 -2
  136. viam/gen/component/arm/v1/arm_pb2.py +68 -51
  137. viam/gen/component/arm/v1/arm_pb2.pyi +108 -42
  138. viam/gen/component/audioin/__init__.py +0 -0
  139. viam/gen/component/audioin/v1/__init__.py +0 -0
  140. viam/gen/component/audioin/v1/audioin_grpc.py +54 -0
  141. viam/gen/component/audioin/v1/audioin_pb2.py +34 -0
  142. viam/gen/component/audioin/v1/audioin_pb2.pyi +94 -0
  143. viam/gen/component/audioinput/v1/audioinput_grpc.py +25 -2
  144. viam/gen/component/audioinput/v1/audioinput_pb2.py +36 -31
  145. viam/gen/component/audioinput/v1/audioinput_pb2.pyi +22 -22
  146. viam/gen/component/audioout/__init__.py +0 -0
  147. viam/gen/component/audioout/v1/__init__.py +0 -0
  148. viam/gen/component/audioout/v1/audioout_grpc.py +54 -0
  149. viam/gen/component/audioout/v1/audioout_pb2.py +32 -0
  150. viam/gen/component/audioout/v1/audioout_pb2.pyi +47 -0
  151. viam/gen/component/base/v1/base_grpc.py +42 -2
  152. viam/gen/component/base/v1/base_pb2.py +58 -47
  153. viam/gen/component/base/v1/base_pb2.pyi +65 -30
  154. viam/gen/component/board/v1/board_grpc.py +59 -7
  155. viam/gen/component/board/v1/board_pb2.py +94 -73
  156. viam/gen/component/board/v1/board_pb2.pyi +165 -68
  157. viam/gen/component/button/__init__.py +0 -0
  158. viam/gen/component/button/v1/__init__.py +0 -0
  159. viam/gen/component/button/v1/button_grpc.py +38 -0
  160. viam/gen/component/button/v1/button_pb2.py +28 -0
  161. viam/gen/component/button/v1/button_pb2.pyi +39 -0
  162. viam/gen/component/camera/v1/camera_grpc.py +38 -2
  163. viam/gen/component/camera/v1/camera_pb2.py +60 -43
  164. viam/gen/component/camera/v1/camera_pb2.pyi +191 -37
  165. viam/gen/component/encoder/v1/encoder_grpc.py +25 -2
  166. viam/gen/component/encoder/v1/encoder_pb2.py +36 -31
  167. viam/gen/component/encoder/v1/encoder_pb2.pyi +15 -15
  168. viam/gen/component/gantry/v1/gantry_grpc.py +47 -2
  169. viam/gen/component/gantry/v1/gantry_pb2.py +56 -43
  170. viam/gen/component/gantry/v1/gantry_pb2.pyi +67 -31
  171. viam/gen/component/generic/v1/generic_grpc.py +16 -2
  172. viam/gen/component/generic/v1/generic_pb2.py +16 -11
  173. viam/gen/component/gripper/v1/gripper_grpc.py +44 -2
  174. viam/gen/component/gripper/v1/gripper_pb2.py +48 -35
  175. viam/gen/component/gripper/v1/gripper_pb2.pyi +62 -24
  176. viam/gen/component/inputcontroller/v1/input_controller_grpc.py +28 -2
  177. viam/gen/component/inputcontroller/v1/input_controller_pb2.py +46 -41
  178. viam/gen/component/inputcontroller/v1/input_controller_pb2.pyi +32 -36
  179. viam/gen/component/motor/v1/motor_grpc.py +51 -2
  180. viam/gen/component/motor/v1/motor_pb2.py +78 -67
  181. viam/gen/component/motor/v1/motor_pb2.pyi +75 -46
  182. viam/gen/component/movementsensor/v1/movementsensor_grpc.py +48 -2
  183. viam/gen/component/movementsensor/v1/movementsensor_pb2.py +70 -63
  184. viam/gen/component/movementsensor/v1/movementsensor_pb2.pyi +84 -57
  185. viam/gen/component/posetracker/v1/pose_tracker_grpc.py +19 -2
  186. viam/gen/component/posetracker/v1/pose_tracker_pb2.py +26 -21
  187. viam/gen/component/posetracker/v1/pose_tracker_pb2.pyi +9 -13
  188. viam/gen/component/powersensor/__init__.py +0 -0
  189. viam/gen/component/powersensor/v1/__init__.py +0 -0
  190. viam/gen/component/powersensor/v1/powersensor_grpc.py +62 -0
  191. viam/gen/component/powersensor/v1/powersensor_pb2.py +42 -0
  192. viam/gen/component/powersensor/v1/powersensor_pb2.pyi +124 -0
  193. viam/gen/component/sensor/v1/sensor_grpc.py +21 -5
  194. viam/gen/component/sensor/v1/sensor_pb2.py +18 -22
  195. viam/gen/component/sensor/v1/sensor_pb2.pyi +1 -69
  196. viam/gen/component/servo/v1/servo_grpc.py +28 -2
  197. viam/gen/component/servo/v1/servo_pb2.py +42 -37
  198. viam/gen/component/servo/v1/servo_pb2.pyi +22 -26
  199. viam/gen/component/switch/__init__.py +0 -0
  200. viam/gen/component/switch/v1/__init__.py +0 -0
  201. viam/gen/component/switch/v1/switch_grpc.py +54 -0
  202. viam/gen/component/switch/v1/switch_pb2.py +40 -0
  203. viam/gen/component/switch/v1/switch_pb2.pyi +116 -0
  204. viam/gen/component/testecho/v1/testecho_grpc.py +15 -0
  205. viam/gen/component/testecho/v1/testecho_pb2.py +29 -26
  206. viam/gen/component/testecho/v1/testecho_pb2.pyi +16 -20
  207. viam/gen/module/v1/module_grpc.py +18 -0
  208. viam/gen/module/v1/module_pb2.py +36 -33
  209. viam/gen/module/v1/module_pb2.pyi +39 -34
  210. viam/gen/opentelemetry/__init__.py +0 -0
  211. viam/gen/opentelemetry/proto/__init__.py +0 -0
  212. viam/gen/opentelemetry/proto/common/__init__.py +0 -0
  213. viam/gen/opentelemetry/proto/common/v1/__init__.py +0 -0
  214. viam/gen/opentelemetry/proto/common/v1/common_grpc.py +0 -0
  215. viam/gen/opentelemetry/proto/common/v1/common_pb2.py +27 -0
  216. viam/gen/opentelemetry/proto/common/v1/common_pb2.pyi +208 -0
  217. viam/gen/opentelemetry/proto/resource/__init__.py +0 -0
  218. viam/gen/opentelemetry/proto/resource/v1/__init__.py +0 -0
  219. viam/gen/opentelemetry/proto/resource/v1/resource_grpc.py +0 -0
  220. viam/gen/opentelemetry/proto/resource/v1/resource_pb2.py +18 -0
  221. viam/gen/opentelemetry/proto/resource/v1/resource_pb2.pyi +59 -0
  222. viam/gen/opentelemetry/proto/trace/__init__.py +0 -0
  223. viam/gen/opentelemetry/proto/trace/v1/__init__.py +0 -0
  224. viam/gen/opentelemetry/proto/trace/v1/trace_grpc.py +0 -0
  225. viam/gen/opentelemetry/proto/trace/v1/trace_pb2.py +37 -0
  226. viam/gen/opentelemetry/proto/trace/v1/trace_pb2.pyi +402 -0
  227. viam/gen/proto/rpc/examples/echo/v1/echo_grpc.py +12 -0
  228. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +25 -22
  229. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.pyi +13 -17
  230. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_grpc.py +12 -0
  231. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +23 -20
  232. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.pyi +13 -17
  233. viam/gen/proto/rpc/v1/auth_grpc.py +11 -0
  234. viam/gen/proto/rpc/v1/auth_pb2.py +27 -24
  235. viam/gen/proto/rpc/v1/auth_pb2.pyi +12 -16
  236. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +35 -32
  237. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.pyi +37 -41
  238. viam/gen/proto/rpc/webrtc/v1/signaling_grpc.py +15 -0
  239. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +62 -57
  240. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +78 -69
  241. viam/gen/provisioning/__init__.py +0 -0
  242. viam/gen/provisioning/v1/__init__.py +0 -0
  243. viam/gen/provisioning/v1/provisioning_grpc.py +59 -0
  244. viam/gen/provisioning/v1/provisioning_pb2.py +45 -0
  245. viam/gen/provisioning/v1/provisioning_pb2.pyi +229 -0
  246. viam/gen/robot/v1/robot_grpc.py +144 -15
  247. viam/gen/robot/v1/robot_pb2.py +193 -119
  248. viam/gen/robot/v1/robot_pb2.pyi +565 -137
  249. viam/gen/service/datamanager/v1/data_manager_grpc.py +20 -2
  250. viam/gen/service/datamanager/v1/data_manager_pb2.py +27 -17
  251. viam/gen/service/datamanager/v1/data_manager_pb2.pyi +52 -10
  252. viam/gen/service/discovery/__init__.py +0 -0
  253. viam/gen/service/discovery/v1/__init__.py +0 -0
  254. viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
  255. viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
  256. viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
  257. viam/gen/service/generic/__init__.py +0 -0
  258. viam/gen/service/generic/v1/__init__.py +0 -0
  259. viam/gen/service/generic/v1/generic_grpc.py +29 -0
  260. viam/gen/service/generic/v1/generic_pb2.py +21 -0
  261. viam/gen/service/generic/v1/generic_pb2.pyi +6 -0
  262. viam/gen/service/mlmodel/v1/mlmodel_grpc.py +9 -0
  263. viam/gen/service/mlmodel/v1/mlmodel_pb2.py +76 -29
  264. viam/gen/service/mlmodel/v1/mlmodel_pb2.pyi +307 -28
  265. viam/gen/service/motion/v1/motion_grpc.py +42 -4
  266. viam/gen/service/motion/v1/motion_pb2.py +119 -51
  267. viam/gen/service/motion/v1/motion_pb2.pyi +595 -120
  268. viam/gen/service/navigation/v1/navigation_grpc.py +49 -1
  269. viam/gen/service/navigation/v1/navigation_pb2.py +76 -51
  270. viam/gen/service/navigation/v1/navigation_pb2.pyi +188 -33
  271. viam/gen/service/sensors/v1/sensors_grpc.py +12 -0
  272. viam/gen/service/sensors/v1/sensors_pb2.py +60 -29
  273. viam/gen/service/sensors/v1/sensors_pb2.pyi +18 -21
  274. viam/gen/service/shell/v1/shell_grpc.py +27 -1
  275. viam/gen/service/shell/v1/shell_pb2.py +37 -15
  276. viam/gen/service/shell/v1/shell_pb2.pyi +260 -7
  277. viam/gen/service/slam/v1/slam_grpc.py +24 -2
  278. viam/gen/service/slam/v1/slam_pb2.py +44 -30
  279. viam/gen/service/slam/v1/slam_pb2.pyi +128 -27
  280. viam/gen/service/video/__init__.py +0 -0
  281. viam/gen/service/video/v1/__init__.py +0 -0
  282. viam/gen/service/video/v1/video_grpc.py +39 -0
  283. viam/gen/service/video/v1/video_pb2.py +29 -0
  284. viam/gen/service/video/v1/video_pb2.pyi +72 -0
  285. viam/gen/service/vision/v1/vision_grpc.py +39 -1
  286. viam/gen/service/vision/v1/vision_pb2.py +61 -45
  287. viam/gen/service/vision/v1/vision_pb2.pyi +180 -41
  288. viam/gen/service/worldstatestore/__init__.py +0 -0
  289. viam/gen/service/worldstatestore/v1/__init__.py +0 -0
  290. viam/gen/service/worldstatestore/v1/world_state_store_grpc.py +55 -0
  291. viam/gen/service/worldstatestore/v1/world_state_store_pb2.py +39 -0
  292. viam/gen/service/worldstatestore/v1/world_state_store_pb2.pyi +171 -0
  293. viam/gen/stream/__init__.py +0 -0
  294. viam/gen/stream/v1/__init__.py +0 -0
  295. viam/gen/stream/v1/stream_grpc.py +59 -0
  296. viam/gen/stream/v1/stream_pb2.py +39 -0
  297. viam/gen/stream/v1/stream_pb2.pyi +161 -0
  298. viam/gen/tagger/v1/tagger_pb2.py +9 -8
  299. viam/logging.py +160 -17
  300. viam/media/__init__.py +0 -9
  301. viam/media/audio.py +22 -10
  302. viam/media/utils/__init__.py +0 -0
  303. viam/media/utils/pil/__init__.py +55 -0
  304. viam/media/{viam_rgba_plugin.py → utils/pil/viam_rgba_plugin.py} +10 -16
  305. viam/media/viam_rgba.py +10 -0
  306. viam/media/video.py +197 -73
  307. viam/module/module.py +191 -44
  308. viam/module/resource_data_consumer.py +41 -0
  309. viam/module/service.py +9 -1
  310. viam/module/types.py +4 -5
  311. viam/operations.py +4 -3
  312. viam/proto/app/__init__.py +361 -5
  313. viam/proto/app/agent/__init__.py +28 -0
  314. viam/proto/app/billing.py +51 -27
  315. viam/proto/app/cloudslam/__init__.py +48 -0
  316. viam/proto/app/data/__init__.py +103 -17
  317. viam/proto/app/datapipelines/__init__.py +56 -0
  318. viam/proto/app/dataset/__init__.py +40 -0
  319. viam/proto/app/datasync/__init__.py +11 -5
  320. viam/proto/app/end_user.py +34 -0
  321. viam/proto/app/mlinference/__init__.py +15 -0
  322. viam/proto/app/mltraining/__init__.py +25 -1
  323. viam/proto/app/packages/__init__.py +3 -3
  324. viam/proto/app/robot.py +19 -1
  325. viam/proto/common/__init__.py +35 -8
  326. viam/proto/component/arm/__init__.py +9 -1
  327. viam/proto/component/audioin/__init__.py +16 -0
  328. viam/proto/component/audioinput/__init__.py +3 -1
  329. viam/proto/component/audioout/__init__.py +15 -0
  330. viam/proto/component/base/__init__.py +7 -1
  331. viam/proto/component/board/__init__.py +13 -5
  332. viam/proto/component/button/__init__.py +15 -0
  333. viam/proto/component/camera/__init__.py +9 -1
  334. viam/proto/component/encoder/__init__.py +3 -1
  335. viam/proto/component/gantry/__init__.py +7 -1
  336. viam/proto/component/generic/__init__.py +3 -1
  337. viam/proto/component/gripper/__init__.py +7 -1
  338. viam/proto/component/inputcontroller/__init__.py +7 -1
  339. viam/proto/component/motor/__init__.py +7 -1
  340. viam/proto/component/movementsensor/__init__.py +7 -1
  341. viam/proto/component/posetracker/__init__.py +7 -1
  342. viam/proto/component/powersensor/__init__.py +30 -0
  343. viam/proto/component/sensor/__init__.py +3 -4
  344. viam/proto/component/servo/__init__.py +3 -1
  345. viam/proto/component/switch/__init__.py +26 -0
  346. viam/proto/component/testecho/__init__.py +3 -1
  347. viam/proto/module/__init__.py +3 -1
  348. viam/proto/opentelemetry/__init__.py +0 -0
  349. viam/proto/opentelemetry/proto/__init__.py +0 -0
  350. viam/proto/opentelemetry/proto/common/__init__.py +15 -0
  351. viam/proto/opentelemetry/proto/resource/__init__.py +10 -0
  352. viam/proto/opentelemetry/proto/trace/__init__.py +15 -0
  353. viam/proto/provisioning/__init__.py +42 -0
  354. viam/proto/robot/__init__.py +57 -9
  355. viam/proto/rpc/auth.py +11 -1
  356. viam/proto/rpc/examples/echo/__init__.py +3 -1
  357. viam/proto/rpc/examples/echoresource/__init__.py +7 -1
  358. viam/proto/rpc/webrtc/grpc.py +3 -1
  359. viam/proto/rpc/webrtc/signaling.py +5 -1
  360. viam/proto/service/datamanager/__init__.py +15 -2
  361. viam/proto/service/discovery/__init__.py +15 -0
  362. viam/proto/service/generic/__init__.py +12 -0
  363. viam/proto/service/mlmodel/__init__.py +27 -1
  364. viam/proto/service/motion/__init__.py +35 -5
  365. viam/proto/service/navigation/__init__.py +19 -1
  366. viam/proto/service/sensors/__init__.py +3 -1
  367. viam/proto/service/shell/__init__.py +25 -2
  368. viam/proto/service/slam/__init__.py +13 -1
  369. viam/proto/service/video/__init__.py +15 -0
  370. viam/proto/service/vision/__init__.py +11 -1
  371. viam/proto/service/worldstatestore/__init__.py +32 -0
  372. viam/proto/stream/__init__.py +36 -0
  373. viam/py.typed +0 -0
  374. viam/resource/base.py +45 -8
  375. viam/resource/easy_resource.py +149 -0
  376. viam/resource/manager.py +35 -14
  377. viam/resource/registry.py +40 -52
  378. viam/resource/rpc_client_base.py +33 -1
  379. viam/resource/rpc_service_base.py +15 -8
  380. viam/resource/types.py +39 -26
  381. viam/robot/client.py +458 -91
  382. viam/robot/service.py +13 -107
  383. viam/rpc/dial.py +133 -15
  384. viam/rpc/libviam_rust_utils.so +0 -0
  385. viam/rpc/server.py +59 -15
  386. viam/rpc/types.py +2 -4
  387. viam/services/discovery/__init__.py +12 -0
  388. viam/services/discovery/client.py +55 -0
  389. viam/services/discovery/discovery.py +52 -0
  390. viam/services/discovery/service.py +43 -0
  391. viam/services/generic/__init__.py +18 -0
  392. viam/services/generic/client.py +58 -0
  393. viam/services/generic/generic.py +58 -0
  394. viam/services/generic/service.py +29 -0
  395. viam/services/mlmodel/__init__.py +15 -1
  396. viam/services/mlmodel/client.py +20 -15
  397. viam/services/mlmodel/mlmodel.py +44 -7
  398. viam/services/mlmodel/service.py +9 -13
  399. viam/services/mlmodel/utils.py +101 -0
  400. viam/services/motion/__init__.py +15 -3
  401. viam/services/motion/client.py +109 -150
  402. viam/services/motion/motion.py +380 -0
  403. viam/services/motion/service.py +132 -0
  404. viam/services/navigation/__init__.py +11 -0
  405. viam/services/navigation/client.py +99 -0
  406. viam/services/navigation/navigation.py +250 -0
  407. viam/services/navigation/service.py +137 -0
  408. viam/services/service_base.py +43 -4
  409. viam/services/service_client_base.py +4 -4
  410. viam/services/slam/__init__.py +4 -1
  411. viam/services/slam/client.py +21 -11
  412. viam/services/slam/service.py +16 -19
  413. viam/services/slam/slam.py +66 -5
  414. viam/services/vision/__init__.py +8 -0
  415. viam/services/vision/client.py +115 -111
  416. viam/services/vision/service.py +143 -0
  417. viam/services/vision/vision.py +317 -0
  418. viam/services/worldstatestore/__init__.py +18 -0
  419. viam/services/worldstatestore/client.py +94 -0
  420. viam/services/worldstatestore/service.py +55 -0
  421. viam/services/worldstatestore/worldstatestore.py +90 -0
  422. viam/sessions_client.py +254 -0
  423. viam/streams.py +44 -0
  424. viam/utils.py +143 -15
  425. viam/version_metadata.py +4 -0
  426. viam_sdk-0.66.0.dist-info/METADATA +157 -0
  427. viam_sdk-0.66.0.dist-info/RECORD +531 -0
  428. {viam_sdk-0.3.0.dist-info → viam_sdk-0.66.0.dist-info}/WHEEL +1 -1
  429. viam/components/audio_input/__init__.py +0 -18
  430. viam/components/audio_input/audio_input.py +0 -79
  431. viam/components/audio_input/client.py +0 -60
  432. viam/components/audio_input/service.py +0 -118
  433. viam/components/types.py +0 -5
  434. viam/gen/app/model/v1/model_grpc.py +0 -39
  435. viam/gen/app/model/v1/model_pb2.py +0 -71
  436. viam/gen/app/model/v1/model_pb2.pyi +0 -285
  437. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_grpc.py +0 -21
  438. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.py +0 -18
  439. viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.pyi +0 -49
  440. viam/media/media.py +0 -53
  441. viam/proto/app/model/__init__.py +0 -40
  442. viam/proto/rpc/examples/fileupload/__init__.py +0 -13
  443. viam/services/sensors/__init__.py +0 -5
  444. viam/services/sensors/client.py +0 -63
  445. viam_sdk-0.3.0.dist-info/LICENSE +0 -202
  446. viam_sdk-0.3.0.dist-info/METADATA +0 -122
  447. viam_sdk-0.3.0.dist-info/RECORD +0 -372
  448. /viam/{gen/app/model → app}/__init__.py +0 -0
  449. /viam/gen/app/{model/v1 → agent}/__init__.py +0 -0
  450. /viam/gen/{proto/rpc/examples/fileupload → app/agent/v1}/__init__.py +0 -0
  451. /viam/gen/{proto/rpc/examples/fileupload/v1 → app/cloudslam}/__init__.py +0 -0
  452. /LICENSE → /viam_sdk-0.66.0.dist-info/licenses/LICENSE +0 -0
@@ -0,0 +1,43 @@
1
+ from grpclib.server import Stream
2
+
3
+ from viam.proto.common import DoCommandRequest, DoCommandResponse
4
+ from viam.proto.service.discovery import (
5
+ DiscoverResourcesRequest,
6
+ DiscoverResourcesResponse,
7
+ UnimplementedDiscoveryServiceBase,
8
+ )
9
+ from viam.resource.rpc_service_base import ResourceRPCServiceBase
10
+ from viam.utils import dict_to_struct, struct_to_dict
11
+
12
+ from .discovery import Discovery
13
+
14
+
15
+ class DiscoveryRPCService(UnimplementedDiscoveryServiceBase, ResourceRPCServiceBase):
16
+ """
17
+ gRPC service for a Discovery service
18
+ """
19
+
20
+ RESOURCE_TYPE = Discovery
21
+
22
+ async def DiscoverResources(self, stream: Stream[DiscoverResourcesRequest, DiscoverResourcesResponse]) -> None:
23
+ request = await stream.recv_message()
24
+ assert request is not None
25
+ discovery = self.get_resource(request.name)
26
+ extra = struct_to_dict(request.extra)
27
+ timeout = stream.deadline.time_remaining() if stream.deadline else None
28
+ result = await discovery.discover_resources(
29
+ extra=extra,
30
+ timeout=timeout,
31
+ )
32
+ response = DiscoverResourcesResponse(
33
+ discoveries=result,
34
+ )
35
+ await stream.send_message(response)
36
+
37
+ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -> None:
38
+ request = await stream.recv_message()
39
+ assert request is not None
40
+ discovery = self.get_resource(request.name)
41
+ timeout = stream.deadline.time_remaining() if stream.deadline else None
42
+ result = await discovery.do_command(struct_to_dict(request.command), timeout=timeout)
43
+ await stream.send_message(DoCommandResponse(result=dict_to_struct(result)))
@@ -0,0 +1,18 @@
1
+ import viam.gen.service.generic.v1.generic_pb2 # Need this import for Generic service descriptors to resolve
2
+ from viam.resource.registry import Registry, ResourceRegistration
3
+
4
+ from .client import GenericClient
5
+ from .generic import Generic
6
+ from .service import GenericRPCService
7
+
8
+ __all__ = [
9
+ "Generic",
10
+ ]
11
+
12
+ Registry.register_api(
13
+ ResourceRegistration(
14
+ Generic,
15
+ GenericRPCService,
16
+ lambda name, channel: GenericClient(name, channel),
17
+ )
18
+ )
@@ -0,0 +1,58 @@
1
+ from typing import Any, Mapping, Optional
2
+
3
+ from grpclib import GRPCError, Status
4
+ from grpclib.client import Channel
5
+
6
+ from viam.proto.common import DoCommandRequest, DoCommandResponse
7
+ from viam.proto.service.generic import GenericServiceStub
8
+ from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase, ResourceRPCClientBase
9
+ from viam.utils import ValueTypes, dict_to_struct, struct_to_dict
10
+
11
+ from .generic import Generic
12
+
13
+
14
+ class GenericClient(Generic, ReconfigurableResourceRPCClientBase):
15
+ """
16
+ gRPC client for the Generic service.
17
+ """
18
+
19
+ def __init__(self, name: str, channel: Channel):
20
+ self.channel = channel
21
+ self.client = GenericServiceStub(channel)
22
+ super().__init__(name)
23
+
24
+ async def do_command(
25
+ self,
26
+ command: Mapping[str, Any],
27
+ *,
28
+ timeout: Optional[float] = None,
29
+ **kwargs,
30
+ ) -> Mapping[str, Any]:
31
+ md = kwargs.get("metadata", self.Metadata()).proto
32
+ request = DoCommandRequest(name=self.name, command=dict_to_struct(command))
33
+ try:
34
+ response: DoCommandResponse = await self.client.DoCommand(request, timeout=timeout, metadata=md)
35
+ except GRPCError as e:
36
+ if e.status == Status.UNIMPLEMENTED:
37
+ raise NotImplementedError()
38
+ raise e
39
+
40
+ return struct_to_dict(response.result)
41
+
42
+
43
+ async def do_command(
44
+ channel: Channel, name: str, command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs
45
+ ) -> Mapping[str, ValueTypes]:
46
+ """Convenience method to allow service clients to execute ``do_command`` functions
47
+
48
+ Args:
49
+ channel (Channel): A gRPC channel
50
+ name (str): The name of the component
51
+ command (Dict[str, Any]): The command to execute
52
+
53
+ Returns:
54
+ Dict[str, Any]: The result of the executed command
55
+ """
56
+ md = kwargs.get("metadata", ResourceRPCClientBase.Metadata()).proto
57
+ client = GenericClient(name, channel)
58
+ return await client.do_command(command, timeout=timeout, metadata=md)
@@ -0,0 +1,58 @@
1
+ from typing import Final
2
+
3
+ from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE
4
+
5
+ from ..service_base import ServiceBase
6
+
7
+
8
+ class Generic(ServiceBase):
9
+ """
10
+ Generic service, which represents any type of service that can execute arbitrary commands
11
+
12
+ This acts as an abstract base class for any drivers representing generic services.
13
+ This cannot be used on its own. If the ``__init__()`` function is overridden, it must call the ``super().__init__()`` function.
14
+
15
+ To create a Generic service (an arbitrary service that can process commands), this ``Generic`` service should be subclassed
16
+ and the ``do_command`` function implemented.
17
+
18
+ Example::
19
+
20
+ class ComplexService(Generic):
21
+
22
+ async def do_command(
23
+ self,
24
+ command: Mapping[str, ValueTypes],
25
+ *,
26
+ timeout: Optional[float] = None,
27
+ **kwargs
28
+ ) -> Mapping[str, ValueTypes]:
29
+ result = {key: False for key in command.keys()}
30
+ for (name, args) in command.items():
31
+ if name == 'set_val':
32
+ self.set_val(*args)
33
+ result[name] = True
34
+ if name == 'get_val':
35
+ result[name] = self.val
36
+ if name == 'complex_command':
37
+ self.complex_command(*args)
38
+ result[name] = True
39
+ return result
40
+
41
+ def set_val(self, val: int):
42
+ self.val = val
43
+
44
+ def complex_command(self, arg1, arg2, arg3):
45
+ ...
46
+
47
+ To execute commands, simply call the ``do_command`` function with the appropriate parameters.
48
+ ::
49
+
50
+ await service.do_command({'set_val': 10})
51
+ service.val # 10
52
+ await service.do_command({'set_val': 5})
53
+ service.val # 5
54
+ """
55
+
56
+ API: Final = API( # pyright: ignore [reportIncompatibleVariableOverride]
57
+ RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE, "generic"
58
+ )
@@ -0,0 +1,29 @@
1
+ from grpclib import GRPCError, Status
2
+ from grpclib.server import Stream
3
+
4
+ from viam.proto.common import DoCommandRequest, DoCommandResponse
5
+ from viam.proto.service.generic import GenericServiceBase
6
+ from viam.resource.rpc_service_base import ResourceRPCServiceBase
7
+ from viam.services.service_base import ServiceBase
8
+ from viam.utils import dict_to_struct, struct_to_dict
9
+
10
+
11
+ class GenericRPCService(GenericServiceBase, ResourceRPCServiceBase):
12
+ """
13
+ gRPC Service for a Generic service
14
+ """
15
+
16
+ RESOURCE_TYPE = ServiceBase
17
+
18
+ async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -> None:
19
+ request = await stream.recv_message()
20
+ assert request is not None
21
+ name = request.name
22
+ service = self.get_resource(name)
23
+ try:
24
+ timeout = stream.deadline.time_remaining() if stream.deadline else None
25
+ result = await service.do_command(struct_to_dict(request.command), timeout=timeout, metadata=stream.metadata)
26
+ except NotImplementedError:
27
+ raise GRPCError(Status.UNIMPLEMENTED, f"``DO`` command is unimplemented for service named: {name}")
28
+ response = DoCommandResponse(result=dict_to_struct(result))
29
+ await stream.send_message(response)
@@ -1,3 +1,17 @@
1
+ try:
2
+ import numpy
3
+ except ImportError:
4
+ import warnings
5
+
6
+ warnings.warn(
7
+ (
8
+ """MLModel support in the Viam Python SDK requires the installation of an
9
+ additional dependency: numpy. Update your package using the extra [mlmodel]
10
+ for example `pip install viam-sdk[mlmodel]` or the equivalent update in your dependency manager."""
11
+ ),
12
+ )
13
+ raise
14
+
1
15
  from viam.proto.service.mlmodel import File, LabelType, Metadata, TensorInfo
2
16
  from viam.resource.registry import Registry, ResourceRegistration
3
17
 
@@ -7,4 +21,4 @@ from .service import MLModelRPCService
7
21
 
8
22
  __all__ = ["File", "LabelType", "Metadata", "MLModel", "MLModelClient", "TensorInfo"]
9
23
 
10
- Registry.register_subtype(ResourceRegistration(MLModel, MLModelRPCService, lambda name, channel: MLModelClient(name, channel)))
24
+ Registry.register_api(ResourceRegistration(MLModel, MLModelRPCService, lambda name, channel: MLModelClient(name, channel)))
@@ -1,11 +1,12 @@
1
1
  from typing import Dict, Mapping, Optional
2
2
 
3
3
  from grpclib.client import Channel
4
+ from numpy.typing import NDArray
4
5
 
5
- from viam.proto.common import DoCommandRequest, DoCommandResponse
6
6
  from viam.proto.service.mlmodel import InferRequest, InferResponse, MetadataRequest, MetadataResponse, MLModelServiceStub
7
7
  from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase
8
- from viam.utils import ValueTypes, dict_to_struct, struct_to_dict
8
+ from viam.services.mlmodel.utils import flat_tensors_to_ndarrays, ndarrays_to_flat_tensors
9
+ from viam.utils import ValueTypes, dict_to_struct
9
10
 
10
11
  from .mlmodel import Metadata, MLModel
11
12
 
@@ -16,17 +17,21 @@ class MLModelClient(MLModel, ReconfigurableResourceRPCClientBase):
16
17
  self.client = MLModelServiceStub(channel)
17
18
  super().__init__(name)
18
19
 
19
- async def infer(self, input_data: Dict[str, ValueTypes], *, timeout: Optional[float] = None) -> Dict[str, ValueTypes]:
20
- request = InferRequest(name=self.name, input_data=dict_to_struct(input_data))
21
- response: InferResponse = await self.client.Infer(request)
22
- return struct_to_dict(response.output_data)
23
-
24
- async def metadata(self, *, timeout: Optional[float] = None) -> Metadata:
25
- request = MetadataRequest(name=self.name)
26
- response: MetadataResponse = await self.client.Metadata(request)
20
+ async def infer(
21
+ self,
22
+ input_tensors: Dict[str, NDArray],
23
+ *,
24
+ extra: Optional[Mapping[str, ValueTypes]] = None,
25
+ timeout: Optional[float] = None,
26
+ **kwargs,
27
+ ) -> Dict[str, NDArray]:
28
+ md = kwargs.get("metadata", self.Metadata()).proto
29
+ request = InferRequest(name=self.name, input_tensors=ndarrays_to_flat_tensors(input_tensors), extra=dict_to_struct(extra))
30
+ response: InferResponse = await self.client.Infer(request, timeout=timeout, metadata=md)
31
+ return flat_tensors_to_ndarrays(response.output_tensors)
32
+
33
+ async def metadata(self, *, extra: Optional[Mapping[str, ValueTypes]] = None, timeout: Optional[float] = None, **kwargs) -> Metadata:
34
+ md = kwargs.get("metadata", self.Metadata()).proto
35
+ request = MetadataRequest(name=self.name, extra=dict_to_struct(extra))
36
+ response: MetadataResponse = await self.client.Metadata(request, timeout=timeout, metadata=md)
27
37
  return response.metadata
28
-
29
- async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) -> Mapping[str, ValueTypes]:
30
- request = DoCommandRequest(name=self.name, command=dict_to_struct(command))
31
- response: DoCommandResponse = await self.client.DoCommand(request, tiemout=timeout)
32
- return struct_to_dict(response.result)
@@ -1,8 +1,10 @@
1
1
  import abc
2
- from typing import Dict, Final, Optional
2
+ from typing import Dict, Final, Mapping, Optional
3
+
4
+ from numpy.typing import NDArray
3
5
 
4
6
  from viam.proto.service.mlmodel import Metadata
5
- from viam.resource.types import RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE, Subtype
7
+ from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE
6
8
  from viam.utils import ValueTypes
7
9
 
8
10
  from ..service_base import ServiceBase
@@ -15,27 +17,62 @@ class MLModel(ServiceBase):
15
17
  This acts as an abstract base class for any drivers representing specific
16
18
  arm implementations. This cannot be used on its own. If the ``__init__()`` function is
17
19
  overridden, it must call the ``super().__init__()`` function.
20
+
21
+ For more information, see `ML model service <https://docs.viam.com/dev/reference/apis/services/ml/>`_.
18
22
  """
19
23
 
20
- SUBTYPE: Final = Subtype(RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE, "mlmodel")
24
+ API: Final = API( # pyright: ignore [reportIncompatibleVariableOverride]
25
+ RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_SERVICE, "mlmodel"
26
+ )
21
27
 
22
28
  @abc.abstractmethod
23
- async def infer(self, input_data: Dict[str, ValueTypes], *, timeout: Optional[float]) -> Dict[str, ValueTypes]:
29
+ async def infer(
30
+ self,
31
+ input_tensors: Dict[str, NDArray],
32
+ *,
33
+ extra: Optional[Mapping[str, ValueTypes]] = None,
34
+ timeout: Optional[float] = None,
35
+ ) -> Dict[str, NDArray]:
24
36
  """Take an already ordered input tensor as an array, make an inference on the model, and return an output tensor map.
25
37
 
38
+ ::
39
+
40
+ import numpy as np
41
+
42
+ my_mlmodel = MLModelClient.from_robot(robot=machine, name="my_mlmodel_service")
43
+
44
+ image_data = np.zeros((1, 384, 384, 3), dtype=np.uint8)
45
+
46
+ # Create the input tensors dictionary
47
+ input_tensors = {
48
+ "image": image_data
49
+ }
50
+
51
+ output_tensors = await my_mlmodel.infer(input_tensors)
52
+
26
53
  Args:
27
- input_data (Dict[str, ValueTypes]): A dictionary of input arrays/tensors as specified in the metadata
54
+ input_tensors (Dict[str, NDArray]): A dictionary of input flat tensors as specified in the metadata
28
55
 
29
56
  Returns:
30
- Dict[str, ValueTypes]: A dictionary of output arrays/tensors as specified in the metadata
57
+ Dict[str, NDArray]: A dictionary of output flat tensors as specified in the metadata
58
+
59
+ For more information, see `ML model service <https://docs.viam.com/dev/reference/apis/services/ml/#infer>`_.
31
60
  """
32
61
  ...
33
62
 
34
63
  @abc.abstractmethod
35
- async def metadata(self, *, timeout: Optional[float]) -> Metadata:
64
+ async def metadata(self, *, extra: Optional[Mapping[str, ValueTypes]] = None, timeout: Optional[float] = None) -> Metadata:
36
65
  """Get the metadata (such as name, type, expected tensor/array shape, inputs, and outputs) associated with the ML model.
37
66
 
67
+ ::
68
+
69
+ my_mlmodel = MLModelClient.from_robot(robot=machine, name="my_mlmodel_service")
70
+
71
+ metadata = await my_mlmodel.metadata()
72
+
38
73
  Returns:
39
74
  Metadata: The metadata
75
+
76
+ For more information, see `ML model service <https://docs.viam.com/dev/reference/apis/services/ml/#metadata>`_.
40
77
  """
41
78
  ...
@@ -1,9 +1,9 @@
1
1
  from grpclib.server import Stream
2
2
 
3
- from viam.errors import ResourceNotFoundError
4
3
  from viam.proto.service.mlmodel import InferRequest, InferResponse, MetadataRequest, MetadataResponse, MLModelServiceBase
5
4
  from viam.resource.rpc_service_base import ResourceRPCServiceBase
6
- from viam.utils import dict_to_struct
5
+ from viam.services.mlmodel.utils import flat_tensors_to_ndarrays, ndarrays_to_flat_tensors
6
+ from viam.utils import struct_to_dict
7
7
 
8
8
  from .mlmodel import MLModel
9
9
 
@@ -19,24 +19,20 @@ class MLModelRPCService(MLModelServiceBase, ResourceRPCServiceBase):
19
19
  request = await stream.recv_message()
20
20
  assert request is not None
21
21
  name = request.name
22
- try:
23
- mlmodel = self.get_resource(name)
24
- except ResourceNotFoundError as e:
25
- raise e.grpc_error
22
+ mlmodel = self.get_resource(name)
23
+ extra = struct_to_dict(request.extra)
26
24
  timeout = stream.deadline.time_remaining() if stream.deadline else None
27
- output_data = await mlmodel.infer(input_data=request.input_data, timeout=timeout)
28
- response = InferResponse(output_data=dict_to_struct(output_data))
25
+ output_tensors = await mlmodel.infer(input_tensors=flat_tensors_to_ndarrays(request.input_tensors), extra=extra, timeout=timeout)
26
+ response = InferResponse(output_tensors=ndarrays_to_flat_tensors(output_tensors))
29
27
  await stream.send_message(response)
30
28
 
31
29
  async def Metadata(self, stream: Stream[MetadataRequest, MetadataResponse]) -> None:
32
30
  request = await stream.recv_message()
33
31
  assert request is not None
34
32
  name = request.name
35
- try:
36
- mlmodel = self.get_resource(name)
37
- except ResourceNotFoundError as e:
38
- raise e.grpc_error
33
+ mlmodel = self.get_resource(name)
34
+ extra = struct_to_dict(request.extra)
39
35
  timeout = stream.deadline.time_remaining() if stream.deadline else None
40
- metadata = await mlmodel.metadata(timeout=timeout)
36
+ metadata = await mlmodel.metadata(extra=extra, timeout=timeout)
41
37
  response = MetadataResponse(metadata=metadata)
42
38
  await stream.send_message(response)
@@ -0,0 +1,101 @@
1
+ from typing import Dict
2
+
3
+ import numpy as np
4
+ from numpy.typing import NDArray
5
+ from packaging.version import Version
6
+
7
+ from viam.proto.service.mlmodel import (
8
+ FlatTensor,
9
+ FlatTensorDataDouble,
10
+ FlatTensorDataFloat,
11
+ FlatTensorDataInt8,
12
+ FlatTensorDataInt16,
13
+ FlatTensorDataInt32,
14
+ FlatTensorDataInt64,
15
+ FlatTensorDataUInt8,
16
+ FlatTensorDataUInt16,
17
+ FlatTensorDataUInt32,
18
+ FlatTensorDataUInt64,
19
+ FlatTensors,
20
+ )
21
+
22
+
23
+ def flat_tensors_to_ndarrays(flat_tensors: FlatTensors) -> Dict[str, NDArray]:
24
+ property_name_to_dtype = {
25
+ "float_tensor": np.float32,
26
+ "double_tensor": np.float64,
27
+ "int8_tensor": np.int8,
28
+ "int16_tensor": np.int16,
29
+ "int32_tensor": np.int32,
30
+ "int64_tensor": np.int64,
31
+ "uint8_tensor": np.uint8,
32
+ "uint16_tensor": np.uint16,
33
+ "uint32_tensor": np.uint32,
34
+ "uint64_tensor": np.uint64,
35
+ }
36
+
37
+ def make_ndarray(flat_data, dtype, shape):
38
+ """Takes flat data (protobuf RepeatedScalarFieldContainer | bytes) to output an ndarray
39
+ of appropriate dtype and shape"""
40
+ make_array = np.frombuffer if dtype == np.int8 or dtype == np.uint8 else np.array
41
+ # As per proto, int16 and uint16 are stored as uint32. As of numpy v2, this creates
42
+ # some strange interactions with negative values for int16. Specifically, we end up
43
+ # trying to create an np.Int16 value with an out of bounds int due to rollover.
44
+ # Creating our array as a uint32 array initially and then casting to int16 solves this.
45
+ if Version(np.__version__) >= Version("2") and dtype == np.int16:
46
+ arr = np.astype(make_array(flat_data, np.uint32), np.int16) # pyright: ignore [reportAttributeAccessIssue]
47
+
48
+ else:
49
+ arr = make_array(flat_data, dtype)
50
+ return arr.reshape(shape)
51
+
52
+ ndarrays: Dict[str, NDArray] = dict()
53
+ for name, flat_tensor in flat_tensors.tensors.items():
54
+ property_name = flat_tensor.WhichOneof("tensor") or flat_tensor.WhichOneof(b"tensor")
55
+ if property_name:
56
+ tensor_data = getattr(flat_tensor, property_name)
57
+ flat_data, dtype, shape = tensor_data.data, property_name_to_dtype[property_name], flat_tensor.shape
58
+ ndarrays[name] = make_ndarray(flat_data, dtype, shape)
59
+ return ndarrays
60
+
61
+
62
+ def ndarrays_to_flat_tensors(ndarrays: Dict[str, NDArray]) -> FlatTensors:
63
+ dtype_name_to_tensor_data_class = {
64
+ "float32": FlatTensorDataFloat,
65
+ "float64": FlatTensorDataDouble,
66
+ "int8": FlatTensorDataInt8,
67
+ "int16": FlatTensorDataInt16,
68
+ "int32": FlatTensorDataInt32,
69
+ "int64": FlatTensorDataInt64,
70
+ "uint8": FlatTensorDataUInt8,
71
+ "uint16": FlatTensorDataUInt16,
72
+ "uint32": FlatTensorDataUInt32,
73
+ "uint64": FlatTensorDataUInt64,
74
+ }
75
+
76
+ def get_tensor_data(ndarray: NDArray):
77
+ """Takes an ndarray and returns the corresponding tensor data class instance
78
+ for example FlatTensorDataInt8, FlatTensorDataUInt8 etc."""
79
+ tensor_data_class = dtype_name_to_tensor_data_class[ndarray.dtype.name]
80
+ data = ndarray.flatten()
81
+ if tensor_data_class == FlatTensorDataInt8 or tensor_data_class == FlatTensorDataUInt8:
82
+ data = data.tobytes() # as per the proto, int8 and uint8 are stored as bytes
83
+ elif tensor_data_class == FlatTensorDataInt16 or tensor_data_class == FlatTensorDataUInt16:
84
+ data = data.astype(np.uint32) # as per the proto, int16 and uint16 are stored as uint32
85
+ tensor_data = tensor_data_class(data=data)
86
+ return tensor_data
87
+
88
+ def get_tensor_data_type(ndarray: NDArray):
89
+ """Takes ndarray and returns a FlatTensor datatype property to be set
90
+ for example "float_tensor", "uint32_tensor" etc."""
91
+ if ndarray.dtype == np.float32:
92
+ return "float_tensor"
93
+ elif ndarray.dtype == np.float64:
94
+ return "double_tensor"
95
+ return f"{ndarray.dtype.name}_tensor"
96
+
97
+ tensors_mapping: Dict[str, FlatTensor] = dict()
98
+ for name, ndarray in ndarrays.items():
99
+ prop_name, prop_value = get_tensor_data_type(ndarray), get_tensor_data(ndarray)
100
+ tensors_mapping[name] = FlatTensor(shape=ndarray.shape, **{prop_name: prop_value})
101
+ return FlatTensors(tensors=tensors_mapping)
@@ -1,5 +1,17 @@
1
+ from viam.proto.service.motion import Constraints, MotionConfiguration
2
+ from viam.resource.registry import Registry, ResourceRegistration
3
+
1
4
  from .client import MotionClient
5
+ from .motion import Motion
6
+ from .service import MotionRPCService
7
+
8
+ __all__ = ["Motion", "MotionClient", "MotionConfiguration", "Constraints"]
9
+
2
10
 
3
- __all__ = [
4
- "MotionClient",
5
- ]
11
+ Registry.register_api(
12
+ ResourceRegistration(
13
+ Motion,
14
+ MotionRPCService,
15
+ lambda name, channel: MotionClient(name, channel),
16
+ )
17
+ )