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.
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
@@ -46,16 +46,14 @@ class MLTrainingClient:
46
46
  async def main():
47
47
 
48
48
  # Make a ViamClient
49
- viam_client = await connect()
50
- # Instantiate an MLTrainingClient to run ML training client API methods on
51
- ml_training_client = viam_client.ml_training_client
52
-
53
- viam_client.close()
49
+ async with await connect() as viam_client:
50
+ # Instantiate an MLTrainingClient to run ML training client API methods on
51
+ ml_training_client = viam_client.ml_training_client
54
52
 
55
53
  if __name__ == '__main__':
56
54
  asyncio.run(main())
57
55
 
58
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
56
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/>`_.
59
57
  """
60
58
 
61
59
  def __init__(self, channel: Channel, metadata: Mapping[str, str]):
@@ -65,7 +63,7 @@ class MLTrainingClient:
65
63
  channel (grpclib.client.Channel): Connection to app.
66
64
  metadata (Mapping[str, str]): Required authorization token to send requests to app.
67
65
 
68
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
66
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/>`_.
69
67
  """
70
68
  self._metadata = metadata
71
69
  self._ml_training_client = MLTrainingServiceStub(channel)
@@ -84,27 +82,29 @@ class MLTrainingClient:
84
82
 
85
83
  ::
86
84
 
85
+ from viam.proto.app.mltraining import ModelType
86
+
87
87
  job_id = await ml_training_client.submit_training_job(
88
- organization_id=organization_id,
89
- dataset_id=dataset_id,
90
- model_name="your-model-name",
88
+ org_id="<organization-id>",
89
+ dataset_id="<dataset-id>",
90
+ model_name="<your-model-name>",
91
91
  model_version="1",
92
- model_type="ModelType.MODEL_TYPE_SINGLE_LABEL_CLASSIFICATION",
93
- tags=tags
92
+ model_type=ModelType.MODEL_TYPE_SINGLE_LABEL_CLASSIFICATION,
93
+ tags=["tag1", "tag2"]
94
94
  )
95
95
 
96
96
  Args:
97
- org_id (str): the id of the org to submit the training job to
98
- dataset_id (str): the id of the dataset
99
- model_name (str): the model name
100
- model_version (str): the model version
101
- model_type (ModelType.ValueType): the model type
102
- tags (List[str]): the tags
97
+ org_id (str): the ID of the org to submit the training job to.
98
+ dataset_id (str): the ID of the dataset to train the model on.
99
+ model_name (str): the model name.
100
+ model_version (str): the model version.
101
+ model_type (ModelType.ValueType): the model type.
102
+ tags (List[str]): the labels to train the model on.
103
103
 
104
104
  Returns:
105
- str: the id of the training job
105
+ str: the ID of the training job.
106
106
 
107
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
107
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#submittrainingjob>`_.
108
108
  """
109
109
 
