viam-sdk 0.45.2__py3-none-win_amd64.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 (476) hide show
  1. viam/__init__.py +71 -0
  2. viam/app/__init__.py +0 -0
  3. viam/app/_logs.py +34 -0
  4. viam/app/app_client.py +2525 -0
  5. viam/app/billing_client.py +143 -0
  6. viam/app/data_client.py +1715 -0
  7. viam/app/ml_training_client.py +251 -0
  8. viam/app/provisioning_client.py +95 -0
  9. viam/app/viam_client.py +260 -0
  10. viam/components/__init__.py +0 -0
  11. viam/components/arm/__init__.py +16 -0
  12. viam/components/arm/arm.py +223 -0
  13. viam/components/arm/client.py +124 -0
  14. viam/components/arm/service.py +123 -0
  15. viam/components/audio_input/__init__.py +18 -0
  16. viam/components/audio_input/audio_input.py +81 -0
  17. viam/components/audio_input/client.py +70 -0
  18. viam/components/audio_input/service.py +114 -0
  19. viam/components/base/__init__.py +13 -0
  20. viam/components/base/base.py +260 -0
  21. viam/components/base/client.py +153 -0
  22. viam/components/base/service.py +138 -0
  23. viam/components/board/__init__.py +9 -0
  24. viam/components/board/board.py +414 -0
  25. viam/components/board/client.py +241 -0
  26. viam/components/board/service.py +223 -0
  27. viam/components/button/__init__.py +10 -0
  28. viam/components/button/button.py +41 -0
  29. viam/components/button/client.py +52 -0
  30. viam/components/button/service.py +46 -0
  31. viam/components/camera/__init__.py +22 -0
  32. viam/components/camera/camera.py +138 -0
  33. viam/components/camera/client.py +98 -0
  34. viam/components/camera/service.py +105 -0
  35. viam/components/component_base.py +65 -0
  36. viam/components/encoder/__init__.py +18 -0
  37. viam/components/encoder/client.py +83 -0
  38. viam/components/encoder/encoder.py +118 -0
  39. viam/components/encoder/service.py +72 -0
  40. viam/components/gantry/__init__.py +11 -0
  41. viam/components/gantry/client.py +115 -0
  42. viam/components/gantry/gantry.py +156 -0
  43. viam/components/gantry/service.py +113 -0
  44. viam/components/generic/__init__.py +18 -0
  45. viam/components/generic/client.py +62 -0
  46. viam/components/generic/generic.py +76 -0
  47. viam/components/generic/service.py +40 -0
  48. viam/components/gripper/__init__.py +11 -0
  49. viam/components/gripper/client.py +85 -0
  50. viam/components/gripper/gripper.py +114 -0
  51. viam/components/gripper/service.py +81 -0
  52. viam/components/input/__init__.py +15 -0
  53. viam/components/input/client.py +194 -0
  54. viam/components/input/input.py +297 -0
  55. viam/components/input/service.py +175 -0
  56. viam/components/motor/__init__.py +11 -0
  57. viam/components/motor/client.py +168 -0
  58. viam/components/motor/motor.py +301 -0
  59. viam/components/motor/service.py +150 -0
  60. viam/components/movement_sensor/__init__.py +21 -0
  61. viam/components/movement_sensor/client.py +161 -0
  62. viam/components/movement_sensor/movement_sensor.py +253 -0
  63. viam/components/movement_sensor/service.py +146 -0
  64. viam/components/pose_tracker/__init__.py +17 -0
  65. viam/components/pose_tracker/client.py +50 -0
  66. viam/components/pose_tracker/pose_tracker.py +40 -0
  67. viam/components/pose_tracker/service.py +45 -0
  68. viam/components/power_sensor/__init__.py +17 -0
  69. viam/components/power_sensor/client.py +86 -0
  70. viam/components/power_sensor/power_sensor.py +104 -0
  71. viam/components/power_sensor/service.py +72 -0
  72. viam/components/sensor/__init__.py +18 -0
  73. viam/components/sensor/client.py +49 -0
  74. viam/components/sensor/sensor.py +48 -0
  75. viam/components/sensor/service.py +51 -0
  76. viam/components/servo/__init__.py +11 -0
  77. viam/components/servo/client.py +86 -0
  78. viam/components/servo/service.py +80 -0
  79. viam/components/servo/servo.py +114 -0
  80. viam/components/switch/__init__.py +10 -0
  81. viam/components/switch/client.py +83 -0
  82. viam/components/switch/service.py +72 -0
  83. viam/components/switch/switch.py +95 -0
  84. viam/errors.py +105 -0
  85. viam/gen/__init__.py +0 -0
  86. viam/gen/app/__init__.py +0 -0
  87. viam/gen/app/agent/__init__.py +0 -0
  88. viam/gen/app/agent/v1/__init__.py +0 -0
  89. viam/gen/app/agent/v1/agent_grpc.py +29 -0
  90. viam/gen/app/agent/v1/agent_pb2.py +47 -0
  91. viam/gen/app/agent/v1/agent_pb2.pyi +280 -0
  92. viam/gen/app/cloudslam/__init__.py +0 -0
  93. viam/gen/app/cloudslam/v1/__init__.py +0 -0
  94. viam/gen/app/cloudslam/v1/cloud_slam_grpc.py +70 -0
  95. viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +54 -0
  96. viam/gen/app/cloudslam/v1/cloud_slam_pb2.pyi +384 -0
  97. viam/gen/app/data/__init__.py +0 -0
  98. viam/gen/app/data/v1/__init__.py +0 -0
  99. viam/gen/app/data/v1/data_grpc.py +206 -0
  100. viam/gen/app/data/v1/data_pb2.py +178 -0
  101. viam/gen/app/data/v1/data_pb2.pyi +1485 -0
  102. viam/gen/app/datapipelines/__init__.py +0 -0
  103. viam/gen/app/datapipelines/v1/__init__.py +0 -0
  104. viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
  105. viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +56 -0
  106. viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +370 -0
  107. viam/gen/app/dataset/__init__.py +0 -0
  108. viam/gen/app/dataset/v1/__init__.py +0 -0
  109. viam/gen/app/dataset/v1/dataset_grpc.py +60 -0
  110. viam/gen/app/dataset/v1/dataset_pb2.py +40 -0
  111. viam/gen/app/dataset/v1/dataset_pb2.pyi +179 -0
  112. viam/gen/app/datasync/__init__.py +0 -0
  113. viam/gen/app/datasync/v1/__init__.py +0 -0
  114. viam/gen/app/datasync/v1/data_sync_grpc.py +47 -0
  115. viam/gen/app/datasync/v1/data_sync_pb2.py +70 -0
  116. viam/gen/app/datasync/v1/data_sync_pb2.pyi +425 -0
  117. viam/gen/app/mlinference/__init__.py +0 -0
  118. viam/gen/app/mlinference/v1/__init__.py +0 -0
  119. viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
  120. viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
  121. viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
  122. viam/gen/app/mltraining/__init__.py +0 -0
  123. viam/gen/app/mltraining/v1/__init__.py +0 -0
  124. viam/gen/app/mltraining/v1/ml_training_grpc.py +78 -0
  125. viam/gen/app/mltraining/v1/ml_training_pb2.py +124 -0
  126. viam/gen/app/mltraining/v1/ml_training_pb2.pyi +415 -0
  127. viam/gen/app/packages/__init__.py +0 -0
  128. viam/gen/app/packages/v1/__init__.py +0 -0
  129. viam/gen/app/packages/v1/packages_grpc.py +54 -0
  130. viam/gen/app/packages/v1/packages_pb2.py +52 -0
  131. viam/gen/app/packages/v1/packages_pb2.pyi +311 -0
  132. viam/gen/app/v1/__init__.py +0 -0
  133. viam/gen/app/v1/app_grpc.py +863 -0
  134. viam/gen/app/v1/app_pb2.py +649 -0
  135. viam/gen/app/v1/app_pb2.pyi +5279 -0
  136. viam/gen/app/v1/billing_grpc.py +76 -0
  137. viam/gen/app/v1/billing_pb2.py +92 -0
  138. viam/gen/app/v1/billing_pb2.pyi +463 -0
  139. viam/gen/app/v1/end_user_grpc.py +59 -0
  140. viam/gen/app/v1/end_user_pb2.py +55 -0
  141. viam/gen/app/v1/end_user_pb2.pyi +181 -0
  142. viam/gen/app/v1/robot_grpc.py +55 -0
  143. viam/gen/app/v1/robot_pb2.py +127 -0
  144. viam/gen/app/v1/robot_pb2.pyi +1202 -0
  145. viam/gen/common/__init__.py +0 -0
  146. viam/gen/common/v1/__init__.py +0 -0
  147. viam/gen/common/v1/common_grpc.py +0 -0
  148. viam/gen/common/v1/common_pb2.py +78 -0
  149. viam/gen/common/v1/common_pb2.pyi +687 -0
  150. viam/gen/component/__init__.py +0 -0
  151. viam/gen/component/arm/__init__.py +0 -0
  152. viam/gen/component/arm/v1/__init__.py +0 -0
  153. viam/gen/component/arm/v1/arm_grpc.py +102 -0
  154. viam/gen/component/arm/v1/arm_pb2.py +74 -0
  155. viam/gen/component/arm/v1/arm_pb2.pyi +344 -0
  156. viam/gen/component/audioinput/__init__.py +0 -0
  157. viam/gen/component/audioinput/v1/__init__.py +0 -0
  158. viam/gen/component/audioinput/v1/audioinput_grpc.py +63 -0
  159. viam/gen/component/audioinput/v1/audioinput_pb2.py +45 -0
  160. viam/gen/component/audioinput/v1/audioinput_pb2.pyi +179 -0
  161. viam/gen/component/base/__init__.py +0 -0
  162. viam/gen/component/base/v1/__init__.py +0 -0
  163. viam/gen/component/base/v1/base_grpc.py +94 -0
  164. viam/gen/component/base/v1/base_pb2.py +66 -0
  165. viam/gen/component/base/v1/base_pb2.pyi +258 -0
  166. viam/gen/component/board/__init__.py +0 -0
  167. viam/gen/component/board/v1/__init__.py +0 -0
  168. viam/gen/component/board/v1/board_grpc.py +127 -0
  169. viam/gen/component/board/v1/board_pb2.py +103 -0
  170. viam/gen/component/board/v1/board_pb2.pyi +496 -0
  171. viam/gen/component/button/__init__.py +0 -0
  172. viam/gen/component/button/v1/__init__.py +0 -0
  173. viam/gen/component/button/v1/button_grpc.py +38 -0
  174. viam/gen/component/button/v1/button_pb2.py +28 -0
  175. viam/gen/component/button/v1/button_pb2.pyi +39 -0
  176. viam/gen/component/camera/__init__.py +0 -0
  177. viam/gen/component/camera/v1/__init__.py +0 -0
  178. viam/gen/component/camera/v1/camera_grpc.py +79 -0
  179. viam/gen/component/camera/v1/camera_pb2.py +67 -0
  180. viam/gen/component/camera/v1/camera_pb2.pyi +373 -0
  181. viam/gen/component/encoder/__init__.py +0 -0
  182. viam/gen/component/encoder/v1/__init__.py +0 -0
  183. viam/gen/component/encoder/v1/encoder_grpc.py +62 -0
  184. viam/gen/component/encoder/v1/encoder_pb2.py +44 -0
  185. viam/gen/component/encoder/v1/encoder_pb2.pyi +147 -0
  186. viam/gen/component/gantry/__init__.py +0 -0
  187. viam/gen/component/gantry/v1/__init__.py +0 -0
  188. viam/gen/component/gantry/v1/gantry_grpc.py +86 -0
  189. viam/gen/component/gantry/v1/gantry_pb2.py +62 -0
  190. viam/gen/component/gantry/v1/gantry_pb2.pyi +239 -0
  191. viam/gen/component/generic/__init__.py +0 -0
  192. viam/gen/component/generic/v1/__init__.py +0 -0
  193. viam/gen/component/generic/v1/generic_grpc.py +37 -0
  194. viam/gen/component/generic/v1/generic_pb2.py +23 -0
  195. viam/gen/component/generic/v1/generic_pb2.pyi +6 -0
  196. viam/gen/component/gripper/__init__.py +0 -0
  197. viam/gen/component/gripper/v1/__init__.py +0 -0
  198. viam/gen/component/gripper/v1/gripper_grpc.py +70 -0
  199. viam/gen/component/gripper/v1/gripper_pb2.py +48 -0
  200. viam/gen/component/gripper/v1/gripper_pb2.pyi +137 -0
  201. viam/gen/component/inputcontroller/__init__.py +0 -0
  202. viam/gen/component/inputcontroller/v1/__init__.py +0 -0
  203. viam/gen/component/inputcontroller/v1/input_controller_grpc.py +71 -0
  204. viam/gen/component/inputcontroller/v1/input_controller_pb2.py +55 -0
  205. viam/gen/component/inputcontroller/v1/input_controller_pb2.pyi +243 -0
  206. viam/gen/component/motor/__init__.py +0 -0
  207. viam/gen/component/motor/v1/__init__.py +0 -0
  208. viam/gen/component/motor/v1/motor_grpc.py +118 -0
  209. viam/gen/component/motor/v1/motor_pb2.py +86 -0
  210. viam/gen/component/motor/v1/motor_pb2.pyi +368 -0
  211. viam/gen/component/movementsensor/__init__.py +0 -0
  212. viam/gen/component/movementsensor/v1/__init__.py +0 -0
  213. viam/gen/component/movementsensor/v1/movementsensor_grpc.py +110 -0
  214. viam/gen/component/movementsensor/v1/movementsensor_pb2.py +78 -0
  215. viam/gen/component/movementsensor/v1/movementsensor_pb2.pyi +384 -0
  216. viam/gen/component/posetracker/__init__.py +0 -0
  217. viam/gen/component/posetracker/v1/__init__.py +0 -0
  218. viam/gen/component/posetracker/v1/pose_tracker_grpc.py +46 -0
  219. viam/gen/component/posetracker/v1/pose_tracker_pb2.py +34 -0
  220. viam/gen/component/posetracker/v1/pose_tracker_pb2.pyi +79 -0
  221. viam/gen/component/powersensor/__init__.py +0 -0
  222. viam/gen/component/powersensor/v1/__init__.py +0 -0
  223. viam/gen/component/powersensor/v1/powersensor_grpc.py +62 -0
  224. viam/gen/component/powersensor/v1/powersensor_pb2.py +42 -0
  225. viam/gen/component/powersensor/v1/powersensor_pb2.pyi +124 -0
  226. viam/gen/component/sensor/__init__.py +0 -0
  227. viam/gen/component/sensor/v1/__init__.py +0 -0
  228. viam/gen/component/sensor/v1/sensor_grpc.py +45 -0
  229. viam/gen/component/sensor/v1/sensor_pb2.py +25 -0
  230. viam/gen/component/sensor/v1/sensor_pb2.pyi +6 -0
  231. viam/gen/component/servo/__init__.py +0 -0
  232. viam/gen/component/servo/v1/__init__.py +0 -0
  233. viam/gen/component/servo/v1/servo_grpc.py +70 -0
  234. viam/gen/component/servo/v1/servo_pb2.py +50 -0
  235. viam/gen/component/servo/v1/servo_pb2.pyi +150 -0
  236. viam/gen/component/switch/__init__.py +0 -0
  237. viam/gen/component/switch/v1/__init__.py +0 -0
  238. viam/gen/component/switch/v1/switch_grpc.py +54 -0
  239. viam/gen/component/switch/v1/switch_pb2.py +40 -0
  240. viam/gen/component/switch/v1/switch_pb2.pyi +109 -0
  241. viam/gen/component/testecho/__init__.py +0 -0
  242. viam/gen/component/testecho/v1/__init__.py +0 -0
  243. viam/gen/component/testecho/v1/testecho_grpc.py +52 -0
  244. viam/gen/component/testecho/v1/testecho_pb2.py +36 -0
  245. viam/gen/component/testecho/v1/testecho_pb2.pyi +114 -0
  246. viam/gen/module/__init__.py +0 -0
  247. viam/gen/module/v1/__init__.py +0 -0
  248. viam/gen/module/v1/module_grpc.py +61 -0
  249. viam/gen/module/v1/module_pb2.py +43 -0
  250. viam/gen/module/v1/module_pb2.pyi +211 -0
  251. viam/gen/proto/__init__.py +0 -0
  252. viam/gen/proto/rpc/__init__.py +0 -0
  253. viam/gen/proto/rpc/examples/__init__.py +0 -0
  254. viam/gen/proto/rpc/examples/echo/__init__.py +0 -0
  255. viam/gen/proto/rpc/examples/echo/v1/__init__.py +0 -0
  256. viam/gen/proto/rpc/examples/echo/v1/echo_grpc.py +44 -0
  257. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +32 -0
  258. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.pyi +87 -0
  259. viam/gen/proto/rpc/examples/echoresource/__init__.py +0 -0
  260. viam/gen/proto/rpc/examples/echoresource/v1/__init__.py +0 -0
  261. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_grpc.py +43 -0
  262. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +29 -0
  263. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.pyi +93 -0
  264. viam/gen/proto/rpc/v1/__init__.py +0 -0
  265. viam/gen/proto/rpc/v1/auth_grpc.py +47 -0
  266. viam/gen/proto/rpc/v1/auth_pb2.py +34 -0
  267. viam/gen/proto/rpc/v1/auth_pb2.pyi +92 -0
  268. viam/gen/proto/rpc/webrtc/__init__.py +0 -0
  269. viam/gen/proto/rpc/webrtc/v1/__init__.py +0 -0
  270. viam/gen/proto/rpc/webrtc/v1/grpc_grpc.py +0 -0
  271. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +43 -0
  272. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.pyi +304 -0
  273. viam/gen/proto/rpc/webrtc/v1/signaling_grpc.py +54 -0
  274. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +70 -0
  275. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +496 -0
  276. viam/gen/provisioning/__init__.py +0 -0
  277. viam/gen/provisioning/v1/__init__.py +0 -0
  278. viam/gen/provisioning/v1/provisioning_grpc.py +51 -0
  279. viam/gen/provisioning/v1/provisioning_pb2.py +39 -0
  280. viam/gen/provisioning/v1/provisioning_pb2.pyi +188 -0
  281. viam/gen/robot/__init__.py +0 -0
  282. viam/gen/robot/v1/__init__.py +0 -0
  283. viam/gen/robot/v1/robot_grpc.py +208 -0
  284. viam/gen/robot/v1/robot_pb2.py +188 -0
  285. viam/gen/robot/v1/robot_pb2.pyi +1020 -0
  286. viam/gen/service/__init__.py +0 -0
  287. viam/gen/service/datamanager/__init__.py +0 -0
  288. viam/gen/service/datamanager/v1/__init__.py +0 -0
  289. viam/gen/service/datamanager/v1/data_manager_grpc.py +38 -0
  290. viam/gen/service/datamanager/v1/data_manager_pb2.py +28 -0
  291. viam/gen/service/datamanager/v1/data_manager_pb2.pyi +39 -0
  292. viam/gen/service/discovery/__init__.py +0 -0
  293. viam/gen/service/discovery/v1/__init__.py +0 -0
  294. viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
  295. viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
  296. viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
  297. viam/gen/service/generic/__init__.py +0 -0
  298. viam/gen/service/generic/v1/__init__.py +0 -0
  299. viam/gen/service/generic/v1/generic_grpc.py +29 -0
  300. viam/gen/service/generic/v1/generic_pb2.py +21 -0
  301. viam/gen/service/generic/v1/generic_pb2.pyi +6 -0
  302. viam/gen/service/mlmodel/__init__.py +0 -0
  303. viam/gen/service/mlmodel/v1/__init__.py +0 -0
  304. viam/gen/service/mlmodel/v1/mlmodel_grpc.py +37 -0
  305. viam/gen/service/mlmodel/v1/mlmodel_pb2.py +83 -0
  306. viam/gen/service/mlmodel/v1/mlmodel_pb2.pyi +480 -0
  307. viam/gen/service/motion/__init__.py +0 -0
  308. viam/gen/service/motion/v1/__init__.py +0 -0
  309. viam/gen/service/motion/v1/motion_grpc.py +87 -0
  310. viam/gen/service/motion/v1/motion_pb2.py +97 -0
  311. viam/gen/service/motion/v1/motion_pb2.pyi +838 -0
  312. viam/gen/service/navigation/__init__.py +0 -0
  313. viam/gen/service/navigation/v1/__init__.py +0 -0
  314. viam/gen/service/navigation/v1/navigation_grpc.py +102 -0
  315. viam/gen/service/navigation/v1/navigation_pb2.py +84 -0
  316. viam/gen/service/navigation/v1/navigation_pb2.pyi +419 -0
  317. viam/gen/service/sensors/__init__.py +0 -0
  318. viam/gen/service/sensors/v1/__init__.py +0 -0
  319. viam/gen/service/sensors/v1/sensors_grpc.py +46 -0
  320. viam/gen/service/sensors/v1/sensors_pb2.py +68 -0
  321. viam/gen/service/sensors/v1/sensors_pb2.pyi +137 -0
  322. viam/gen/service/shell/__init__.py +0 -0
  323. viam/gen/service/shell/v1/__init__.py +0 -0
  324. viam/gen/service/shell/v1/shell_grpc.py +55 -0
  325. viam/gen/service/shell/v1/shell_pb2.py +45 -0
  326. viam/gen/service/shell/v1/shell_pb2.pyi +307 -0
  327. viam/gen/service/slam/__init__.py +0 -0
  328. viam/gen/service/slam/v1/__init__.py +0 -0
  329. viam/gen/service/slam/v1/slam_grpc.py +61 -0
  330. viam/gen/service/slam/v1/slam_pb2.py +51 -0
  331. viam/gen/service/slam/v1/slam_pb2.pyi +213 -0
  332. viam/gen/service/vision/__init__.py +0 -0
  333. viam/gen/service/vision/v1/__init__.py +0 -0
  334. viam/gen/service/vision/v1/vision_grpc.py +87 -0
  335. viam/gen/service/vision/v1/vision_pb2.py +69 -0
  336. viam/gen/service/vision/v1/vision_pb2.pyi +454 -0
  337. viam/gen/stream/__init__.py +0 -0
  338. viam/gen/stream/v1/__init__.py +0 -0
  339. viam/gen/stream/v1/stream_grpc.py +59 -0
  340. viam/gen/stream/v1/stream_pb2.py +39 -0
  341. viam/gen/stream/v1/stream_pb2.pyi +161 -0
  342. viam/gen/tagger/__init__.py +0 -0
  343. viam/gen/tagger/v1/__init__.py +0 -0
  344. viam/gen/tagger/v1/tagger_grpc.py +0 -0
  345. viam/gen/tagger/v1/tagger_pb2.py +16 -0
  346. viam/gen/tagger/v1/tagger_pb2.pyi +15 -0
  347. viam/logging.py +216 -0
  348. viam/media/__init__.py +0 -0
  349. viam/media/audio.py +16 -0
  350. viam/media/utils/__init__.py +0 -0
  351. viam/media/utils/pil/__init__.py +51 -0
  352. viam/media/utils/pil/viam_rgba_plugin.py +73 -0
  353. viam/media/viam_rgba.py +10 -0
  354. viam/media/video.py +217 -0
  355. viam/module/__init__.py +5 -0
  356. viam/module/module.py +281 -0
  357. viam/module/service.py +66 -0
  358. viam/module/types.py +23 -0
  359. viam/operations.py +124 -0
  360. viam/proto/__init__.py +0 -0
  361. viam/proto/app/__init__.py +554 -0
  362. viam/proto/app/agent/__init__.py +28 -0
  363. viam/proto/app/billing.py +58 -0
  364. viam/proto/app/cloudslam/__init__.py +48 -0
  365. viam/proto/app/data/__init__.py +138 -0
  366. viam/proto/app/datapipelines/__init__.py +56 -0
  367. viam/proto/app/dataset/__init__.py +36 -0
  368. viam/proto/app/datasync/__init__.py +44 -0
  369. viam/proto/app/end_user.py +34 -0
  370. viam/proto/app/mlinference/__init__.py +15 -0
  371. viam/proto/app/mltraining/__init__.py +52 -0
  372. viam/proto/app/packages/__init__.py +38 -0
  373. viam/proto/app/robot.py +84 -0
  374. viam/proto/common/__init__.py +66 -0
  375. viam/proto/component/__init__.py +0 -0
  376. viam/proto/component/arm/__init__.py +48 -0
  377. viam/proto/component/audioinput/__init__.py +30 -0
  378. viam/proto/component/base/__init__.py +42 -0
  379. viam/proto/component/board/__init__.py +62 -0
  380. viam/proto/component/button/__init__.py +15 -0
  381. viam/proto/component/camera/__init__.py +46 -0
  382. viam/proto/component/encoder/__init__.py +28 -0
  383. viam/proto/component/gantry/__init__.py +40 -0
  384. viam/proto/component/generic/__init__.py +12 -0
  385. viam/proto/component/gripper/__init__.py +30 -0
  386. viam/proto/component/inputcontroller/__init__.py +38 -0
  387. viam/proto/component/motor/__init__.py +56 -0
  388. viam/proto/component/movementsensor/__init__.py +50 -0
  389. viam/proto/component/posetracker/__init__.py +19 -0
  390. viam/proto/component/powersensor/__init__.py +30 -0
  391. viam/proto/component/sensor/__init__.py +12 -0
  392. viam/proto/component/servo/__init__.py +32 -0
  393. viam/proto/component/switch/__init__.py +26 -0
  394. viam/proto/component/testecho/__init__.py +30 -0
  395. viam/proto/module/__init__.py +38 -0
  396. viam/proto/provisioning/__init__.py +36 -0
  397. viam/proto/robot/__init__.py +130 -0
  398. viam/proto/rpc/__init__.py +0 -0
  399. viam/proto/rpc/auth.py +34 -0
  400. viam/proto/rpc/examples/__init__.py +0 -0
  401. viam/proto/rpc/examples/echo/__init__.py +26 -0
  402. viam/proto/rpc/examples/echoresource/__init__.py +30 -0
  403. viam/proto/rpc/webrtc/__init__.py +0 -0
  404. viam/proto/rpc/webrtc/grpc.py +36 -0
  405. viam/proto/rpc/webrtc/signaling.py +58 -0
  406. viam/proto/service/__init__.py +0 -0
  407. viam/proto/service/datamanager/__init__.py +19 -0
  408. viam/proto/service/discovery/__init__.py +15 -0
  409. viam/proto/service/generic/__init__.py +12 -0
  410. viam/proto/service/mlmodel/__init__.py +54 -0
  411. viam/proto/service/motion/__init__.py +68 -0
  412. viam/proto/service/navigation/__init__.py +58 -0
  413. viam/proto/service/sensors/__init__.py +18 -0
  414. viam/proto/service/shell/__init__.py +36 -0
  415. viam/proto/service/slam/__init__.py +36 -0
  416. viam/proto/service/vision/__init__.py +46 -0
  417. viam/proto/stream/__init__.py +36 -0
  418. viam/proto/tagger/__init__.py +6 -0
  419. viam/py.typed +0 -0
  420. viam/resource/__init__.py +0 -0
  421. viam/resource/base.py +123 -0
  422. viam/resource/easy_resource.py +153 -0
  423. viam/resource/manager.py +126 -0
  424. viam/resource/registry.py +199 -0
  425. viam/resource/rpc_client_base.py +65 -0
  426. viam/resource/rpc_service_base.py +48 -0
  427. viam/resource/types.py +213 -0
  428. viam/robot/__init__.py +0 -0
  429. viam/robot/client.py +909 -0
  430. viam/robot/service.py +69 -0
  431. viam/rpc/__init__.py +0 -0
  432. viam/rpc/dial.py +420 -0
  433. viam/rpc/libviam_rust_utils.dll +0 -0
  434. viam/rpc/server.py +201 -0
  435. viam/rpc/signaling.py +29 -0
  436. viam/rpc/types.py +22 -0
  437. viam/services/__init__.py +0 -0
  438. viam/services/discovery/__init__.py +12 -0
  439. viam/services/discovery/client.py +55 -0
  440. viam/services/discovery/discovery.py +52 -0
  441. viam/services/discovery/service.py +43 -0
  442. viam/services/generic/__init__.py +18 -0
  443. viam/services/generic/client.py +58 -0
  444. viam/services/generic/generic.py +58 -0
  445. viam/services/generic/service.py +29 -0
  446. viam/services/mlmodel/__init__.py +24 -0
  447. viam/services/mlmodel/client.py +37 -0
  448. viam/services/mlmodel/mlmodel.py +78 -0
  449. viam/services/mlmodel/service.py +38 -0
  450. viam/services/mlmodel/utils.py +101 -0
  451. viam/services/motion/__init__.py +17 -0
  452. viam/services/motion/client.py +215 -0
  453. viam/services/motion/motion.py +378 -0
  454. viam/services/motion/service.py +132 -0
  455. viam/services/navigation/__init__.py +11 -0
  456. viam/services/navigation/client.py +99 -0
  457. viam/services/navigation/navigation.py +250 -0
  458. viam/services/navigation/service.py +137 -0
  459. viam/services/service_base.py +78 -0
  460. viam/services/service_client_base.py +46 -0
  461. viam/services/slam/__init__.py +17 -0
  462. viam/services/slam/client.py +62 -0
  463. viam/services/slam/service.py +75 -0
  464. viam/services/slam/slam.py +111 -0
  465. viam/services/vision/__init__.py +15 -0
  466. viam/services/vision/client.py +206 -0
  467. viam/services/vision/service.py +146 -0
  468. viam/services/vision/vision.py +315 -0
  469. viam/sessions_client.py +245 -0
  470. viam/streams.py +44 -0
  471. viam/utils.py +365 -0
  472. viam/version_metadata.py +4 -0
  473. viam_sdk-0.45.2.dist-info/METADATA +157 -0
  474. viam_sdk-0.45.2.dist-info/RECORD +476 -0
  475. viam_sdk-0.45.2.dist-info/WHEEL +4 -0
  476. viam_sdk-0.45.2.dist-info/licenses/LICENSE +202 -0