110
110
  request = SubmitTrainingJobRequest(
@@ -119,36 +119,39 @@ class MLTrainingClient:
119
119
  return response.id
120
120
 
121
121
  async def submit_custom_training_job(
122
- self, org_id: str, dataset_id: str, registry_item_id: str, model_name: str, model_version: str
122
+ self, org_id: str, dataset_id: str, registry_item_id: str, registry_item_version: str, model_name: str, model_version: str
123
123
  ) -> str:
124
124
  """Submit a custom training job.
125
125
 
126
126
  ::
127
127
 
128
128
  job_id = await ml_training_client.submit_custom_training_job(
129
- organization_id=organization_id,
130
- dataset_id=dataset_id,
131
- registry_item_id="your-registry-item-id",
132
- model_name="your-model-name",
129
+ org_id="<organization-id>",
130
+ dataset_id="<dataset-id>",
131
+ registry_item_id="viam:classification-tflite",
132
+ registry_item_version="2024-08-13T12-11-54",
133
+ model_name="<your-model-name>",
133
134
  model_version="1"
134
135
  )
135
136
 
136
137
  Args:
137
- org_id (str): the id of the org to submit the training job to
138
- dataset_id (str): the id of the dataset
139
- registry_item_id (List[str]): the id of the registry item
140
- model_name (str): the model name
141
- model_version (str): the model version
138
+ org_id (str): the ID of the org to submit the training job to.
139
+ dataset_id (str): the ID of the dataset to train the model on.
140
+ registry_item_id (str): the ID of the training script from the registry.
141
+ registry_item_version (str): the version of the training script from the registry.
142
+ model_name (str): the model name.
143
+ model_version (str): the model version.
142
144
 
143
145
  Returns:
144
- str: the id of the training job
146
+ str: the ID of the training job.
145
147
 
146
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
148
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#submitcustomtrainingjob>`_.
147
149
  """
148
150
 
149
151
  request = SubmitCustomTrainingJobRequest(
150
152
  dataset_id=dataset_id,
151
153
  registry_item_id=registry_item_id,
154
+ registry_item_version=registry_item_version,
152
155
  organization_id=org_id,
153
156
  model_name=model_name,
154
157
  model_version=model_version,
@@ -162,15 +165,15 @@ class MLTrainingClient:
162
165
  ::
163
166
 
164
167
  job_metadata = await ml_training_client.get_training_job(
165
- id="INSERT YOUR JOB ID")
168
+ id="<job-id>")
166
169
 
167
170
  Args:
168
- id (str): the id of the requested training job.
171
+ id (str): the ID of the requested training job.
169
172
 
170
173
  Returns:
171
- viam.proto.app.mltraining.TrainingJobMetadata: training job data.
174
+ viam.proto.app.mltraining.TrainingJobMetadata: the training job data.
172
175
 
173
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
176
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#gettrainingjob>`_.
174
177
  """
175
178
 
176
179
  request = GetTrainingJobRequest(id=id)
@@ -188,19 +191,19 @@ class MLTrainingClient:
188
191
  ::
189
192
 
190
193
  jobs_metadata = await ml_training_client.list_training_jobs(
191
- org_id="INSERT YOUR ORG ID")
194
+ org_id="<org-id>")
192
195
 
193
196
  first_job_id = jobs_metadata[1].id
194
197
 
195
198
  Args:
196
- org_id (str): the id of the org to request training job data from.
197
- training_status (Optional[TrainingStatus]): status of training jobs to filter the list by.
199
+ org_id (str): the ID of the org to request training job data from.
200
+ training_status (Optional[TrainingStatus]): the status to filter the training jobs list by.
198
201
  If unspecified, all training jobs will be returned.
199
202
 
200
203
  Returns:
201
- List[viam.proto.app.mltraining.TrainingJobMetadata]: a list of training job data.
204
+ List[viam.proto.app.mltraining.TrainingJobMetadata]: the list of training job data.
202
205
 
203
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
206
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#listtrainingjobs>`_.
204
207
  """
205
208
 
206
209
  training_status = training_status if training_status else TrainingStatus.TRAINING_STATUS_UNSPECIFIED
@@ -215,15 +218,15 @@ class MLTrainingClient:
215
218
  ::
216
219
 
217
220
  await ml_training_client.cancel_training_job(
218
- id="INSERT YOUR JOB ID")
221
+ id="<job-id>")
219
222
 
220
223
  Args:
221
- id (str): the id of the job to be canceled.
224
+ id (str): the ID of the job to cancel.
222
225
 
223
226
  Raises:
224
- GRPCError: if no training job exists with the given id.
227
+ GRPCError: if no training job exists with the given ID.
225
228
 
226
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
229
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#canceltrainingjob>`_.
227
230
  """
228
231
 
229
232
  request = CancelTrainingJobRequest(id=id)
@@ -235,12 +238,12 @@ class MLTrainingClient:
235
238
  ::
236
239
 
237
240
  await ml_training_client.delete_completed_training_job(
238
- id="INSERT YOUR JOB ID")
241
+ id="<job-id>")
239
242
 
240
243
  Args:
241
- id (str): the id of the training job
244
+ id (str): the ID of the training job to delete.
242
245
 
243
- For more information, see `ML Training Client API <https://docs.viam.com/appendix/apis/ml-training-client/>`_.
246
+ For more information, see `ML Training Client API <https://docs.viam.com/dev/reference/apis/ml-training-client/#deletecompletedtrainingjob>`_.
244
247
  """
245
248
  request = DeleteCompletedTrainingJobRequest(id=id)
246
249
  await self._ml_training_client.DeleteCompletedTrainingJob(request, metadata=self._metadata)
@@ -41,11 +41,9 @@ class ProvisioningClient:
41
41
  async def main():
42
42
 
43
43
  # Make a ViamClient
44
- viam_client = await connect()
45
- # Instantiate a ProvisioningClient to run provisioning client API methods on
46
- provisioning_client = viam_client.provisioning_client
47
-
48
- viam_client.close()
44
+ async with await connect() as viam_client:
45
+ # Instantiate a ProvisioningClient to run provisioning client API methods on
46
+ provisioning_client = viam_client.provisioning_client
49
47
 
50
48
  if __name__ == '__main__':
51
49
  asyncio.run(main())
viam/app/viam_client.py CHANGED
@@ -1,4 +1,5 @@
1
- from typing import Mapping, Optional
1
+ import os
2
+ from typing import Any, Mapping, Optional
2
3
 
3
4
  from grpclib.client import Channel
4
5
  from typing_extensions import Self
@@ -9,7 +10,8 @@ from viam.app.billing_client import BillingClient
9
10
  from viam.app.data_client import DataClient
10
11
  from viam.app.ml_training_client import MLTrainingClient
11
12
  from viam.app.provisioning_client import ProvisioningClient
12
- from viam.rpc.dial import DialOptions, _dial_app, _get_access_token
13
+ from viam.robot.client import RobotClient
14
+ from viam.rpc.dial import Credentials, DialOptions, _dial_app, _get_access_token
13
15
 
14
16
  LOGGER = logging.getLogger(__name__)
15
17
 
@@ -18,19 +20,51 @@ class ViamClient:
18
20
  """gRPC client for all communication and interaction with app.
19
21
 
20
22
  `ViamClient` class for creating and managing specialized client instances.
21
- There is currently 1 way to instantiate a `ViamClient` object::
23
+ There are currently 2 ways to instantiate a `ViamClient` object::
22
24
 
23
25
  ViamClient.create_from_dial_options(...)
26
+ ViamClient.create_from_env_vars()
24
27
  """
25
28
 
29
+ @classmethod
30
+ async def create_from_env_vars(cls, dial_options: Optional[DialOptions] = None, app_url: Optional[str] = None) -> Self:
31
+ """Create `ViamClient` using credentials set in the environment as `VIAM_API_KEY` and `VIAM_API_KEY_ID`.
32
+
33
+ ::
34
+
35
+ client = await ViamClient.create_from_env_vars()
36
+
37
+ Args:
38
+ dial_options (Optional[viam.rpc.dial.DialOptions]): Options for authorization and connection to app.
39
+ If not provided, default options will be selected. Note that `creds` and `auth_entity`
40
+ fields will be overwritten by the values set by a module.
41
+ app_url: (Optional[str]): URL of app. Uses app.viam.com if not specified.
42
+
43
+ Raises:
44
+ ValueError: If there are no env vars set by the module, or if they are set improperly
45
+
46
+ """
47
+ dial_options = dial_options if dial_options else DialOptions()
48
+ api_key = os.environ.get("VIAM_API_KEY")
49
+ if api_key is None:
50
+ raise ValueError("api key cannot be None")
51
+ api_key_id = os.environ.get("VIAM_API_KEY_ID")
52
+ if api_key_id is None:
53
+ raise ValueError("api key ID cannot be None")
54
+ credentials = Credentials(type="api-key", payload=api_key)
55
+ dial_options.credentials = credentials
56
+ dial_options.auth_entity = api_key_id
57
+
58
+ return await cls.create_from_dial_options(dial_options, app_url)
59
+
26
60
  @classmethod
27
61
  async def create_from_dial_options(cls, dial_options: DialOptions, app_url: Optional[str] = None) -> Self:
28
- """Create `ViamClient` that establishes a connection to the Viam app.
62
+ """Create `ViamClient` that establishes a connection to Viam.
29
63
 
30
64
  ::
31
65
 
32
66
  dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>")
33
- ViamClient.create_from_dial_options(dial_options)
67
+ client = await ViamClient.create_from_dial_options(dial_options)
34
68
 
35
69
  Args:
36
70
  dial_options (viam.rpc.dial.DialOptions): Required information for authorization and connection to app.
@@ -51,9 +85,7 @@ class ViamClient:
51
85
  raise ValueError("dial_options.auth_entity cannot be None.")
52
86
 
53
87
  self = cls()
54
- self._location_id = None
55
- if dial_options.credentials.type == "robot-location-secret":
56
- self._location_id = dial_options.auth_entity.split(".")[1]
88
+ self._dial_options = dial_options
57
89
  if app_url is None:
58
90
  app_url = "app.viam.com"
59
91
  self._channel = await _dial_app(app_url)
@@ -64,7 +96,7 @@ class ViamClient:
64
96
  _channel: Channel
65
97
  _metadata: Mapping[str, str]
66
98
  _closed: bool = False
67
- _location_id: Optional[str]
99
+ _dial_options: DialOptions
68
100
 
69
101
  @property
70
102
  def data_client(self) -> DataClient:
@@ -105,7 +137,7 @@ class ViamClient:
105
137
  # Instantiate an AppClient called "fleet" to run fleet management API methods on
106
138
  fleet = viam_client.app_client
107
139
  """
108
- return AppClient(self._channel, self._metadata, self._location_id)
140
+ return AppClient(self._channel, self._metadata)
109
141
 
110
142
  @property
111
143
  def ml_training_client(self) -> MLTrainingClient:
@@ -171,7 +203,25 @@ class ViamClient:
171
203
  """
172
204
  return ProvisioningClient(self._channel, self._metadata)
173
205
 
174
- def close(self):
206
+ async def __aenter__(self) -> "ViamClient":
207
+ """A ViamClient can act as an asynchronous context manager. It will do nothing special when
208
+ the context is entered.
209
+ """
210
+ return self
211
+
212
+ async def __aexit__(self, exc_type: Optional[type], exc_value: Optional[BaseException], traceback: Optional[Any]) -> None:
213
+ """A ViamClient can act as an asynchronous context manager. It will close itself when
214
+ the context is exited.
215
+
216
+ ::
217
+
218
+ async with ViamClient.create_from_dial_options(...) as client:
219
+ await do_something_with(client)
220
+ # client is closed here
221
+ """
222
+ self.close()
223
+
224
+ def close(self) -> None:
175
225
  """Close opened channels used for the various service stubs initialized."""
176
226
  if self._closed:
177
227
  LOGGER.debug("ViamClient is already closed.")
@@ -179,3 +229,47 @@ class ViamClient:
179
229
  LOGGER.debug("Closing gRPC channel to app.")
180
230
  self._channel.close()
181
231
  self._closed = True
232
+
233
+ async def connect_to_machine(self, *, address: Optional[str] = None, id: Optional[str] = None) -> RobotClient:
234
+ """Connect to a machine using existing credentials.
235
+
236
+ A connection can be attempted using either the machine's address or its ID.
237
+ If both an address and ID are provided, the address will take precedence and the ID will be ignored.
238
+
239
+ ::
240
+
241
+ async def connect() -> ViamClient:
242
+ # Replace "<API-KEY>" (including brackets) with your API key and "<API-KEY-ID>" with your API key ID
243
+ dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>")
244
+ return await ViamClient.create_from_dial_options(dial_options)
245
+
246
+
247
+ async def main():
248
+ viam_client = await connect()
249
+
250
+ # Connect to a machine and obtain a RobotClient
251
+ # Replace "<MACHINE_ADDRESS>" (including brackets) with your machine's connection address
252
+ machine = await viam_client.connect_to_machine(address="<MACHINE_ADDRESS>")
253
+
254
+ Args:
255
+ address (Optional[str]): The address (FQDN) of the machine. Defaults to None.
256
+ id (Optional[str]): The ID (as a UUID) of the machine. Defaults to None.
257
+
258
+ Raises:
259
+ ValueError: If neither an address nor ID is provided.
260
+
261
+ Returns:
262
+ RobotClient: The active connection to the machine.
263
+ """
264
+ if address is None and id is None:
265
+ raise ValueError("Either a machine address or ID must be provided")
266
+
267
+ if id is not None and address is None:
268
+ parts = await self.app_client.get_robot_parts(id)
269
+ main_part = next(p for p in parts if p.main_part)
270
+ address = main_part.fqdn
271
+
272
+ opts = RobotClient.Options(dial_options=self._dial_options)
273
+
274
+ assert address is not None
275
+ return await RobotClient.at_address(address, opts)
@@ -1,11 +1,6 @@
1
- import asyncio
2
-
3
1
  from viam.proto.common import KinematicsFileFormat, Pose