viam/app/app_client.py ADDED
@@ -0,0 +1,2525 @@
1
+ import json
2
+ from datetime import datetime
3
+ from enum import Enum
4
+ from typing import Any, AsyncIterator, List, Literal, Mapping, Optional, Tuple, Union
5
+
6
+ from grpclib.client import Channel
7
+ from typing_extensions import Self
8
+
9
+ from viam import logging
10
+ from viam.app._logs import _LogsStream, _LogsStreamWithIterator
11
+ from viam.proto.app import (
12
+ AddRoleRequest,
13
+ APIKeyWithAuthorizations,
14
+ AppServiceStub,
15
+ AuthenticatorInfo,
16
+ Authorization,
17
+ AuthorizedPermissions,
18
+ ChangeRoleRequest,
19
+ CheckPermissionsRequest,
20
+ CheckPermissionsResponse,
21
+ CreateFragmentRequest,
22
+ CreateFragmentResponse,
23
+ CreateKeyFromExistingKeyAuthorizationsRequest,
24
+ CreateKeyFromExistingKeyAuthorizationsResponse,
25
+ CreateKeyRequest,
26
+ CreateKeyResponse,
27
+ CreateLocationRequest,
28
+ CreateLocationResponse,
29
+ CreateLocationSecretRequest,
30
+ CreateLocationSecretResponse,
31
+ CreateModuleRequest,
32
+ CreateModuleResponse,
33
+ CreateOrganizationInviteRequest,
34
+ CreateOrganizationInviteResponse,
35
+ CreateOrganizationRequest,
36
+ CreateOrganizationResponse,
37
+ CreateRegistryItemRequest,
38
+ CreateRobotPartSecretRequest,
39
+ CreateRobotPartSecretResponse,
40
+ DeleteFragmentRequest,
41
+ DeleteKeyRequest,
42
+ DeleteLocationRequest,
43
+ DeleteLocationSecretRequest,
44
+ DeleteOrganizationInviteRequest,
45
+ DeleteOrganizationMemberRequest,
46
+ DeleteOrganizationRequest,
47
+ DeleteRegistryItemRequest,
48
+ DeleteRobotPartRequest,
49
+ DeleteRobotPartSecretRequest,
50
+ DeleteRobotRequest,
51
+ GetFragmentHistoryRequest,
52
+ GetFragmentHistoryResponse,
53
+ GetFragmentRequest,
54
+ GetFragmentResponse,
55
+ GetLocationRequest,
56
+ GetLocationResponse,
57
+ GetModuleRequest,
58
+ GetModuleResponse,
59
+ GetOrganizationNamespaceAvailabilityRequest,
60
+ GetOrganizationNamespaceAvailabilityResponse,
61
+ GetOrganizationRequest,
62
+ GetOrganizationResponse,
63
+ GetOrganizationsWithAccessToLocationRequest,
64
+ GetOrganizationsWithAccessToLocationResponse,
65
+ GetRegistryItemRequest,
66
+ GetRegistryItemResponse,
67
+ GetRobotAPIKeysRequest,
68
+ GetRobotAPIKeysResponse,
69
+ GetRobotPartHistoryRequest,
70
+ GetRobotPartHistoryResponse,
71
+ GetRobotPartLogsRequest,
72
+ GetRobotPartLogsResponse,
73
+ GetRobotPartRequest,
74
+ GetRobotPartResponse,
75
+ GetRobotPartsRequest,
76
+ GetRobotPartsResponse,
77
+ GetRobotRequest,
78
+ GetRobotResponse,
79
+ GetRoverRentalRobotsRequest,
80
+ GetRoverRentalRobotsResponse,
81
+ GetUserIDByEmailRequest,
82
+ GetUserIDByEmailResponse,
83
+ ListAuthorizationsRequest,
84
+ ListAuthorizationsResponse,
85
+ ListFragmentsRequest,
86
+ ListFragmentsResponse,
87
+ ListKeysRequest,
88
+ ListKeysResponse,
89
+ ListLocationsRequest,
90
+ ListLocationsResponse,
91
+ ListModulesRequest,
92
+ ListModulesResponse,
93
+ ListOrganizationMembersRequest,
94
+ ListOrganizationMembersResponse,
95
+ ListOrganizationsByUserRequest,
96
+ ListOrganizationsByUserResponse,
97
+ ListOrganizationsRequest,
98
+ ListOrganizationsResponse,
99
+ ListRegistryItemsRequest,
100
+ ListRegistryItemsResponse,
101
+ ListRobotsRequest,
102
+ ListRobotsResponse,
103
+ Location,
104
+ LocationAuth,
105
+ LocationAuthRequest,
106
+ LocationAuthResponse,
107
+ MarkPartAsMainRequest,
108
+ MarkPartForRestartRequest,
109
+ Model,
110
+ Module,
111
+ ModuleFileInfo,
112
+ NewRobotPartRequest,
113
+ NewRobotPartResponse,
114
+ NewRobotRequest,
115
+ NewRobotResponse,
116
+ Organization,
117
+ OrganizationIdentity,
118
+ OrganizationInvite,
119
+ OrganizationMember,
120
+ OrgDetails,
121
+ RegistryItem,
122
+ RegistryItemStatus,
123
+ RemoveRoleRequest,
124
+ ResendOrganizationInviteRequest,
125
+ ResendOrganizationInviteResponse,
126
+ Robot,
127
+ RotateKeyRequest,
128
+ RotateKeyResponse,
129
+ RoverRentalRobot,
130
+ SharedSecret,
131
+ ShareLocationRequest,
132
+ TailRobotPartLogsRequest,
133
+ TailRobotPartLogsResponse,
134
+ UnshareLocationRequest,
135
+ UpdateFragmentRequest,
136
+ UpdateFragmentResponse,
137
+ UpdateLocationRequest,
138
+ UpdateLocationResponse,
139
+ UpdateModuleRequest,
140
+ UpdateModuleResponse,
141
+ UpdateOrganizationInviteAuthorizationsRequest,
142
+ UpdateOrganizationInviteAuthorizationsResponse,
143
+ UpdateOrganizationRequest,
144
+ UpdateOrganizationResponse,
145
+ UpdateRegistryItemRequest,
146
+ UpdateRobotPartRequest,
147
+ UpdateRobotPartResponse,
148
+ UpdateRobotRequest,
149
+ UpdateRobotResponse,
150
+ UploadModuleFileRequest,
151
+ Visibility,
152
+ )
153
+ from viam.proto.app import Fragment as FragmentPB
154
+ from viam.proto.app import FragmentHistoryEntry as FragmentHistoryEntryPB
155
+ from viam.proto.app import FragmentVisibility as FragmentVisibilityPB
156
+ from viam.proto.app import RobotPart as RobotPartPB
157
+ from viam.proto.app import RobotPartHistoryEntry as RobotPartHistoryEntryPB
158
+ from viam.proto.app.packages import PackageType
159
+ from viam.proto.common import LogEntry as LogEntryPB
160
+ from viam.utils import datetime_to_timestamp, dict_to_struct, struct_to_dict
161
+
162
+ LOGGER = logging.getLogger(__name__)
163
+
164
+
165
+ class RobotPart:
166
+ """A class that mirrors the `RobotPart` proto message.
167
+
168
+ Use this class to make the attributes of a `viam.proto.app.RobotPart` more accessible and easier to read/interpret.
169
+ """
170
+
171
+ @classmethod
172
+ def from_proto(cls, robot_part: RobotPartPB) -> Self:
173
+ """Create a `RobotPart` from the .proto defined `RobotPart`.
174
+
175
+ Args:
176
+ robot_part (viam.proto.app.RobotPart): The object to copy from.
177
+
178
+ Returns:
179
+ RobotPart: The `RobotPart`.
180
+ """
181
+ self = cls()
182
+ self.id = robot_part.id
183
+ self.name = robot_part.name
184
+ self.dns_name = robot_part.dns_name
185
+ self.secret = robot_part.secret
186
+ self.robot = robot_part.robot
187
+ self.location_id = robot_part.location_id
188
+ self.robot_config = struct_to_dict(robot_part.robot_config) if robot_part.HasField("robot_config") else None
189
+ self.last_access = robot_part.last_access.ToDatetime() if robot_part.HasField("last_access") else None
190
+ self.user_supplied_info = struct_to_dict(robot_part.user_supplied_info) if robot_part.HasField("user_supplied_info") else None
191
+ self.main_part = robot_part.main_part
192
+ self.fqdn = robot_part.fqdn
193
+ self.local_fqdn = robot_part.local_fqdn
194
+ self.created_on = robot_part.created_on.ToDatetime() if robot_part.HasField("created_on") else None
195
+ self.secrets = list(robot_part.secrets)
196
+ return self
197
+
198
+ id: str
199
+ name: str
200
+ dns_name: str
201
+ secret: str
202
+ robot: str
203
+ location_id: str
204
+ robot_config: Optional[Mapping[str, Any]]
205
+ last_access: Optional[datetime]
206
+ user_supplied_info: Optional[Mapping[str, Any]]
207
+ main_part: bool
208
+ fqdn: str
209
+ local_fqdn: str
210
+ created_on: Optional[datetime]
211
+ secrets: Optional[List[SharedSecret]]
212
+
213
+ @property
214
+ def proto(self) -> RobotPartPB:
215
+ return RobotPartPB(
216
+ id=self.id,
217
+ name=self.name,
218
+ dns_name=self.dns_name,
219
+ secret=self.secret,
220
+ robot=self.robot,
221
+ location_id=self.location_id,
222
+ robot_config=dict_to_struct(self.robot_config) if self.robot_config else None,
223
+ last_access=datetime_to_timestamp(self.last_access) if self.last_access else None,
224
+ user_supplied_info=dict_to_struct(self.user_supplied_info) if self.user_supplied_info else None,
225
+ main_part=self.main_part,
226
+ fqdn=self.fqdn,
227
+ local_fqdn=self.local_fqdn,
228
+ created_on=datetime_to_timestamp(self.created_on) if self.created_on else None,
229
+ secrets=self.secrets,
230
+ )
231
+
232
+
233
+ class LogEntry:
234
+ """A class that mirrors the `LogEntry` proto message.
235
+
236
+ Use this class to make the attributes of a `viam.proto.app.LogEntry` more accessible and easier to read/interpret.
237
+ """
238
+
239
+ @classmethod
240
+ def from_proto(cls, log_entry: LogEntryPB) -> Self:
241
+ """Create a `LogEntry` from the .proto defined `LogEntry`.
242
+
243
+ Args:
244
+ log_entry (viam.proto.app.LogEntry): The object to copy from.
245
+
246
+ Returns:
247
+ LogEntry: The `LogEntry`.
248
+ """
249
+ self = cls()
250
+ self.host = log_entry.host
251
+ self.level = log_entry.level
252
+ self.time = log_entry.time.ToDatetime() if log_entry.HasField("time") else None
253
+ self.logger_name = log_entry.logger_name
254
+ self.message = log_entry.message
255
+ self.caller = struct_to_dict(log_entry.caller) if log_entry.HasField("caller") else None
256
+ self.stack = log_entry.stack
257
+ self.fields = [struct_to_dict(field) for field in log_entry.fields]
258
+ return self
259
+
260
+ host: str
261
+ level: str
262
+ time: Optional[datetime]
263
+ logger_name: str
264
+ message: str
265
+ caller: Optional[Mapping[str, Any]]
266
+ stack: str
267
+ fields: Optional[List[Mapping[str, Any]]]
268
+
269
+ @property
270
+ def proto(self) -> LogEntryPB:
271
+ return LogEntryPB(
272
+ host=self.host,
273
+ level=self.level,
274
+ time=datetime_to_timestamp(self.time) if self.time else None,
275
+ logger_name=self.logger_name,
276
+ message=self.message,
277
+ caller=dict_to_struct(self.caller) if self.caller else None,
278
+ stack=self.stack,
279
+ fields=[dict_to_struct(field) for field in self.fields] if self.fields else None,
280
+ )
281
+
282
+
283
+ class Fragment:
284
+ """A class that mirrors the `Fragment` proto message.
285
+
286
+ Use this class to make the attributes of a `viam.proto.app.RobotPart` more accessible and easier to read/interpret.
287
+ """
288
+
289
+ class Visibility(str, Enum):
290
+ """
291
+ FragmentVisibility specifies who is permitted to view the fragment.
292
+ """
293
+
294
+ PRIVATE = "private"
295
+ """
296
+ Only visible to members in the fragment's organization.
297
+ """
298
+
299
+ PUBLIC = "public"
300
+ """
301
+ Visible to anyone and appears on the fragments page.
302
+ """
303
+
304
+ PUBLIC_UNLISTED = "public_unlisted"
305
+ """
306
+ Visible to anyone but does not appear on the fragments page.
307
+ """
308
+
309
+ UNSPECIFIED = "unspecified"
310
+ """
311
+ Uninitialized visibility.
312
+ """
313
+
314
+ @classmethod
315
+ def from_proto(cls, visibility: FragmentVisibilityPB.ValueType) -> "Fragment.Visibility":
316
+ if visibility == FragmentVisibilityPB.FRAGMENT_VISIBILITY_PRIVATE:
317
+ return Fragment.Visibility.PRIVATE
318
+ if visibility == FragmentVisibilityPB.FRAGMENT_VISIBILITY_PUBLIC:
319
+ return Fragment.Visibility.PUBLIC
320
+ if visibility == FragmentVisibilityPB.FRAGMENT_VISIBILITY_PUBLIC_UNLISTED:
321
+ return Fragment.Visibility.PUBLIC_UNLISTED
322
+ return Fragment.Visibility.UNSPECIFIED
323
+
324
+ def to_proto(self) -> FragmentVisibilityPB.ValueType:
325
+ if self == self.PRIVATE:
326
+ return FragmentVisibilityPB.FRAGMENT_VISIBILITY_PRIVATE
327
+ if self == self.PUBLIC:
328
+ return FragmentVisibilityPB.FRAGMENT_VISIBILITY_PUBLIC
329
+ if self == self.PUBLIC_UNLISTED:
330
+ return FragmentVisibilityPB.FRAGMENT_VISIBILITY_PUBLIC_UNLISTED
331
+ return FragmentVisibilityPB.FRAGMENT_VISIBILITY_UNSPECIFIED
332
+
333
+ @classmethod
334
+ def from_proto(cls, fragment: FragmentPB) -> Self:
335
+ """Create a `Fragment` from the .proto defined `Fragment`.
336
+
337
+ Args:
338
+ fragment (viam.proto.app.Fragment): The object to copy from.
339
+
340
+ Returns:
341
+ Fragment: The `Fragment`.
342
+ """
343
+ self = cls()
344
+ self.id = fragment.id
345
+ self.name = fragment.name
346
+ self.fragment = struct_to_dict(fragment.fragment) if fragment.HasField("fragment") else None
347
+ self.organization_owner = fragment.organization_owner
348
+ self.public = fragment.public
349
+ self.created_on = fragment.created_on.ToDatetime() if fragment.HasField("created_on") else None
350
+ self.organization_name = fragment.organization_name
351
+ self.robot_part_count = fragment.robot_part_count
352
+ self.organization_count = fragment.organization_count
353
+ self.only_used_by_owner = fragment.only_used_by_owner
354
+ self.visibility = Fragment.Visibility.from_proto(fragment.visibility)
355
+ return self
356
+
357
+ id: str
358
+ name: str
359
+ fragment: Optional[Mapping[str, Any]]
360
+ organization_owner: str
361
+ public: bool
362
+ created_on: Optional[datetime]
363
+ organization_name: str
364
+ robot_part_count: int
365
+ organization_count: int
366
+ only_used_by_owner: bool
367
+ visibility: Visibility
368
+
369
+ @property
370
+ def proto(self) -> FragmentPB:
371
+ return FragmentPB(
372
+ id=self.id,
373
+ name=self.name,
374
+ fragment=dict_to_struct(self.fragment) if self.fragment else None,
375
+ organization_owner=self.organization_owner,
376
+ public=self.public,
377
+ created_on=datetime_to_timestamp(self.created_on) if self.created_on else None,
378
+ organization_name=self.organization_name,
379
+ robot_part_count=self.robot_part_count,
380
+ organization_count=self.organization_count,
381
+ only_used_by_owner=self.only_used_by_owner,
382
+ visibility=self.visibility.to_proto(),
383
+ )
384
+
385
+
386
+ class FragmentHistoryEntry:
387
+ """A class that mirrors the `FragmentHistoryEntry` proto message.
388
+
389
+ Use this class to make the attributes of a `viam.proto.app.FragmentHistoryEntry` more accessible and easier to read/interpret.
390
+ """
391
+
392
+ @classmethod
393
+ def from_proto(cls, fragment_history_entry: FragmentHistoryEntryPB) -> Self:
394
+ """Create a `FragmentHistoryEntry` from the .proto defined `FragmentHistoryEntry`.
395
+
396
+ Args:
397
+ fragment_history_entry (viam.proto.app.FragmentHistoryEntry): The object to copy from.
398
+
399
+ Returns:
400
+ FragmentHistoryEntry: The `FragmentHistoryEntry`.
401
+ """
402
+ self = cls()
403
+ self.fragment = fragment_history_entry.fragment
404
+ self.edited_on = fragment_history_entry.edited_on.ToDatetime()
405
+ self.old = Fragment.from_proto(fragment_history_entry.old)
406
+ self.edited_by = fragment_history_entry.edited_by
407
+ return self
408
+
409
+ fragment: str
410
+ edited_on: datetime
411
+ old: Fragment
412
+ edited_by: AuthenticatorInfo
413
+
414
+ @property
415
+ def proto(self) -> FragmentHistoryEntryPB:
416
+ return FragmentHistoryEntryPB(
417
+ fragment=self.fragment,
418
+ edited_on=datetime_to_timestamp(self.edited_on),
419
+ edited_by=self.edited_by,
420
+ old=self.old.proto if self.old else None,
421
+ )
422
+
423
+
424
+ class RobotPartHistoryEntry:
425
+ """A class that mirrors the `RobotPartHistoryEntry` proto message.
426
+
427
+ Use this class to make the attributes of a `viam.proto.app.RobotPartHistoryEntry` more accessible and easier to read/interpret.
428
+ """
429
+
430
+ @classmethod
431
+ def from_proto(cls, robot_part_history_entry: RobotPartHistoryEntryPB) -> Self:
432
+ """Create a `RobotPartHistoryEntry` from the .proto defined `RobotPartHistoryEntry`.
433
+
434
+ Args:
435
+ robot_part_history_entry (viam.proto.app.RobotPartHistoryEntry): The object to copy from.
436
+
437
+ Returns:
438
+ RobotPartHistoryEntry: The `RobotPartHistoryEntry`.
439
+ """
440
+ self = cls()
441
+ self.part = robot_part_history_entry.part
442
+ self.robot = robot_part_history_entry.robot
443
+ self.when = robot_part_history_entry.when.ToDatetime() if robot_part_history_entry.HasField("when") else None
444
+ self.old = RobotPart.from_proto(robot_part_history_entry.old) if robot_part_history_entry.HasField("old") else None
445
+ return self
446
+
447
+ part: str
448
+ robot: str
449
+ when: Optional[datetime]
450
+ old: Optional[RobotPart]
451
+
452
+ @property
453
+ def proto(self) -> RobotPartHistoryEntryPB:
454
+ return RobotPartHistoryEntryPB(
455
+ part=self.part,
456
+ robot=self.robot,
457
+ when=datetime_to_timestamp(self.when) if self.when else None,
458
+ old=self.old.proto if self.old else None,
459
+ )
460
+
461
+
462
+ class APIKeyAuthorization:
463
+ """A class with the necessary authorization data for creating an API key.
464
+
465
+ Use this class when constructing API key authorizations to minimize the risk of malformed or missing data.
466
+ """
467
+
468
+ def __init__(
469
+ self,
470
+ role: Union[Literal["owner"], Literal["operator"]],
471
+ resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
472
+ resource_id: str,
473
+ ):
474
+ """role (Union[Literal["owner"], Literal["operator"]]): The role to add.
475
+ resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]): Type of the resource to add role to.
476
+ Must match `resource_id`.
477
+ resource_id (str): ID of the resource the role applies to (that is, either an organization, location, or robot ID).
478
+ """
479
+ self._role = role
480
+ self._resource_type = resource_type
481
+ self._resource_id = resource_id
482
+
483
+ _role: str
484
+ _resource_type: str
485
+ _resource_id: str
486
+
487
+
488
+ class AppClient:
489
+ """gRPC client for method calls to app.
490
+
491
+ Constructor is used by `ViamClient` to instantiate relevant service stub. Calls to `AppClient` methods should be made through
492
+ `ViamClient`.
493
+
494
+ Establish a Connection::
495
+
496
+ import asyncio
497
+
498
+ from viam.rpc.dial import DialOptions, Credentials
499
+ from viam.app.viam_client import ViamClient
500
+
501
+
502
+ async def connect() -> ViamClient:
503
+ # Replace "<API-KEY>" (including brackets) with your API key and "<API-KEY-ID>" with your API key ID
504
+ dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>")
505
+ return await ViamClient.create_from_dial_options(dial_options)
506
+
507
+
508
+ async def main():
509
+
510
+ # Make a ViamClient
511
+ viam_client = await connect()
512
+ # Instantiate an AppClient called "cloud" to run cloud app API methods on
513
+ cloud = viam_client.app_client
514
+
515
+ viam_client.close()
516
+
517
+ if __name__ == '__main__':
518
+ asyncio.run(main())
519
+
520
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/>`_.
521
+ """
522
+
523
+ def __init__(self, channel: Channel, metadata: Mapping[str, str], location_id: Optional[str] = None):
524
+ """Create an `AppClient` that maintains a connection to app.
525
+
526
+ Args:
527
+ channel (grpclib.client.Channel): connection to app.
528
+ metadata (Mapping[str, str]): Required authorization token to send requests to app.
529
+ location_id (Optional[str]): Default location ID.
530
+ """
531
+ self._metadata = metadata
532
+ self._app_client = AppServiceStub(channel)
533
+ self._location_id = location_id
534
+ self._channel = channel
535
+
536
+ _app_client: AppServiceStub
537
+ _metadata: Mapping[str, str]
538
+ _location_id: Optional[str]
539
+ _channel: Channel
540
+ _organization_id: Optional[str] = None
541
+
542
+ async def _create_authorization(
543
+ self,
544
+ organization_id: str,
545
+ identity_id: str,
546
+ identity_type: str,
547
+ role: Union[Literal["owner"], Literal["operator"]],
548
+ resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
549
+ resource_id: str,
550
+ ) -> Authorization:
551
+ return Authorization(
552
+ authorization_type="role",
553
+ identity_id=identity_id,
554
+ identity_type=identity_type,
555
+ authorization_id=f"{resource_type}_{role}",
556
+ resource_type=resource_type,
557
+ resource_id=resource_id,
558
+ organization_id=organization_id,
559
+ )
560
+
561
+ async def _create_authorization_for_new_api_key(self, org_id: str, auth: APIKeyAuthorization) -> Authorization:
562
+ """Creates a new Authorization specifically for creating an API key."""
563
+ return await self._create_authorization(
564
+ organization_id=org_id,
565
+ identity_id="", # setting `identity_id` when creating an API key results in an error
566
+ identity_type="api-key",
567
+ role=auth._role, # type: ignore -- Ignoring because this is technically a `string`
568
+ resource_type=auth._resource_type, # type: ignore -- Ignoring because this is technically a `string`
569
+ resource_id=auth._resource_id,
570
+ )
571
+
572
+ async def get_user_id_by_email(self, email: str) -> str:
573
+ """Get the ID of a user by email.
574
+
575
+ ::
576
+
577
+ id = await cloud.get_user_id_by_email("youremail@email.com")
578
+
579
+ Args:
580
+ email (str): The email of the user.
581
+
582
+ Returns:
583
+ str: The ID of the user.
584
+
585
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getuseridbyemail>`_.
586
+ """
587
+ request = GetUserIDByEmailRequest(email=email)
588
+ response: GetUserIDByEmailResponse = await self._app_client.GetUserIDByEmail(request, metadata=self._metadata)
589
+ return response.user_id
590
+
591
+ async def create_organization(self, name: str) -> Organization:
592
+ """Create an organization.
593
+
594
+ ::
595
+
596
+ organization = await cloud.create_organization("name")
597
+
598
+ Args:
599
+ name (str): The name of the organization.
600
+
601
+ Returns:
602
+ Organization: The created organization.
603
+
604
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createorganization>`_.
605
+ """
606
+ request = CreateOrganizationRequest(name=name)
607
+ response: CreateOrganizationResponse = await self._app_client.CreateOrganization(request, metadata=self._metadata)
608
+ return response.organization
609
+
610
+ async def list_organizations(self) -> List[Organization]:
611
+ """List the organization(s) the user is an authorized owner of.
612
+
613
+ ::
614
+
615
+ org_list = await cloud.list_organizations()
616
+
617
+ Returns:
618
+ List[viam.proto.app.Organization]: The list of organizations.
619
+
620
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listorganizations>`_.
621
+ """
622
+ request = ListOrganizationsRequest()
623
+ response: ListOrganizationsResponse = await self._app_client.ListOrganizations(request, metadata=self._metadata)
624
+ return list(response.organizations)
625
+
626
+ async def get_organizations_with_access_to_location(self, location_id: str) -> List[OrganizationIdentity]:
627
+ """Get all organizations that have access to a location.
628
+
629
+ ::
630
+
631
+ org_list = await cloud.get_organizations_with_access_to_location("location-id")
632
+
633
+ Args:
634
+ location_id (str): The ID of the location.
635
+
636
+ Returns:
637
+ List[viam.proto.app.OrganizationIdentity]: The list of organizations.
638
+
639
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getorganizationswithaccesstolocation>`_.
640
+ """
641
+ request = GetOrganizationsWithAccessToLocationRequest(location_id=location_id)
642
+ response: GetOrganizationsWithAccessToLocationResponse = await self._app_client.GetOrganizationsWithAccessToLocation(
643
+ request, metadata=self._metadata
644
+ )
645
+ return list(response.organization_identities)
646
+
647
+ async def list_organizations_by_user(self, user_id: str) -> List[OrgDetails]:
648
+ """List the organizations a user belongs to.
649
+
650
+ ::
651
+
652
+ org_list = await cloud.list_organizations_by_user("<YOUR-USER-ID>")
653
+
654
+ Args:
655
+ user_id (str): The ID of the user. You can retrieve this with the get_user_id_by_email() method.
656
+
657
+ Returns:
658
+ List[OrgDetails]: The list of organizations.
659
+
660
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listorganizationsbyuser>`_.
661
+ """
662
+ request = ListOrganizationsByUserRequest(user_id=user_id)
663
+ response: ListOrganizationsByUserResponse = await self._app_client.ListOrganizationsByUser(request, metadata=self._metadata)
664
+ return list(response.orgs)
665
+
666
+ async def get_organization(self, org_id: str) -> Organization:
667
+ """Retrieve the organization object for the requested organization containing the organization's ID,
668
+ name, public namespace, and more.
669
+
670
+ ::
671
+
672
+ org = await cloud.get_organization("<YOUR-ORG-ID>")
673
+
674
+ Args:
675
+ org_id (str): The ID of the organization to query. You can retrieve this from the organization settings page.
676
+
677
+ Raises:
678
+ GRPCError: If the provided org_id is invalid, or not currently authed to.
679
+
680
+ Returns:
681
+ viam.proto.app.Organization: The requested organization.
682
+
683
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getorganization>`_.
684
+ """
685
+ request = GetOrganizationRequest(organization_id=org_id)
686
+ response: GetOrganizationResponse = await self._app_client.GetOrganization(request, metadata=self._metadata)
687
+ return response.organization
688
+
689
+ async def get_organization_namespace_availability(self, public_namespace: str) -> bool:
690
+ """Check the availability of an organization namespace.
691
+
692
+ ::
693
+
694
+ available = await cloud.get_organization_namespace_availability(
695
+ public_namespace="my-cool-organization")
696
+
697
+ Args:
698
+ public_namespace (str): Organization namespace to check. Namespaces can only contain lowercase alphanumeric and dash
699
+ characters.
700
+
701
+ Raises:
702
+ GRPCError: If an invalid namespace (for example, "") is provided.
703
+
704
+ Returns:
705
+ bool: True if the provided namespace is available.
706
+
707
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getorganizationnamespaceavailability>`_.
708
+ """
709
+ request = GetOrganizationNamespaceAvailabilityRequest(public_namespace=public_namespace)
710
+ response: GetOrganizationNamespaceAvailabilityResponse = await self._app_client.GetOrganizationNamespaceAvailability(
711
+ request, metadata=self._metadata
712
+ )
713
+ return response.available
714
+
715
+ async def update_organization(
716
+ self,
717
+ org_id: str,
718
+ name: Optional[str] = None,
719
+ public_namespace: Optional[str] = None,
720
+ region: Optional[str] = None,
721
+ cid: Optional[str] = None,
722
+ ) -> Organization:
723
+ """Updates organization details.
724
+
725
+ ::
726
+
727
+ organization = await cloud.update_organization(
728
+ org_id="<YOUR-ORG-ID>",
729
+ name="Artoo's Org",
730
+ public_namespace="artoo"
731
+ )
732
+
733
+ Args:
734
+ org_id (str): The ID of the organization to update.
735
+ name (Optional[str]): If provided, updates the org's name.
736
+ public_namespace (Optional[str]): If provided, sets the org's namespace if it hasn't already been set.
737
+ region (Optional[str]): If provided, updates the org's region.
738
+ cid (Optional[str]): If provided, update's the org's CRM ID.
739
+
740
+ Raises:
741
+ GRPCError: If the org's namespace has already been set, or if the provided namespace is already taken.
742
+
743
+ Returns:
744
+ viam.proto.app.Organization: The updated organization.
745
+
746
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updateorganization>`_.
747
+ """
748
+ request = UpdateOrganizationRequest(
749
+ organization_id=org_id,
750
+ public_namespace=public_namespace,
751
+ region=region,
752
+ cid=cid,
753
+ name=name,
754
+ )
755
+ response: UpdateOrganizationResponse = await self._app_client.UpdateOrganization(request, metadata=self._metadata)
756
+ return response.organization
757
+
758
+ async def delete_organization(self, org_id: str) -> None:
759
+ """Delete an organization
760
+
761
+ ::
762
+
763
+ await cloud.delete_organization("<YOUR-ORG-ID>")
764
+
765
+ Args:
766
+ org_id (str): The ID of the organization.
767
+ You can obtain your organization ID from the Viam app's organization settings page.
768
+
769
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleteorganization>`_.
770
+ """
771
+ request = DeleteOrganizationRequest(organization_id=org_id)
772
+ await self._app_client.DeleteOrganization(request, metadata=self._metadata)
773
+
774
+ async def list_organization_members(self, org_id: str) -> Tuple[List[OrganizationMember], List[OrganizationInvite]]:
775
+ """List the members and invites of the currently authed-to organization.
776
+
777
+ ::
778
+
779
+ member_list, invite_list = await cloud.list_organization_members("<YOUR-ORG-ID>")
780
+
781
+ Args:
782
+ org_id (str): The ID of the organization to list members of.
783
+ You can obtain your organization ID from the Viam app's organization settings page.
784
+
785
+ Returns:
786
+ Tuple[List[viam.proto.app.OrganizationMember], List[viam.proto.app.OrganizationInvite]]: A tuple containing two lists; the first
787
+ [0] of organization members, and the second [1] of organization invites.
788
+
789
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listorganizationmembers>`_.
790
+ """
791
+ request = ListOrganizationMembersRequest(organization_id=org_id)
792
+ response: ListOrganizationMembersResponse = await self._app_client.ListOrganizationMembers(request, metadata=self._metadata)
793
+ return list(response.members), list(response.invites)
794
+
795
+ async def create_organization_invite(
796
+ self,
797
+ org_id: str,
798
+ email: str,
799
+ authorizations: Optional[List[Authorization]] = None,
800
+ send_email_invite: bool = True,
801
+ ) -> OrganizationInvite:
802
+ """Creates an organization invite and sends it via email.
803
+
804
+ ::
805
+
806
+ await cloud.create_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
807
+
808
+ Args:
809
+ org_id (str): The ID of the organization to create an invite for.
810
+ You can obtain your organization ID from the Viam app's organization settings page.
811
+ email (str): The email address to send the invite to.
812
+ authorizations (Optional[List[viam.proto.app.Authorization]]): Specifications of the
813
+ authorizations to include in the invite. If not provided, full owner permissions will
814
+ be granted.
815
+ send_email_invite (Optional[bool]): Whether or not an email should be sent to the recipient of an invite.
816
+ The user must accept the email to be added to the associated authorizations.
817
+ When set to false, the user automatically receives the associated authorization
818
+ on the next login of the user with the associated email address.
819
+
820
+ Raises:
821
+ GRPCError: if an invalid email is provided, or if the user is already a member of the org.
822
+
823
+ Returns:
824
+ OrganizationInvite: The organization invite.
825
+
826
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createorganizationinvite>`_.
827
+ """
828
+ request = CreateOrganizationInviteRequest(
829
+ organization_id=org_id, email=email, authorizations=authorizations, send_email_invite=send_email_invite
830
+ )
831
+ response: CreateOrganizationInviteResponse = await self._app_client.CreateOrganizationInvite(request, metadata=self._metadata)
832
+ return response.invite
833
+
834
+ async def update_organization_invite_authorizations(
835
+ self,
836
+ org_id: str,
837
+ email: str,
838
+ add_authorizations: Optional[List[Authorization]] = None,
839
+ remove_authorizations: Optional[List[Authorization]] = None,
840
+ ) -> OrganizationInvite:
841
+ """Update the authorizations attached to an organization invite that has already been created.
842
+
843
+ Note that an invite can only have one authorization at each resource (for example, organization, location, robot, etc.) level and
844
+ must have at least one authorization overall.
845
+
846
+ ::
847
+
848
+ from viam.proto.app import Authorization
849
+
850
+ auth = Authorization(
851
+ authorization_type="role",
852
+ authorization_id="location_owner",
853
+ resource_type="location", # "robot", "location", or "organization"
854
+ resource_id="012456lni0", # machine id, location id or org id
855
+ identity_id="",
856
+ organization_id="<YOUR-ORG-ID>",
857
+ identity_type=""
858
+ )
859
+
860
+ update_invite = await cloud.update_organization_invite_authorizations(
861
+ org_id="<YOUR-ORG-ID>",
862
+ email="notarealemail@viam.com",
863
+ add_authorizations=[auth]
864
+ )
865
+
866
+ Args:
867
+ org_id (str): The ID of the organization that the invite is for.
868
+ You can obtain your organization ID from the Viam app's organization settings page.
869
+ email (str): Email of the user the invite was sent to.
870
+ add_authorizations (Optional[List[viam.proto.app.Authorization]]): Optional list of authorizations to add to the invite.
871
+ remove_authorizations (Optional[List[viam.proto.app.Authorization]]): Optional list of authorizations to remove from the invite.
872
+
873
+ Raises:
874
+ GRPCError: If no authorizations are passed or if an invalid combination of authorizations is passed (for example an
875
+ authorization to remove when the invite only contains one authorization).
876
+
877
+ Returns:
878
+ viam.proto.app.OrganizationInvite: The updated invite.
879
+
880
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updateorganizationinviteauthorizations>`_.
881
+ """
882
+ request = UpdateOrganizationInviteAuthorizationsRequest(
883
+ organization_id=org_id, email=email, add_authorizations=add_authorizations, remove_authorizations=remove_authorizations
884
+ )
885
+ response: UpdateOrganizationInviteAuthorizationsResponse = await self._app_client.UpdateOrganizationInviteAuthorizations(
886
+ request, metadata=self._metadata
887
+ )
888
+ return response.invite
889
+
890
+ async def delete_organization_member(self, org_id: str, user_id: str) -> None:
891
+ """Remove a member from the organization.
892
+
893
+ ::
894
+
895
+ member_list, invite_list = await cloud.list_organization_members(org_id="<YOUR-ORG-ID>")
896
+ first_user_id = member_list[0].user_id
897
+
898
+ await cloud.delete_organization_member(org_id="org_id", user_id=first_user_id)
899
+
900
+ Args:
901
+ org_id (str): The ID of the org to remove the user from.
902
+ You can obtain your organization ID from the Viam app's organization settings page.
903
+ user_id (str): The ID of the user to remove.
904
+
905
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleteorganizationmember>`_.
906
+ """
907
+ request = DeleteOrganizationMemberRequest(organization_id=org_id, user_id=user_id)
908
+ await self._app_client.DeleteOrganizationMember(request, metadata=self._metadata)
909
+
910
+ async def delete_organization_invite(self, org_id: str, email: str) -> None:
911
+ """Deletes a pending organization invite.
912
+
913
+ ::
914
+
915
+ await cloud.delete_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
916
+
917
+ Args:
918
+ org_id (str): The ID of the organization that the invite to delete was for.
919
+ You can obtain your organization ID from the Viam app's organization settings page.
920
+ email (str): The email address the pending invite was sent to.
921
+
922
+ Raises:
923
+ GRPCError: If no pending invite is associated with the provided email address.
924
+
925
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleteorganizationinvite>`_.
926
+ """
927
+ request = DeleteOrganizationInviteRequest(organization_id=org_id, email=email)
928
+ await self._app_client.DeleteOrganizationInvite(request, metadata=self._metadata)
929
+
930
+ async def resend_organization_invite(self, org_id: str, email: str) -> OrganizationInvite:
931
+ """Re-sends a pending organization invite email.
932
+
933
+ ::
934
+
935
+ org_invite = await cloud.resend_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
936
+
937
+ Args:
938
+ org_id (str): The ID of the organization that the invite to resend was for.
939
+ You can obtain your organization ID from the Viam app's organization settings page.
940
+ email (str): The email address associated with the invite.
941
+
942
+ Raises:
943
+ GRPCError: If no pending invite is associated with the provided email address.
944
+
945
+ Returns:
946
+ viam.proto.app.OrganizationInvite: The organization invite sent.
947
+
948
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#resendorganizationinvite>`_.
949
+ """
950
+ request = ResendOrganizationInviteRequest(organization_id=org_id, email=email)
951
+ response: ResendOrganizationInviteResponse = await self._app_client.ResendOrganizationInvite(request, metadata=self._metadata)
952
+ return response.invite
953
+
954
+ async def create_location(self, org_id: str, name: str, parent_location_id: Optional[str] = None) -> Location:
955
+ """Create and name a location under the currently authed-to organization and the specified parent location.
956
+
957
+ ::
958
+
959
+ my_new_location = await cloud.create_location(org_id="<YOUR-ORG-ID>", name="Robotville", parent_location_id="111ab12345")
960
+
961
+ Args:
962
+ org_id (str): The ID of the organization to create the location under.
963
+ You can obtain your organization ID from the Viam app's organization settings page.
964
+ name (str): Name of the location.
965
+ parent_location_id (Optional[str]): Optional parent location to put the location under. Defaults to a root-level location if no
966
+ location ID is provided.
967
+
968
+ Raises:
969
+ GRPCError: If either an invalid name (for example, ""), or parent location ID (for example, a nonexistent ID) is passed.
970
+
971
+ Returns:
972
+ viam.proto.app.Location: The newly created location.
973
+
974
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createlocation>`_.
975
+ """
976
+ request = CreateLocationRequest(organization_id=org_id, name=name, parent_location_id=parent_location_id)
977
+ response: CreateLocationResponse = await self._app_client.CreateLocation(request, metadata=self._metadata)
978
+ return response.location
979
+
980
+ async def get_location(self, location_id: Optional[str] = None) -> Location:
981
+ """Get a location.
982
+
983
+ ::
984
+
985
+ location = await cloud.get_location(location_id="123ab12345")
986
+
987
+ Args:
988
+ location_id (Optional[str]): ID of the location to get. Defaults to the location ID provided at `AppClient` instantiation.
989
+
990
+ Raises:
991
+ GRPCError: If an invalid location ID is passed or if one isn't passed and there was no location ID provided at `AppClient`
992
+ instantiation.
993
+
994
+ Returns:
995
+ viam.proto.app.Location: The location.
996
+
997
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getlocation>`_.
998
+ """
999
+ request = GetLocationRequest(location_id=location_id if location_id else self._location_id if self._location_id else "")
1000
+ response: GetLocationResponse = await self._app_client.GetLocation(request, metadata=self._metadata)
1001
+ return response.location
1002
+
1003
+ async def update_location(self, location_id: str, name: Optional[str] = None, parent_location_id: Optional[str] = None) -> Location:
1004
+ """Change the name of a location and/or assign it a new parent location.
1005
+
1006
+ ::
1007
+
1008
+ # The following line takes the location with ID "abc12abcde" and moves it to be a
1009
+ # sub-location of the location with ID "xyz34xxxxx"
1010
+ my_updated_location = await cloud.update_location(
1011
+ location_id="abc12abcde",
1012
+ name="",
1013
+ parent_location_id="xyz34xxxxx",
1014
+ )
1015
+
1016
+ # The following line changes the name of the location without changing its parent location
1017
+ my_updated_location = await cloud.update_location(
1018
+ location_id="abc12abcde",
1019
+ name="Land Before Robots"
1020
+ )
1021
+
1022
+ # The following line moves the location back up to be a top level location without changing its name
1023
+ my_updated_location = await cloud.update_location(
1024
+ location_id="abc12abcde",
1025
+ name="",
1026
+ parent_location_id=""
1027
+ )
1028
+
1029
+ Args:
1030
+ location_id (str): ID of the location to update. Must be specified.
1031
+ name (Optional[str]): Optional new name to be updated on the location. Defaults to the empty string "" (that is, the name
1032
+ doesn't change).
1033
+ parent_location_id(Optional[str]): Optional ID of new parent location to move the location under. Defaults to the empty string
1034
+ "" (that is, no new parent location is assigned).
1035
+
1036
+ Raises:
1037
+ GRPCError: If either an invalid location ID, name, or parent location ID is passed.
1038
+
1039
+ Returns:
1040
+ viam.proto.app.Location: The newly updated location.
1041
+
1042
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updatelocation>`_.
1043
+ """
1044
+ request = UpdateLocationRequest(location_id=location_id, name=name, parent_location_id=parent_location_id)
1045
+ response: UpdateLocationResponse = await self._app_client.UpdateLocation(request, metadata=self._metadata)
1046
+ return response.location
1047
+
1048
+ async def delete_location(self, location_id: str) -> None:
1049
+ """Delete a location.
1050
+
1051
+ ::
1052
+
1053
+ await cloud.delete_location(location_id="abc12abcde")
1054
+
1055
+ Args:
1056
+ location_id (str): ID of the location to delete. Must be specified.
1057
+
1058
+ Raises:
1059
+ GRPCError: If an invalid location ID is passed.
1060
+
1061
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deletelocation>`_.
1062
+ """
1063
+ request = DeleteLocationRequest(location_id=location_id)
1064
+ await self._app_client.DeleteLocation(request, metadata=self._metadata)
1065
+
1066
+ async def list_locations(self, org_id: str) -> List[Location]:
1067
+ """Get a list of all locations under the currently authed-to organization.
1068
+
1069
+ ::
1070
+
1071
+ locations = await cloud.list_locations("<YOUR-ORG-ID>")
1072
+
1073
+ Args:
1074
+ org_id (str): The ID of the org to list locations for.
1075
+ You can obtain your organization ID from the Viam app's organization settings page.
1076
+
1077
+ Returns:
1078
+ List[viam.proto.app.Location]: The list of locations.
1079
+
1080
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listlocations>`_.
1081
+ """
1082
+ request = ListLocationsRequest(organization_id=org_id)
1083
+ response: ListLocationsResponse = await self._app_client.ListLocations(request, metadata=self._metadata)
1084
+ return list(response.locations)
1085
+
1086
+ async def share_location(self, organization_id: str, location_id: str) -> None:
1087
+ """Share a location with an organization.
1088
+
1089
+ ::
1090
+
1091
+ await cloud.share_location("<YOUR-ORG-ID>", "<YOUR-LOCATION-ID>")
1092
+
1093
+ Args:
1094
+ organization_id (str): The ID of the organization.
1095
+ location_id (str): The ID of the location.
1096
+
1097
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#sharelocation>`_.
1098
+ """
1099
+ request = ShareLocationRequest(location_id=location_id, organization_id=organization_id)
1100
+ await self._app_client.ShareLocation(request, metadata=self._metadata)
1101
+
1102
+ async def unshare_location(self, organization_id: str, location_id: str) -> None:
1103
+ """Stop sharing a location with an organization.
1104
+
1105
+ ::
1106
+
1107
+ await cloud.unshare_location("<YOUR-ORG-ID>", "<YOUR-LOCATION-ID>")
1108
+
1109
+ Args:
1110
+ organization_id (str): The ID of the organization.
1111
+ location_id (str): The ID of the location.
1112
+
1113
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#unsharelocation>`_.
1114
+ """
1115
+ request = UnshareLocationRequest(location_id=location_id, organization_id=organization_id)
1116
+ await self._app_client.UnshareLocation(request, metadata=self._metadata)
1117
+
1118
+ async def location_auth(self, location_id: Optional[str] = None) -> LocationAuth:
1119
+ """Get a location's `LocationAuth` (location secret(s)).
1120
+
1121
+ ::
1122
+
1123
+ loc_auth = await cloud.location_auth(location_id="123xy12345")
1124
+
1125
+ Args:
1126
+ location_id (str): ID of the location to retrieve `LocationAuth` from. Defaults to the location ID provided at `AppClient`
1127
+ instantiation.
1128
+
1129
+ Raises:
1130
+ GRPCError: If an invalid location ID is passed or if one isn't passed and there was no location ID provided at `AppClient`
1131
+ instantiation.
1132
+
1133
+ Returns:
1134
+ viam.proto.app.LocationAuth: The `LocationAuth` containing location secrets.
1135
+
1136
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#locationauth>`_.
1137
+ """
1138
+ request = LocationAuthRequest(location_id=location_id if location_id else self._location_id if self._location_id else "")
1139
+ response: LocationAuthResponse = await self._app_client.LocationAuth(request, metadata=self._metadata)
1140
+ return response.auth
1141
+
1142
+ async def create_location_secret(self, location_id: Optional[str] = None) -> LocationAuth:
1143
+ """Create a new location secret.
1144
+
1145
+ ::
1146
+
1147
+ new_loc_auth = await cloud.create_location_secret(location_id="123xy12345")
1148
+
1149
+ Args:
1150
+ location_id (Optional[str]): ID of the location to generate a new secret for. Defaults to the location ID provided at
1151
+ `AppClient` instantiation.
1152
+
1153
+ Raises:
1154
+ GRPCError: If an invalid location ID is passed or one isn't passed and there was no location ID provided at `AppClient`
1155
+ instantiation.
1156
+
1157
+ Returns:
1158
+ viam.proto.app.LocationAuth: The specified location's `LocationAuth` containing the newly created secret.
1159
+
1160
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createlocationsecret>`_.
1161
+ """
1162
+ request = CreateLocationSecretRequest(location_id=location_id if location_id else self._location_id if self._location_id else "")
1163
+ response: CreateLocationSecretResponse = await self._app_client.CreateLocationSecret(request, metadata=self._metadata)
1164
+ return response.auth
1165
+
1166
+ async def delete_location_secret(self, secret_id: str, location_id: Optional[str] = None) -> None:
1167
+ """Delete a location secret.
1168
+
1169
+ ::
1170
+
1171
+ await cloud.delete_location_secret(
1172
+ secret_id="abcd123-456-7890ab-cxyz98-989898xyzxyz",
1173
+ location_id="123xy12345"
1174
+ )
1175
+
1176
+ Args:
1177
+ location_id (str): ID of the location to delete secret from. Defaults to the location ID provided at `AppClient` instantiation.
1178
+ secret_id (str): ID of the secret to delete.
1179
+
1180
+ Raises:
1181
+ GRPCError: If either an invalid location ID or secret ID is passed or a location ID isn't passed and there was no location
1182
+ ID provided at `AppClient` instantiation.
1183
+
1184
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deletelocationsecret>`_.
1185
+ """
1186
+ request = DeleteLocationSecretRequest(
1187
+ location_id=location_id if location_id else self._location_id if self._location_id else "", secret_id=secret_id
1188
+ )
1189
+ await self._app_client.DeleteLocationSecret(request, metadata=self._metadata)
1190
+
1191
+ async def get_robot(self, robot_id: str) -> Robot:
1192
+ """Get a machine.
1193
+
1194
+ ::
1195
+
1196
+ machine = await cloud.get_robot(robot_id="1a123456-x1yz-0ab0-a12xyzabc")
1197
+
1198
+ Args:
1199
+ robot_id (str): ID of the machine to get. You can copy this value from the URL of the machine's page.
1200
+
1201
+ Raises:
1202
+ GRPCError: If an invalid machine ID is passed.
1203
+
1204
+ Returns:
1205
+ viam.proto.app.Robot: The machine.
1206
+
1207
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobot>`_.
1208
+ """
1209
+ request = GetRobotRequest(id=robot_id)
1210
+ response: GetRobotResponse = await self._app_client.GetRobot(request, metadata=self._metadata)
1211
+ return response.robot
1212
+
1213
+ async def get_rover_rental_robots(self, org_id: str) -> List[RoverRentalRobot]:
1214
+ """Returns a list of rover rental robots within an org.
1215
+
1216
+ ::
1217
+
1218
+ rental_robots = await cloud.get_rover_rental_robots()
1219
+
1220
+ Args:
1221
+ org_id (str): The ID of the organization to list rover rental robots for.
1222
+ You can obtain your organization ID from the Viam app's organization settings page.
1223
+
1224
+ Returns:
1225
+ List[viam.proto.app.RoverRentalRobot]: The list of rover rental robots.
1226
+
1227
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/>`_.
1228
+ """
1229
+ request = GetRoverRentalRobotsRequest(org_id=org_id)
1230
+ response: GetRoverRentalRobotsResponse = await self._app_client.GetRoverRentalRobots(request, metadata=self._metadata)
1231
+ return list(response.robots)
1232
+
1233
+ async def get_robot_parts(self, robot_id: str) -> List[RobotPart]:
1234
+ """Get a list of all the parts under a specific machine.
1235
+
1236
+ ::
1237
+
1238
+ list_of_parts = await cloud.get_robot_parts(
1239
+ robot_id="1a123456-x1yz-0ab0-a12xyzabc"
1240
+ )
1241
+
1242
+ Args:
1243
+ robot_id (str): ID of the machine to get parts from.
1244
+
1245
+ Raises:
1246
+ GRPCError: If an invalid machine ID is passed.
1247
+
1248
+ Returns:
1249
+ List[viam.app.app_client.RobotPart]: The list of machine parts.
1250
+
1251
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobotparts>`_.
1252
+ """
1253
+ request = GetRobotPartsRequest(robot_id=robot_id)
1254
+ response: GetRobotPartsResponse = await self._app_client.GetRobotParts(request, metadata=self._metadata)
1255
+ return [RobotPart.from_proto(robot_part=part) for part in response.parts]
1256
+
1257
+ async def get_robot_part(self, robot_part_id: str, dest: Optional[str] = None, indent: int = 4) -> RobotPart:
1258
+ """Get a machine part.
1259
+
1260
+ ::
1261
+
1262
+ my_robot_part = await cloud.get_robot_part(
1263
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22"
1264
+ )
1265
+ # Check if machine is live (last access time less than 10 sec ago)
1266
+ if (time.time() - my_robot_part.last_access.timestamp()) <= 10000:
1267
+ print("Machine is live.")
1268
+
1269
+ Args:
1270
+ robot_part_id (str): ID of the machine part to get. You can retrieve this value by navigating to the machine's page,
1271
+ clicking on the part status dropdown, and clicking the copy icon next to Part ID.
1272
+ dest (Optional[str]): Optional filepath to write the machine part's config file in JSON format to.
1273
+ indent (int): Size (in number of spaces) of indent when writing config to `dest`. Defaults to 4.
1274
+
1275
+ Raises:
1276
+ GRPCError: If an invalid machine part ID is passed.
1277
+
1278
+ Returns:
1279
+ viam.app.app_client.RobotPart: The machine part.
1280
+
1281
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobotpart>`_.
1282
+ """
1283
+ request = GetRobotPartRequest(id=robot_part_id)
1284
+ response: GetRobotPartResponse = await self._app_client.GetRobotPart(request, metadata=self._metadata)
1285
+
1286
+ if dest:
1287
+ try:
1288
+ file = open(dest, "w")
1289
+ file.write(f"{json.dumps(json.loads(response.config_json), indent=indent)}")
1290
+ file.flush()
1291
+ except Exception as e:
1292
+ LOGGER.error(f"Failed to write config JSON to file {dest}", exc_info=e)
1293
+
1294
+ return RobotPart.from_proto(robot_part=response.part)
1295
+
1296
+ async def get_robot_part_logs(
1297
+ self,
1298
+ robot_part_id: str,
1299
+ filter: Optional[str] = None,
1300
+ dest: Optional[str] = None,
1301
+ log_levels: List[str] = [],
1302
+ num_log_entries: int = 100,
1303
+ ) -> List[LogEntry]:
1304
+ """Get the logs associated with a robot part.
1305
+
1306
+ ::
1307
+
1308
+ part_logs = await cloud.get_robot_part_logs(
1309
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22",
1310
+ num_log_entries=20
1311
+ )
1312
+
1313
+ Args:
1314
+ robot_part_id (str): ID of the machine part to get logs from.
1315
+ filter (Optional[str]): Only include logs with messages that contain the string `filter`. Defaults to empty string "" (that is,
1316
+ no filter).
1317
+ dest (Optional[str]): Optional filepath to write the log entries to.
1318
+ log_levels (List[str]): List of log levels for which entries should be returned. Defaults to empty list, which returns all logs.
1319
+ num_log_entries (int): Number of log entries to return. Passing 0 returns all logs. Defaults to 100. All logs or the first
1320
+ `num_log_entries` logs will be returned, whichever comes first.
1321
+
1322
+ Raises:
1323
+ GRPCError: If an invalid robot part ID is passed.
1324
+
1325
+ Returns:
1326
+ List[viam.app.app_client.LogEntry]: The list of log entries.
1327
+
1328
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobotpartlogs>`_.
1329
+ """
1330
+ if num_log_entries < 0:
1331
+ raise ValueError("'num_log_entries must be at least 0.")
1332
+ logs_left = num_log_entries
1333
+ page_token = ""
1334
+ logs = []
1335
+
1336
+ while True:
1337
+ new_logs, next_page_token = await self._get_robot_part_logs(
1338
+ robot_part_id=robot_part_id, filter=filter if filter else "", page_token=page_token, log_levels=log_levels
1339
+ )
1340
+ if num_log_entries != 0 and len(new_logs) > logs_left:
1341
+ logs += new_logs[0:logs_left]
1342
+ break
1343
+ logs += new_logs
1344
+ logs_left -= len(new_logs)
1345
+ if not next_page_token or next_page_token == "" or logs_left == 0:
1346
+ break
1347
+ page_token = next_page_token
1348
+
1349
+ if dest:
1350
+ try:
1351
+ file = open(dest, "w")
1352
+ for log in logs:
1353
+ time = log.time
1354
+ level = log.level.upper()
1355
+ logger_name = log.logger_name.split(".")[0]
1356
+ file_name = log.caller["File"] + ":" + str(int(log.caller["Line"]))
1357
+ message = log.message
1358
+ file.write(f"{time}\t{level}\t{logger_name}\t{file_name:<64}{message}\n")
1359
+ file.flush()
1360
+ except Exception as e:
1361
+ LOGGER.error(f"Failed to write robot part from robot part with ID [{robot_part_id}]logs to file {dest}", exc_info=e)
1362
+
1363
+ return logs
1364
+
1365
+ async def _get_robot_part_logs(
1366
+ self, robot_part_id: str, filter: str, page_token: str, log_levels: List[str]
1367
+ ) -> Tuple[List[LogEntry], str]:
1368
+ request = GetRobotPartLogsRequest(id=robot_part_id, filter=filter, page_token=page_token, levels=log_levels)
1369
+ response: GetRobotPartLogsResponse = await self._app_client.GetRobotPartLogs(request, metadata=self._metadata)
1370
+ return [LogEntry.from_proto(log) for log in response.logs], response.next_page_token
1371
+
1372
+ async def tail_robot_part_logs(
1373
+ self, robot_part_id: str, errors_only: bool = True, filter: Optional[str] = None
1374
+ ) -> _LogsStream[List[LogEntry]]:
1375
+ """Get an asynchronous iterator that receives live machine part logs.
1376
+
1377
+ ::
1378
+
1379
+ logs_stream = await cloud.tail_robot_part_logs(
1380
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22"
1381
+ )
1382
+
1383
+ Args:
1384
+ robot_part_id (str): ID of the machine part to retrieve logs from.
1385
+ errors_only (bool): Boolean specifying whether or not to only include error logs. Defaults to True.
1386
+ filter (Optional[str]): Only include logs with messages that contain the string `filter`. Defaults to empty string "" (that is,
1387
+ no filter).
1388
+
1389
+ Returns:
1390
+ _LogsStream[List[LogEntry]]: The asynchronous iterator receiving live machine part logs.
1391
+ """
1392
+
1393
+ async def read() -> AsyncIterator[List[LogEntry]]:
1394
+ async with self._app_client.TailRobotPartLogs.open(metadata=self._metadata) as stream:
1395
+ await stream.send_message(
1396
+ TailRobotPartLogsRequest(id=robot_part_id, errors_only=errors_only, filter=filter if filter else "")
1397
+ )
1398
+
1399
+ while True:
1400
+ response: Optional[TailRobotPartLogsResponse] = await stream.recv_message()
1401
+ if response is None or len(response.logs) == 0:
1402
+ break
1403
+ logs = [LogEntry.from_proto(log) for log in response.logs]
1404
+ yield logs
1405
+
1406
+ return _LogsStreamWithIterator(read())
1407
+
1408
+ async def get_robot_part_history(self, robot_part_id: str) -> List[RobotPartHistoryEntry]:
1409
+ """Get a list containing the history of a machine part.
1410
+
1411
+ ::
1412
+
1413
+ part_history = await cloud.get_robot_part_history(
1414
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22"
1415
+ )
1416
+
1417
+ Args:
1418
+ robot_part_id (str): ID of the machine part to retrieve history from.
1419
+
1420
+ Raises:
1421
+ GRPCError: If an invalid machine part ID is provided.
1422
+
1423
+ Returns:
1424
+ List[viam.app.app_client.RobotPartHistoryEntry]: The list of the machine part's history.
1425
+
1426
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobotapikeys>`_.
1427
+ """
1428
+ request = GetRobotPartHistoryRequest(id=robot_part_id)
1429
+ response: GetRobotPartHistoryResponse = await self._app_client.GetRobotPartHistory(request, metadata=self._metadata)
1430
+ return [RobotPartHistoryEntry.from_proto(part_history) for part_history in response.history]
1431
+
1432
+ async def update_robot_part(self, robot_part_id: str, name: str, robot_config: Optional[Mapping[str, Any]] = None) -> RobotPart:
1433
+ """Change the name and assign an optional new configuration to a machine part.
1434
+
1435
+ ::
1436
+
1437
+ my_machine_part = await cloud.update_robot_part(
1438
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22"
1439
+ )
1440
+
1441
+ Args:
1442
+ robot_part_id (str): ID of the robot part to update.
1443
+ name (str): New name to be updated on the robot part.
1444
+ robot_config (Mapping[str, Any]): Optional new config represented as a dictionary to be updated on the machine part. The machine
1445
+ part's config will remain as is (no change) if one isn't passed.
1446
+
1447
+ Raises:
1448
+ GRPCError: If either an invalid machine part ID, name, or config is passed.
1449
+
1450
+ Returns:
1451
+ viam.app.app_client.RobotPart: The newly updated robot part.
1452
+
1453
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updaterobotpart>`_.
1454
+ """
1455
+ request = UpdateRobotPartRequest(id=robot_part_id, name=name, robot_config=dict_to_struct(robot_config) if robot_config else None)
1456
+ response: UpdateRobotPartResponse = await self._app_client.UpdateRobotPart(request, metadata=self._metadata)
1457
+ return RobotPart.from_proto(robot_part=response.part)
1458
+
1459
+ async def new_robot_part(self, robot_id: str, part_name: str) -> str:
1460
+ """Create a new machine part.
1461
+
1462
+ ::
1463
+
1464
+ new_part_id = await cloud.new_robot_part(
1465
+ robot_id="1a123456-x1yz-0ab0-a12xyzabc", part_name="myNewSubPart"
1466
+ )
1467
+
1468
+ Args:
1469
+ robot_id (str): ID of the machine to create a new part for.
1470
+ part_name (str): Name of the new part.
1471
+
1472
+ Raises:
1473
+ GRPCError: If either an invalid machine ID or name is passed.
1474
+
1475
+ Returns:
1476
+ str: The new machine part's ID.
1477
+
1478
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#newrobotpart>`_.
1479
+ """
1480
+ request = NewRobotPartRequest(robot_id=robot_id, part_name=part_name)
1481
+ response: NewRobotPartResponse = await self._app_client.NewRobotPart(request, metadata=self._metadata)
1482
+ return response.part_id
1483
+
1484
+ async def delete_robot_part(self, robot_part_id: str) -> None:
1485
+ """Delete the specified machine part.
1486
+
1487
+ ::
1488
+
1489
+ await cloud.delete_robot_part(
1490
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22"
1491
+ )
1492
+
1493
+ Args:
1494
+ robot_part_id (str): ID of the machine part to delete. Must be specified.
1495
+
1496
+ Raises:
1497
+ GRPCError: If an invalid machine part ID is passed.
1498
+
1499
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleterobotpart>`_.
1500
+ """
1501
+ request = DeleteRobotPartRequest(part_id=robot_part_id)
1502
+ await self._app_client.DeleteRobotPart(request, metadata=self._metadata)
1503
+
1504
+ async def get_robot_api_keys(self, robot_id: str) -> List[APIKeyWithAuthorizations]:
1505
+ """Gets the API Keys for the machine.
1506
+
1507
+ ::
1508
+
1509
+ api_keys = await cloud.get_robot_api_keys(robot_id="robot-id")
1510
+
1511
+ Args:
1512
+ robot_id (str): The ID of the machine.
1513
+
1514
+ Returns:
1515
+ List[APIKeyWithAuthorizations]: The list of API keys.
1516
+
1517
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getrobotapikeys>`_.
1518
+ """
1519
+ request = GetRobotAPIKeysRequest(robot_id=robot_id)
1520
+ response: GetRobotAPIKeysResponse = await self._app_client.GetRobotAPIKeys(request, metadata=self._metadata)
1521
+ return list(response.api_keys)
1522
+
1523
+ async def mark_part_as_main(self, robot_part_id: str) -> None:
1524
+ """Mark a machine part as the main part of a machine.
1525
+
1526
+ ::
1527
+
1528
+ await cloud.mark_part_as_main(
1529
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
1530
+
1531
+ Args:
1532
+ robot_part_id (str): ID of the machine part to mark as main.
1533
+
1534
+ Raises:
1535
+ GRPCError: If an invalid machine part ID is passed.
1536
+
1537
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#markpartasmain>`_.
1538
+ """
1539
+ request = MarkPartAsMainRequest(part_id=robot_part_id)
1540
+ await self._app_client.MarkPartAsMain(request, metadata=self._metadata)
1541
+
1542
+ async def mark_part_for_restart(self, robot_part_id: str) -> None:
1543
+ """Mark the specified machine part for restart.
1544
+
1545
+ ::
1546
+
1547
+ await cloud.mark_part_for_restart(
1548
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
1549
+
1550
+ Args:
1551
+ robot_part_id (str): ID of the machine part to mark for restart.
1552
+
1553
+ Raises:
1554
+ GRPCError: If an invalid machine part ID is passed.
1555
+
1556
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#markpartforrestart>`_.
1557
+ """
1558
+ request = MarkPartForRestartRequest(part_id=robot_part_id)
1559
+ await self._app_client.MarkPartForRestart(request, metadata=self._metadata)
1560
+
1561
+ async def create_robot_part_secret(self, robot_part_id: str) -> RobotPart:
1562
+ """Create a machine part secret.
1563
+
1564
+ ::
1565
+
1566
+ part_with_new_secret = await cloud.create_robot_part_secret(
1567
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
1568
+
1569
+ Args:
1570
+ robot_part_id (str): ID of the machine part to create a secret for.
1571
+
1572
+ Raises:
1573
+ GRPCError: If an invalid machine part ID is passed.
1574
+
1575
+ Returns:
1576
+ viam.app.app_client.RobotPart: The machine part the new secret was generated for.
1577
+
1578
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createrobotpartsecret>`_.
1579
+ """
1580
+ request = CreateRobotPartSecretRequest(part_id=robot_part_id)
1581
+ response: CreateRobotPartSecretResponse = await self._app_client.CreateRobotPartSecret(request, metadata=self._metadata)
1582
+ return RobotPart.from_proto(response.part)
1583
+
1584
+ async def delete_robot_part_secret(self, robot_part_id: str, secret_id: str) -> None:
1585
+ """Delete a machine part secret.
1586
+
1587
+ ::
1588
+
1589
+ await cloud.delete_robot_part_secret(
1590
+ robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22",
1591
+ secret_id="123xyz12-abcd-4321-12ab-12xy1xyz12xy")
1592
+
1593
+ Args:
1594
+ robot_part_id (str): ID of the machine part to delete the secret from.
1595
+ secret_id (str): ID of the secret to delete.
1596
+
1597
+ Raises:
1598
+ GRPCError: If an invalid machine part ID or secret ID is passed.
1599
+
1600
+ For more information, see `Fleet Management API <hhttps://docs.viam.com/dev/reference/apis/fleet/#deleterobotpartsecret>`_.
1601
+ """
1602
+ request = DeleteRobotPartSecretRequest(part_id=robot_part_id, secret_id=secret_id)
1603
+ await self._app_client.DeleteRobotPartSecret(request, metadata=self._metadata)
1604
+
1605
+ async def list_robots(self, location_id: Optional[str] = None) -> List[Robot]:
1606
+ """Get a list of all machines under the specified location.
1607
+
1608
+ ::
1609
+
1610
+ list_of_machines = await cloud.list_robots(location_id="123ab12345")
1611
+
1612
+ Args:
1613
+ location_id (Optional[str]): ID of the location to retrieve the machines from. Defaults to the location ID provided at
1614
+ `AppClient` instantiation.
1615
+
1616
+ Raises:
1617
+ GRPCError: If an invalid location ID is passed or one isn't passed and there was no location ID provided at `AppClient`
1618
+ instantiation.
1619
+
1620
+ Returns:
1621
+ List[viam.proto.app.Robot]: The list of robots.
1622
+
1623
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listrobots>`_.
1624
+ """
1625
+ request = ListRobotsRequest(location_id=location_id if location_id else self._location_id if self._location_id else "")
1626
+ response: ListRobotsResponse = await self._app_client.ListRobots(request, metadata=self._metadata)
1627
+ return list(response.robots)
1628
+
1629
+ async def new_robot(self, name: str, location_id: Optional[str] = None) -> str:
1630
+ """Create a new machine.
1631
+
1632
+ ::
1633
+
1634
+ new_machine_id = await cloud.new_robot(name="beepboop", location_id="my-location-id")
1635
+
1636
+ Args:
1637
+ name (str): Name of the new machine.
1638
+ location_id (Optional[str]): ID of the location under which to create the machine. Defaults to the current authorized location.
1639
+
1640
+ Raises:
1641
+ GRPCError: If an invalid location ID is passed or one isn't passed and there was no location ID provided at `AppClient`
1642
+ instantiation.
1643
+
1644
+ Returns:
1645
+ str: The new robot's ID.
1646
+
1647
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#newrobot>`_.
1648
+ """
1649
+ request = NewRobotRequest(location=location_id if location_id else self._location_id if self._location_id else "", name=name)
1650
+ response: NewRobotResponse = await self._app_client.NewRobot(request, metadata=self._metadata)
1651
+ return response.id
1652
+
1653
+ async def update_robot(self, robot_id: str, name: str, location_id: Optional[str] = None) -> Robot:
1654
+ """Change the name of an existing machine.
1655
+
1656
+ ::
1657
+
1658
+ updated_robot = await cloud.update_robot(
1659
+ robot_id="1a123456-x1yz-0ab0-a12xyzabc",
1660
+ name="Orange-Robot",
1661
+ location_id="23ab12345"
1662
+ )
1663
+
1664
+ Args:
1665
+ robot_id (str): ID of the machine to update.
1666
+ name (str): New name to be updated on the machine.
1667
+ location_id (Optional[str]): ID of the location under which the machine exists. Defaults to the location ID provided at
1668
+ `AppClient` instantiation
1669
+
1670
+ Raises:
1671
+ GRPCError: If either an invalid machine ID, name, or location ID is passed or a location ID isn't passed and there was no
1672
+ location ID provided at `AppClient` instantiation.
1673
+
1674
+ Returns:
1675
+ viam.proto.app.Robot: The newly updated machine.
1676
+
1677
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updaterobot>`_.
1678
+ """
1679
+ request = UpdateRobotRequest(
1680
+ id=robot_id, name=name, location=location_id if location_id else self._location_id if self._location_id else ""
1681
+ )
1682
+ response: UpdateRobotResponse = await self._app_client.UpdateRobot(request, metadata=self._metadata)
1683
+ return response.robot
1684
+
1685
+ async def delete_robot(self, robot_id: str) -> None:
1686
+ """Delete the specified machine.
1687
+
1688
+ ::
1689
+
1690
+ await cloud.delete_robot(robot_id="1a123456-x1yz-0ab0-a12xyzabc")
1691
+
1692
+ Args:
1693
+ robot_id (str): ID of the machine to delete.
1694
+
1695
+ Raises:
1696
+ GRPCError: If an invalid machine ID is passed.
1697
+
1698
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleterobot>`_.
1699
+ """
1700
+ request = DeleteRobotRequest(id=robot_id)
1701
+ await self._app_client.DeleteRobot(request, metadata=self._metadata)
1702
+
1703
+ async def list_fragments(
1704
+ self, org_id: str, show_public: bool = True, visibilities: Optional[List[Fragment.Visibility]] = None
1705
+ ) -> List[Fragment]:
1706
+ """Get a list of fragments under the currently authed-to organization.
1707
+
1708
+ ::
1709
+
1710
+ fragments_list = await cloud.list_fragments(org_id="org-id", visibilities=[])
1711
+
1712
+ Args:
1713
+ org_id (str): The ID of the organization to list fragments for.
1714
+ You can obtain your organization ID from the Viam app's organization settings page.
1715
+ show_public (bool): Optional boolean specifying whether or not to only show public fragments. If True, only public fragments
1716
+ will return. If False, only private fragments will return. Defaults to True.
1717
+
1718
+ .. deprecated:: 0.25.0
1719
+ Use ``visibilities`` instead.
1720
+ visibilities (Optional[List[Fragment.Visibility]]): List of FragmentVisibilities specifying which types of fragments to include
1721
+ in the results. If empty, by default only public fragments will be returned.
1722
+
1723
+ Returns:
1724
+ List[viam.app.app_client.Fragment]: The list of fragments.
1725
+
1726
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listfragments>`_.
1727
+ """
1728
+ request = ListFragmentsRequest(
1729
+ organization_id=org_id,
1730
+ fragment_visibility=map(Fragment.Visibility.to_proto, visibilities if visibilities else []),
1731
+ show_public=show_public,
1732
+ )
1733
+ response: ListFragmentsResponse = await self._app_client.ListFragments(request, metadata=self._metadata)
1734
+ return [Fragment.from_proto(fragment=fragment) for fragment in response.fragments]
1735
+
1736
+ async def get_fragment(self, fragment_id: str) -> Fragment:
1737
+ """Get a fragment.
1738
+
1739
+ ::
1740
+
1741
+ # Get a fragment and print its name and when it was created.
1742
+ the_fragment = await cloud.get_fragment(
1743
+ fragment_id="12a12ab1-1234-5678-abcd-abcd01234567")
1744
+ print("Name: ", the_fragment.name, "\\nCreated on: ", the_fragment.created_on)
1745
+
1746
+ Args:
1747
+ fragment_id (str): ID of the fragment to get.
1748
+
1749
+ Raises:
1750
+ GRPCError: If an invalid fragment ID is passed.
1751
+
1752
+ Returns:
1753
+ viam.app.app_client.Fragment: The fragment.
1754
+
1755
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getfragment>`_.
1756
+ """
1757
+ request = GetFragmentRequest(id=fragment_id)
1758
+ response: GetFragmentResponse = await self._app_client.GetFragment(request, metadata=self._metadata)
1759
+ return Fragment.from_proto(fragment=response.fragment)
1760
+
1761
+ async def create_fragment(self, org_id: str, name: str, config: Optional[Mapping[str, Any]] = None) -> Fragment:
1762
+ """Create a new private fragment.
1763
+
1764
+ ::
1765
+
1766
+ new_fragment = await cloud.create_fragment(org_id="org-id", name="cool_smart_machine_to_configure_several_of")
1767
+
1768
+ Args:
1769
+ org_id (str): The ID of the organization to create the fragment within.
1770
+ You can obtain your organization ID from the Viam app's organization settings page.
1771
+ name (str): Name of the fragment.
1772
+ config (Optional[Mapping[str, Any]]): Optional Dictionary representation of new config to assign to specified fragment. Can be
1773
+ assigned by updating the fragment.
1774
+
1775
+ Raises:
1776
+ GRPCError: If an invalid name is passed.
1777
+
1778
+ Returns:
1779
+ viam.app.app_client.Fragment: The newly created fragment.
1780
+
1781
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createfragment>`_.
1782
+ """
1783
+ request = CreateFragmentRequest(name=name, config=dict_to_struct(config) if config else None, organization_id=org_id)
1784
+ response: CreateFragmentResponse = await self._app_client.CreateFragment(request, metadata=self._metadata)
1785
+ return Fragment.from_proto(response.fragment)
1786
+
1787
+ async def update_fragment(
1788
+ self,
1789
+ fragment_id: str,
1790
+ name: str,
1791
+ config: Optional[Mapping[str, Any]] = None,
1792
+ public: Optional[bool] = None,
1793
+ visibility: Optional[Fragment.Visibility] = None,
1794
+ ) -> Fragment:
1795
+ """Update a fragment name AND its config and/or visibility.
1796
+
1797
+ ::
1798
+
1799
+ updated_fragment = await cloud.update_fragment(
1800
+ fragment_id="12a12ab1-1234-5678-abcd-abcd01234567",
1801
+ name="better_name")
1802
+
1803
+ Args:
1804
+ fragment_id (str): ID of the fragment to update.
1805
+ name (str): New name to associate with the fragment.
1806
+ config (Optional[Mapping[str, Any]]): Optional Dictionary representation of new config to assign to specified fragment. Not
1807
+ passing this parameter will leave the fragment's config unchanged.
1808
+ public (bool): Boolean specifying whether the fragment is public. Not passing this parameter will leave the fragment's
1809
+ visibility unchanged. A fragment is private by default when created.
1810
+
1811
+ .. deprecated:: 0.25.0
1812
+ Use ``visibility`` instead.
1813
+ visibility (Optional[FragmentVisibility]): Optional FragmentVisibility list specifying who should be allowed
1814
+ to view the fragment. Not passing this parameter will leave the fragment's visibility unchanged.
1815
+ A fragment is private by default when created.
1816
+
1817
+ Raises:
1818
+ GRPCError: if an invalid ID, name, or config is passed.
1819
+
1820
+ Returns:
1821
+ viam.app.app_client.Fragment: The newly updated fragment.
1822
+
1823
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updatefragment>`_.
1824
+ """
1825
+ request = UpdateFragmentRequest(
1826
+ id=fragment_id,
1827
+ name=name,
1828
+ config=dict_to_struct(config) if config else None,
1829
+ public=public,
1830
+ visibility=visibility.to_proto() if visibility else None,
1831
+ )
1832
+ response: UpdateFragmentResponse = await self._app_client.UpdateFragment(request, metadata=self._metadata)
1833
+ return Fragment.from_proto(response.fragment)
1834
+
1835
+ async def delete_fragment(self, fragment_id: str) -> None:
1836
+ """Delete a fragment.
1837
+
1838
+ ::
1839
+
1840
+ await cloud.delete_fragment(
1841
+ fragment_id="12a12ab1-1234-5678-abcd-abcd01234567")
1842
+
1843
+ Args:
1844
+ fragment_id (str): ID of the fragment to delete.
1845
+
1846
+ Raises:
1847
+ GRPCError: If an invalid fragment ID is passed.
1848
+
1849
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deletefragment>`_.
1850
+ """
1851
+ request = DeleteFragmentRequest(id=fragment_id)
1852
+ await self._app_client.DeleteFragment(request, metadata=self._metadata)
1853
+
1854
+ async def get_fragment_history(
1855
+ self, id: str, page_token: Optional[str] = "", page_limit: Optional[int] = 10
1856
+ ) -> List[FragmentHistoryEntry]:
1857
+ """Get fragment history.
1858
+
1859
+ ::
1860
+
1861
+ fragment_history = await cloud.get_fragment_history(
1862
+ id = "12a12ab1-1234-5678-abcd-abcd01234567",
1863
+ page_token = "pg-token",
1864
+ page_limit = 10
1865
+ )
1866
+
1867
+ Args:
1868
+ id (str): ID of the fragment to fetch history for.
1869
+ page_token (Optional[str]): the page token for the fragment history collection
1870
+ page_limit (Optional[int]): the number of fragment history documents to return in the result.
1871
+ The default page limit is 10.
1872
+
1873
+ Raises:
1874
+ GRPCError: if an invalid fragment id, page token or page limit is passed.
1875
+
1876
+ Returns:
1877
+ viam.app.app_client.FragmentHistoryResponse: A list of documents with the fragment history.
1878
+
1879
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getfragmenthistory>`_.
1880
+ """
1881
+
1882
+ request = GetFragmentHistoryRequest(id=id, page_token=page_token, page_limit=page_limit)
1883
+ response: GetFragmentHistoryResponse = await self._app_client.GetFragmentHistory(request, metadata=self._metadata)
1884
+ return [FragmentHistoryEntry.from_proto(fragment_history) for fragment_history in response.history]
1885
+
1886
+ async def add_role(
1887
+ self,
1888
+ org_id: str,
1889
+ identity_id: str,
1890
+ role: Union[Literal["owner"], Literal["operator"]],
1891
+ resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
1892
+ resource_id: str,
1893
+ ) -> None:
1894
+ """Add a role under the currently authed-to organization.
1895
+
1896
+ ::
1897
+
1898
+ await cloud.add_role(
1899
+ org_id="<YOUR-ORG-ID>",
1900
+ identity_id="abc01234-0123-4567-ab12-a11a00a2aa22",
1901
+ role="owner",
1902
+ resource_type="location",
1903
+ resource_id="111ab12345"
1904
+ )
1905
+
1906
+ Args:
1907
+ org_id (str): The ID of the organization to create the role in.
1908
+ You can obtain your organization ID from the Viam app's organization settings page.
1909
+ identity_id (str): ID of the entity the role belongs to (for example, a user ID).
1910
+ role (Union[Literal["owner"], Literal["operator"]]): The role to add.
1911
+ resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]): Type of the resource to add role to.
1912
+ Must match `resource_id`.
1913
+ resource_id (str): ID of the resource the role applies to (that is, either an organization, location, or robot ID).
1914
+
1915
+ Raises:
1916
+ GRPCError: If either an invalid identity ID, role ID, resource type, or resource ID is passed.
1917
+
1918
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#addrole>`_.
1919
+ """
1920
+ authorization = await self._create_authorization(
1921
+ organization_id=org_id,
1922
+ identity_id=identity_id,
1923
+ identity_type="",
1924
+ role=role,
1925
+ resource_type=resource_type,
1926
+ resource_id=resource_id,
1927
+ )
1928
+ request = AddRoleRequest(authorization=authorization)
1929
+ await self._app_client.AddRole(request, metadata=self._metadata)
1930
+
1931
+ async def remove_role(
1932
+ self,
1933
+ org_id: str,
1934
+ identity_id: str,
1935
+ role: Union[Literal["owner"], Literal["operator"]],
1936
+ resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
1937
+ resource_id: str,
1938
+ ) -> None:
1939
+ """Remove a role under the currently authed-to organization.
1940
+
1941
+ ::
1942
+
1943
+ await cloud.remove_role(
1944
+ org_id="<YOUR-ORG-ID>",
1945
+ identity_id="abc01234-0123-4567-ab12-a11a00a2aa22",
1946
+ role="owner",
1947
+ resource_type="location",
1948
+ resource_id="111ab12345"
1949
+ )
1950
+
1951
+ Args:
1952
+ org_id (str): The ID of the organization the role exists in.
1953
+ You can obtain your organization ID from the Viam app's organization settings page.
1954
+ identity_id (str): ID of the entity the role belongs to (for example, a user ID).
1955
+ role (Union[Literal["owner"], Literal["operator"]]): The role to remove.
1956
+ resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]): Type of the resource the role is being
1957
+ removed from. Must match `resource_id`.
1958
+ resource_id (str): ID of the resource the role applies to (that is, either an organization, location, or robot ID).
1959
+
1960
+ Raises:
1961
+ GRPCError: If either an invalid identity ID, role ID, resource type, or resource ID or is passed.
1962
+
1963
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#removerole>`_.
1964
+ """
1965
+ authorization = await self._create_authorization(
1966
+ organization_id=org_id,
1967
+ identity_id=identity_id,
1968
+ identity_type="",
1969
+ role=role,
1970
+ resource_type=resource_type,
1971
+ resource_id=resource_id,
1972
+ )
1973
+ request = RemoveRoleRequest(authorization=authorization)
1974
+ await self._app_client.RemoveRole(request, metadata=self._metadata)
1975
+
1976
+ async def change_role(
1977
+ self,
1978
+ organization_id: str,
1979
+ old_identity_id: str,
1980
+ old_role: Union[Literal["owner"], Literal["operator"]],
1981
+ old_resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
1982
+ old_resource_id: str,
1983
+ new_identity_id: str,
1984
+ new_role: Union[Literal["owner"], Literal["operator"]],
1985
+ new_resource_type: Union[Literal["organization"], Literal["location"], Literal["robot"]],
1986
+ new_resource_id: str,
1987
+ ) -> None:
1988
+ """Changes a role to a new role.
1989
+
1990
+ ::
1991
+
1992
+ await cloud.change_role(
1993
+ organization_id="<YOUR-ORG-ID>",
1994
+ old_identity_id="abc01234-0123-4567-ab12-a11a00a2aa22",
1995
+ old_role="operator",
1996
+ old_resource_type="location",
1997
+ old_resource_id="111ab12345",
1998
+ new_identity_id="abc01234-0123-4567-ab12-a11a00a2aa22",
1999
+ new_role="owner",
2000
+ new_resource_type="organization",
2001
+ new_resource_id="abc12345"
2002
+ )
2003
+
2004
+ Args:
2005
+ organization_id (str): ID of the organization
2006
+ old_identity_id (str): ID of the entity the role belongs to (for example, a user ID).
2007
+ old_role (Union[Literal["owner"], Literal["operator"]]): The role to be changed.
2008
+ old_resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]): Type of the resource the role is
2009
+ added to. Must match `old_resource_id`.
2010
+ old_resource_id (str): ID of the resource the role applies to (that is, either an organization, location, or robot ID).
2011
+
2012
+ new_identity_id (str): New ID of the entity the role belongs to (for example, a user ID).
2013
+ new_role (Union[Literal["owner"], Literal["operator"]]): The new role.
2014
+ new_resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]): Type of the resource to add role to.
2015
+ Must match `new_resource_id`.
2016
+ new_resource_id (str): New ID of the resource the role applies to (that is, either an organization, location, or robot ID).
2017
+
2018
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#changerole>`_.
2019
+ """
2020
+ old_authorization = await self._create_authorization(
2021
+ organization_id=organization_id,
2022
+ identity_id=old_identity_id,
2023
+ identity_type="",
2024
+ role=old_role,
2025
+ resource_type=old_resource_type,
2026
+ resource_id=old_resource_id,
2027
+ )
2028
+ new_authorization = await self._create_authorization(
2029
+ organization_id=organization_id,
2030
+ identity_id=new_identity_id,
2031
+ identity_type="",
2032
+ role=new_role,
2033
+ resource_type=new_resource_type,
2034
+ resource_id=new_resource_id,
2035
+ )
2036
+ request = ChangeRoleRequest(old_authorization=old_authorization, new_authorization=new_authorization)
2037
+ await self._app_client.ChangeRole(request, metadata=self._metadata)
2038
+
2039
+ async def list_authorizations(self, org_id: str, resource_ids: Optional[List[str]] = None) -> List[Authorization]:
2040
+ """List all authorizations under a specific resource (or resources) within the currently authed-to organization. If no resource IDs
2041
+ are provided, all resource authorizations within the organizations are returned.
2042
+
2043
+ ::
2044
+
2045
+ list_of_auths = await cloud.list_authorizations(
2046
+ org_id="<YOUR-ORG-ID>",
2047
+ resource_ids=["1a123456-x1yz-0ab0-a12xyzabc"])
2048
+
2049
+ Args:
2050
+ org_id: The ID of the organization to list authorizations for.
2051
+ resource_ids (Optional[List[str]]): IDs of the resources to retrieve authorizations from.
2052
+ If None, defaults to all resources.
2053
+
2054
+ Raises:
2055
+ GRPCError: If an invalid resource ID is passed.
2056
+
2057
+ Returns:
2058
+ List[viam.proto.app.Authorization]: The list of authorizations.
2059
+
2060
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listauthorizations>`_.
2061
+ """
2062
+ request = ListAuthorizationsRequest(organization_id=org_id, resource_ids=resource_ids)
2063
+ response: ListAuthorizationsResponse = await self._app_client.ListAuthorizations(request, metadata=self._metadata)
2064
+ return list(response.authorizations)
2065
+
2066
+ async def check_permissions(self, permissions: List[AuthorizedPermissions]) -> List[AuthorizedPermissions]:
2067
+ """Checks validity of a list of permissions.
2068
+
2069
+ ::
2070
+
2071
+ from viam.proto.app import AuthorizedPermissions
2072
+
2073
+ # Check whether the entity you're currently authenticated to has permission to control and/or
2074
+ # read logs from robots in the "organization-identifier123" org
2075
+ permissions = [AuthorizedPermissions(resource_type="organization",
2076
+ resource_id="<YOUR-ORG-ID>",
2077
+ permissions=["control_robot",
2078
+ "read_robot_logs"])]
2079
+
2080
+ filtered_permissions = await cloud.check_permissions(permissions)
2081
+
2082
+ Args:
2083
+ permissions (List[viam.proto.app.AuthorizedPermissions]): the permissions to validate
2084
+ (for example, "read_organization", "control_robot")
2085
+
2086
+ Raises:
2087
+ GRPCError: If the list of permissions to validate is empty.
2088
+
2089
+ Returns:
2090
+ List[viam.proto.app.AuthorizedPermissions]: The permissions argument, with invalid permissions filtered out.
2091
+
2092
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#checkpermissions>`_.
2093
+ """
2094
+ request = CheckPermissionsRequest(permissions=permissions)
2095
+ response: CheckPermissionsResponse = await self._app_client.CheckPermissions(request, metadata=self._metadata)
2096
+ return list(response.authorized_permissions)
2097
+
2098
+ async def get_registry_item(self, item_id: str) -> RegistryItem:
2099
+ """Get registry item by ID.
2100
+
2101
+ ::
2102
+
2103
+ item = await cloud.get_registry_item("item-id")
2104
+
2105
+ Args:
2106
+ item_id (str): The ID of the registry item. This is the namespace and name of the item in the
2107
+ form `namespace:name`. For example, `Viam's csi-cam-pi module's <https://app.viam.com/module/viam/csi-cam-pi>`_ item ID
2108
+ would be `viam:csi-cam-pi`. You can also use `org-id:name`. For example,
2109
+ `abc01234-0123-4567-ab12-a11a00a2aa22:training-script`.
2110
+
2111
+ Returns:
2112
+ RegistryItem: The registry item.
2113
+
2114
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getregistryitem>`_.
2115
+ """
2116
+ request = GetRegistryItemRequest(item_id=item_id)
2117
+ response: GetRegistryItemResponse = await self._app_client.GetRegistryItem(request, metadata=self._metadata)
2118
+ return response.item
2119
+
2120
+ async def create_registry_item(self, organization_id: str, name: str, type: PackageType.ValueType) -> None:
2121
+ """Create a registry item
2122
+
2123
+ ::
2124
+
2125
+ from viam.proto.app.packages import PackageType
2126
+
2127
+ await cloud.create_registry_item("<YOUR-ORG-ID>", "name", PackageType.PACKAGE_TYPE_ML_MODEL)
2128
+
2129
+ Args:
2130
+ organization_id (str): The organization to create the registry item under.
2131
+ name (str): The name of the registry item, which must be unique within your org.
2132
+ type (PackageType.ValueType): The type of the item in the registry.
2133
+
2134
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createregistryitem>`_.
2135
+ """
2136
+ request = CreateRegistryItemRequest(organization_id=organization_id, name=name, type=type)
2137
+ await self._app_client.CreateRegistryItem(request, metadata=self._metadata)
2138
+
2139
+ async def update_registry_item(
2140
+ self, item_id: str, type: PackageType.ValueType, description: str, visibility: Visibility.ValueType
2141
+ ) -> None:
2142
+ """Update a registry item.
2143
+
2144
+ ::
2145
+
2146
+ from viam.proto.app.packages import PackageType
2147
+ from viam.proto.app import Visibility
2148
+
2149
+ await cloud.update_registry_item(
2150
+ "your-namespace:your-name",
2151
+ PackageType.PACKAGE_TYPE_ML_TRAINING,
2152
+ "description",
2153
+ Visibility.VISIBILITY_PUBLIC
2154
+ )
2155
+
2156
+ Args:
2157
+ item_id (str): The ID of the registry item, containing either the namespace and module name
2158
+ (for example, `my-org:my-module`) or organization ID and module name (`org-id:my-module`).
2159
+ type (PackageType.ValueType): The type of the item in the registry.
2160
+ description (str): The description of the registry item.
2161
+ visibility (Visibility.ValueType): The visibility of the registry item.
2162
+
2163
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updateregistryitem>`_.
2164
+ """
2165
+
2166
+ request = UpdateRegistryItemRequest(item_id=item_id, type=type, description=description, visibility=visibility)
2167
+ await self._app_client.UpdateRegistryItem(request, metadata=self._metadata)
2168
+
2169
+ async def list_registry_items(
2170
+ self,
2171
+ organization_id: str,
2172
+ types: List[PackageType.ValueType],
2173
+ visibilities: List[Visibility.ValueType],
2174
+ platforms: List[str],
2175
+ statuses: List[RegistryItemStatus.ValueType],
2176
+ search_term: Optional[str] = None,
2177
+ page_token: Optional[str] = None,
2178
+ ) -> List[RegistryItem]:
2179
+ """List the registry items in an organization.
2180
+
2181
+ ::
2182
+
2183
+ from viam.proto.app.packages import PackageType
2184
+ from viam.proto.app import Visibility, RegistryItemStatus
2185
+
2186
+ # List private, published ml training scripts in your organization
2187
+ registry_items = await cloud.list_registry_items(
2188
+ organization_id="<YOUR-ORG-ID>",
2189
+ types=[PackageType.PACKAGE_TYPE_ML_TRAINING],
2190
+ visibilities=[Visibility.VISIBILITY_PRIVATE],
2191
+ platforms=[""],
2192
+ statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED]
2193
+ )
2194
+
2195
+ # List public, published linux modules in all organizations
2196
+ registry_items = await cloud.list_registry_items(
2197
+ organization_id="",
2198
+ types=[PackageType.PACKAGE_TYPE_MODULE],
2199
+ visibilities=[Visibility.VISIBILITY_PUBLIC],
2200
+ platforms=["linux/any"],
2201
+ statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED]
2202
+ )
2203
+
2204
+ Args:
2205
+ organization_id (str): The ID of the organization to return registry items for.
2206
+ types (List[PackageType.ValueType]): The types of registry items.
2207
+ visibilities (List[Visibility.ValueType]): The visibilities of registry items.
2208
+ platforms (List[str]): The platforms of registry items.
2209
+ statuses (List[RegistryItemStatus.ValueType]): The types of the items in the registry.
2210
+ search_term (Optional[str]): The search term of the registry items.
2211
+ page_token (Optional[str]): The page token of the registry items.
2212
+
2213
+ Returns:
2214
+ List[RegistryItem]: The list of registry items.
2215
+
2216
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listregistryitems>`_.
2217
+ """
2218
+ request = ListRegistryItemsRequest(
2219
+ organization_id=organization_id,
2220
+ types=types,
2221
+ visibilities=visibilities,
2222
+ platforms=platforms,
2223
+ statuses=statuses,
2224
+ search_term=search_term if search_term is not None else "",
2225
+ page_token=page_token if page_token is not None else "",
2226
+ )
2227
+ response: ListRegistryItemsResponse = await self._app_client.ListRegistryItems(request, metadata=self._metadata)
2228
+ return list(response.items)
2229
+
2230
+ async def delete_registry_item(self, item_id: str) -> None:
2231
+ """Delete a registry item
2232
+
2233
+ ::
2234
+
2235
+ await cloud.delete_registry_item("your-namespace:your-name")
2236
+
2237
+ Args:
2238
+ item_id (str): The ID of the deleted registry item, containing either the namespace and module name
2239
+ (for example, `my-org:my-module`) or organization ID and module name (`org-id:my-module`).
2240
+
2241
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deleteregistryitem>`_.
2242
+ """
2243
+ request = DeleteRegistryItemRequest(item_id=item_id)
2244
+ await self._app_client.DeleteRegistryItem(request, metadata=self._metadata)
2245
+
2246
+ async def create_module(self, org_id: str, name: str) -> Tuple[str, str]:
2247
+ """Create a module under the currently authed-to organization.
2248
+
2249
+ ::
2250
+
2251
+ new_module = await cloud.create_module(org_id="org-id", name="cool_new_hoverboard_module")
2252
+ print("Module ID:", new_module[0])
2253
+
2254
+ Args:
2255
+ org_id (str): The ID of the organization to create the module under.
2256
+ You can obtain your organization ID from the Viam app's organization settings page.
2257
+ name (str): The name of the module. Must be unique within your organization.
2258
+
2259
+ Raises:
2260
+ GRPCError: If an invalid name (for example, "") is passed.
2261
+
2262
+ Returns:
2263
+ Tuple[str, str]: A tuple containing the ID [0] of the new module and its URL [1].
2264
+
2265
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createmodule>`_.
2266
+ """
2267
+ request = CreateModuleRequest(organization_id=org_id, name=name)
2268
+ response: CreateModuleResponse = await self._app_client.CreateModule(request, metadata=self._metadata)
2269
+ return response.module_id, response.url
2270
+
2271
+ async def update_module(
2272
+ self,
2273
+ module_id: str,
2274
+ url: str,
2275
+ description: str,
2276
+ models: Optional[List[Model]],
2277
+ entrypoint: str,
2278
+ public: bool = False,
2279
+ ) -> str:
2280
+ """Update the documentation URL, description, models, entrypoint, and/or the visibility of a module.
2281
+
2282
+ ::
2283
+
2284
+ from viam.proto.app import Model
2285
+
2286
+ model = Model(
2287
+ api="rdk:component:base",
2288
+ model="my-group:cool_new_hoverboard_module:wheeled"
2289
+ )
2290
+
2291
+ url_of_my_module = await cloud.update_module(
2292
+ module_id="my-group:cool_new_hoverboard_module",
2293
+ url="https://docsformymodule.viam.com",
2294
+ models=[model],
2295
+ description="A base to support hoverboards.",
2296
+ entrypoint="exec"
2297
+ )
2298
+
2299
+ Args:
2300
+ module_id (str): ID of the module being updated, containing either the namespace and module name
2301
+ (for example, `my-org:my-module`) or organization ID and module name (`org-id:my-module`).
2302
+ url (str): The url to reference for documentation and code (NOT the url of the module itself).
2303
+ description (str): A short description of the module that explains its purpose.
2304
+ models (List[viam.proto.app.Model]): list of models that are available in the module.
2305
+ entrypoint (str): The executable to run to start the module program.
2306
+ public (bool): The visibility that should be set for the module. Defaults to False (private).
2307
+
2308
+ Raises:
2309
+ GRPCError: If either an invalid module ID, URL, list of models, or organization ID is passed.
2310
+
2311
+ Returns:
2312
+ str: The URL of the newly updated module.
2313
+
2314
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#updatemodule>`_.
2315
+ """
2316
+ request = UpdateModuleRequest(
2317
+ module_id=module_id,
2318
+ visibility=Visibility.VISIBILITY_PUBLIC if public else Visibility.VISIBILITY_PRIVATE,
2319
+ url=url,
2320
+ description=description,
2321
+ models=models,
2322
+ entrypoint=entrypoint,
2323
+ )
2324
+ response: UpdateModuleResponse = await self._app_client.UpdateModule(request, metadata=self._metadata)
2325
+ return response.url
2326
+
2327
+ async def upload_module_file(self, module_file_info: Optional[ModuleFileInfo], file: bytes) -> str:
2328
+ """Upload a module file
2329
+
2330
+ ::
2331
+
2332
+ from viam.proto.app import ModuleFileInfo
2333
+
2334
+ module_file_info = ModuleFileInfo(
2335
+ module_id = "sierra:cool_new_hoverboard_module",
2336
+ version = "1.0.0",
2337
+ platform = "darwin/arm64"
2338
+ )
2339
+
2340
+ file_id = await cloud.upload_module_file(
2341
+ module_file_info=module_file_info,
2342
+ file=b"<file>"
2343
+ )
2344
+
2345
+ Args:
2346
+ module_file_info (Optional[viam.proto.app.ModuleFileInfo]): Relevant metadata.
2347
+ file (bytes): Bytes of file to upload.
2348
+
2349
+ Returns:
2350
+ str: URL of uploaded file.
2351
+
2352
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#uploadmodulefile>`_.
2353
+ """
2354
+ request_module_file_info = UploadModuleFileRequest(module_file_info=module_file_info)
2355
+ request_file = UploadModuleFileRequest(file=file)
2356
+ async with self._app_client.UploadModuleFile.open(metadata=self._metadata) as stream:
2357
+ await stream.send_message(request_module_file_info)
2358
+ await stream.send_message(request_file, end=True)
2359
+ response: Union[UploadModuleFileRequest, None] = await stream.recv_message()
2360
+ if not response:
2361
+ await stream.recv_trailing_metadata() # causes us to throw appropriate gRPC error.
2362
+ raise TypeError("Response cannot be empty") # we should never get here, but for typechecking
2363
+ return response.url
2364
+
2365
+ async def get_module(self, module_id: str) -> Module:
2366
+ """Get a module.
2367
+
2368
+ ::
2369
+
2370
+ the_module = await cloud.get_module(module_id="my-group:my-cool-modular-base")
2371
+
2372
+ Args:
2373
+ module_id (str): ID of the module being retrieved, containing either the namespace and module name
2374
+ (for example, `my-org:my-module`) or organization ID and module name (`org-id:my-module`).
2375
+
2376
+ Raises:
2377
+ GRPCError: If an invalid module ID is passed.
2378
+
2379
+ Returns:
2380
+ viam.proto.app.Module: The module.
2381
+
2382
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#getmodule>`_.
2383
+ """
2384
+ request = GetModuleRequest(module_id=module_id)
2385
+ response: GetModuleResponse = await self._app_client.GetModule(request, metadata=self._metadata)
2386
+ return response.module
2387
+
2388
+ async def list_modules(self, org_id: str) -> List[Module]:
2389
+ """List the modules under the currently authed-to organization.
2390
+
2391
+ ::
2392
+
2393
+ modules_list = await cloud.list_modules("<YOUR-ORG-ID>")
2394
+
2395
+ Args:
2396
+ org_id (str): The ID of the organization to list modules for.
2397
+ You can obtain your organization ID from the Viam app's organization settings page.
2398
+
2399
+ Returns:
2400
+ List[viam.proto.app.Module]: The list of modules.
2401
+
2402
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listmodules>`_.
2403
+ """
2404
+ request = ListModulesRequest(organization_id=org_id)
2405
+ response: ListModulesResponse = await self._app_client.ListModules(request, metadata=self._metadata)
2406
+ return list(response.modules)
2407
+
2408
+ # TODO(RSDK-5569): when user-based auth exists, make `name` default to `None` and let
2409
+ # app deal with setting a default.
2410
+ async def create_key(self, org_id: str, authorizations: List[APIKeyAuthorization], name: Optional[str] = None) -> Tuple[str, str]:
2411
+ """Creates a new API key.
2412
+
2413
+ ::
2414
+
2415
+ from viam.app.app_client import APIKeyAuthorization
2416
+
2417
+ auth = APIKeyAuthorization(
2418
+ role="owner",
2419
+ resource_type="robot",
2420
+ resource_id="your-machine-id123"
2421
+ )
2422
+
2423
+ api_key, api_key_id = cloud.create_key(
2424
+ org_id="<YOUR-ORG-ID>",
2425
+ authorizations=[auth],
2426
+ name="my_key"
2427
+ )
2428
+
2429
+ Args:
2430
+ org_id (str): The ID of the organization to create the key for.
2431
+ You can obtain your organization ID from the Viam app's organization settings page.
2432
+ authorizations (List[viam.proto.app.Authorization]): A list of authorizations to associate
2433
+ with the key.
2434
+ name (Optional[str]): A name for the key. If None, defaults to the current timestamp.
2435
+
2436
+ Raises:
2437
+ GRPCError: If the authorizations list is empty.
2438
+
2439
+ Returns:
2440
+ Tuple[str, str]: The api key and api key ID.
2441
+
2442
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createkey>`_.
2443
+ """
2444
+ name = name if name is not None else str(datetime.now())
2445
+ authorizations_pb = [await self._create_authorization_for_new_api_key(org_id, auth) for auth in authorizations]
2446
+ request = CreateKeyRequest(authorizations=authorizations_pb, name=name)
2447
+ response: CreateKeyResponse = await self._app_client.CreateKey(request, metadata=self._metadata)
2448
+ return (response.key, response.id)
2449
+
2450
+ async def delete_key(self, id: str) -> None:
2451
+ """Delete a API key.
2452
+
2453
+ ::
2454
+
2455
+ await cloud.delete_key("key-id")
2456
+
2457
+ Args:
2458
+ id (str): The ID of the API key.
2459
+
2460
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#deletekey>`_.
2461
+ """
2462
+ request = DeleteKeyRequest(id=id)
2463
+ await self._app_client.DeleteKey(request, metadata=self._metadata)
2464
+
2465
+ async def create_key_from_existing_key_authorizations(self, id: str) -> Tuple[str, str]:
2466
+ """Creates a new API key with an existing key's authorizations
2467
+
2468
+ ::
2469
+
2470
+ api_key, api_key_id = await cloud.create_key_from_existing_key_authorizations(
2471
+ id="INSERT YOUR API KEY ID")
2472
+
2473
+ Args:
2474
+ id (str): the ID of the API key to duplication authorizations from
2475
+
2476
+ Returns:
2477
+ Tuple[str, str]: The API key and API key id
2478
+
2479
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#createkeyfromexistingkeyauthorizations>`_.
2480
+ """
2481
+ request = CreateKeyFromExistingKeyAuthorizationsRequest(id=id)
2482
+ response: CreateKeyFromExistingKeyAuthorizationsResponse = await self._app_client.CreateKeyFromExistingKeyAuthorizations(
2483
+ request,
2484
+ metadata=self._metadata,
2485
+ )
2486
+ return (response.key, response.id)
2487
+
2488
+ async def list_keys(self, org_id: str) -> List[APIKeyWithAuthorizations]:
2489
+ """Lists all keys for the currently-authed-to org.
2490
+
2491
+ ::
2492
+
2493
+ keys = await cloud.list_keys(org_id="<YOUR-ORG-ID>")
2494
+
2495
+ Args:
2496
+ org_id (str): The ID of the organization to list API keys for.
2497
+ You can obtain your organization ID from the Viam app's organization settings page.
2498
+
2499
+ Returns:
2500
+ List[viam.proto.app.APIKeyWithAuthorizations]: The existing API keys and authorizations.
2501
+
2502
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#listkeys>`_.
2503
+ """
2504
+ request = ListKeysRequest(org_id=org_id)
2505
+ response: ListKeysResponse = await self._app_client.ListKeys(request, metadata=self._metadata)
2506
+ return list(response.api_keys)
2507
+
2508
+ async def rotate_key(self, id: str) -> Tuple[str, str]:
2509
+ """Rotate an API key.
2510
+
2511
+ ::
2512
+
2513
+ id, key = await cloud.rotate_key("key-id")
2514
+
2515
+ Args:
2516
+ id (str): The ID of the key to be rotated.
2517
+
2518
+ Returns:
2519
+ Tuple[str, str]: The API key and API key id
2520
+
2521
+ For more information, see `Fleet Management API <https://docs.viam.com/dev/reference/apis/fleet/#rotatekey>`_.
2522
+ """
2523
+ request = RotateKeyRequest(id=id)
2524
+ response: RotateKeyResponse = await self._app_client.RotateKey(request, metadata=self._metadata)
2525
+ return response.key, response.id