4
2
  from viam.proto.component.arm import JointPositions
5
- from viam.proto.component.arm import Status as ArmStatus
6
- from viam.proto.robot import Status
7
3
  from viam.resource.registry import Registry, ResourceRegistration
8
- from viam.utils import message_to_struct
9
4
 
10
5
  from .arm import Arm
11
6
  from .client import ArmClient
@@ -18,23 +13,4 @@ __all__ = [
18
13
  "Pose",
19
14
  ]
20
15
 
21
-
22
- async def create_status(component: Arm) -> Status:
23
- (
24
- end_position,
25
- joint_positions,
26
- is_moving,
27
- ) = await asyncio.gather(
28
- component.get_end_position(),
29
- component.get_joint_positions(),
30
- component.is_moving(),
31
- )
32
- s = ArmStatus(
33
- end_position=end_position,
34
- joint_positions=joint_positions,
35
- is_moving=is_moving,
36
- )
37
- return Status(name=Arm.get_resource_name(component.name), status=message_to_struct(s))
38
-
39
-
40
- Registry.register_subtype(ResourceRegistration(Arm, ArmRPCService, lambda name, channel: ArmClient(name, channel), create_status))
16
+ Registry.register_api(ResourceRegistration(Arm, ArmRPCService, lambda name, channel: ArmClient(name, channel)))
@@ -1,7 +1,7 @@
1
1
  import abc
2
2
  from typing import Any, Dict, Final, Optional, Tuple
3
3
 
4
- from viam.resource.types import RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, Subtype
4
+ from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT
5
5
 
6
6
  from ..component_base import ComponentBase
7
7
  from . import JointPositions, KinematicsFileFormat, Pose
@@ -23,10 +23,10 @@ class Arm(ComponentBase):
23
23
  # To use move_to_joint_positions:
24
24
  from viam.proto.component.arm import JointPositions
25
25
 
26
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
26
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/>`_.
27
27
  """
28
28
 
29
- SUBTYPE: Final = Subtype(RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "arm") # pyright: ignore [reportIncompatibleVariableOverride]
29
+ API: Final = API(RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "arm") # pyright: ignore [reportIncompatibleVariableOverride]
30
30
 
31
31
  @abc.abstractmethod
32
32
  async def get_end_position(
@@ -41,7 +41,7 @@ class Arm(ComponentBase):
41
41
 
42
42
  ::
43
43
 
44
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
44
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
45
45
 
46
46
  # Get the end position of the arm as a Pose.
47
47
  pos = await my_arm.get_end_position()
@@ -52,7 +52,7 @@ class Arm(ComponentBase):
52
52
  Location is expressed as distance, which is represented by x, y, and z coordinate values.
53
53
  Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.
54
54
 
55
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
55
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getendposition>`_.
56
56
  """
57
57
  ...
58
58
 
@@ -70,7 +70,7 @@ class Arm(ComponentBase):
70
70
 
71
71
  ::
72
72
 
73
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
73
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
74
74
 
75
75
  # Create a Pose for the arm.
76
76
  examplePose = Pose(x=5, y=5, z=5, o_x=5, o_y=5, o_z=5, theta=20)
@@ -84,7 +84,7 @@ class Arm(ComponentBase):
84
84
  Location is expressed as distance, which is represented by x, y, and z coordinate values.
85
85
  Orientation is expressed as an orientation vector, which is represented by o_x, o_y, o_z, and theta values.
86
86
 
87
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
87
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#movetoposition>`_.
88
88
  """
89
89
  ...
90
90
 
@@ -102,15 +102,14 @@ class Arm(ComponentBase):
102
102
 
103
103
  ::
104
104
 
105
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
105
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
106
106
 
107
107
  # Declare a list of values with your desired rotational value for each joint on
108
- # the arm.
108
+ # the arm. This example is for a 5dof arm.
109
109
  degrees = [0.0, 45.0, 0.0, 0.0, 0.0]
110
110
 
111
111
  # Declare a new JointPositions with these values.
112
- jointPos = arm.move_to_joint_positions(
113
- JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
112
+ jointPos = JointPositions(values=degrees)
114
113
 
115
114
  # Move each joint of the arm to the position these values specify.
116
115
  await my_arm.move_to_joint_positions(positions=jointPos)
@@ -118,7 +117,7 @@ class Arm(ComponentBase):
118
117
  Args:
119
118
  positions (JointPositions): The destination ``JointPositions`` for the arm.
120
119
 
121
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
120
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#movetojointpositions>`_.
122
121
  """
123
122
  ...
124
123
 
@@ -135,7 +134,7 @@ class Arm(ComponentBase):
135
134
 
136
135
  ::
137
136
 
138
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
137
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
139
138
 
140
139
  # Get the current position of each joint on the arm as JointPositions.
141
140
  pos = await my_arm.get_joint_positions()
@@ -145,7 +144,7 @@ class Arm(ComponentBase):
145
144
  ``JointPositions`` can have one attribute, ``values``, a list of joint positions with rotational values (degrees)
146
145
  and translational values (mm).
147
146
 
148
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
147
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getjointpositions>`_.
149
148
  """
150
149
  ...
151
150
 
@@ -162,12 +161,12 @@ class Arm(ComponentBase):
162
161
 
163
162
  ::
164
163
 
165
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
164
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
166
165
 
167
166
  # Stop all motion of the arm. It is assumed that the arm stops immediately.
168
167
  await my_arm.stop()
169
168
 
170
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
169
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#stop>`_.
171
170
  """
172
171
  ...
173
172
 
@@ -178,31 +177,31 @@ class Arm(ComponentBase):
178
177
 
179
178
  ::
180
179
 
181
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
180
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
182
181
 
183
182
  # Stop all motion of the arm. It is assumed that the arm stops immediately.
184
183
  await my_arm.stop()
185
184
 
186
185
  # Print if the arm is currently moving.
187
- print(my_arm.is_moving())
186
+ print(await my_arm.is_moving())
188
187
 
189
188
  Returns:
190
189
  bool: Whether the arm is moving.
191
190
 
192
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
191
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#ismoving>`_.
193
192
  """
194
193
  ...
195
194
 
196
195
  @abc.abstractmethod
197
196
  async def get_kinematics(
198
- self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None
197
+ self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
199
198
  ) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
200
199
  """
201
200
  Get the kinematics information associated with the arm.
202
201
 
203
202
  ::
204
203
 
205
- my_arm = Arm.from_robot(robot=robot, name="my_arm")
204
+ my_arm = Arm.from_robot(robot=machine, name="my_arm")
206
205
 
207
206
  # Get the kinematics information associated with the arm.
208
207
  kinematics = await my_arm.get_kinematics()
@@ -219,6 +218,6 @@ class Arm(ComponentBase):
219
218
  Viam's kinematic parameter format (spatial vector algebra) (``KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA``),
220
219
  and the second [1] value represents the byte contents of the file.
221
220
 
222
- For more information, see `Arm component <https://docs.viam.com/components/arm/>`_.
221
+ For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getkinematics>`_.
223
222
  """
224
223
  ...