wandb 0.22.1__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (919) hide show
  1. package_readme.md +97 -0
  2. wandb/__init__.py +248 -0
  3. wandb/__init__.pyi +1230 -0
  4. wandb/__main__.py +3 -0
  5. wandb/_analytics.py +65 -0
  6. wandb/_iterutils.py +73 -0
  7. wandb/_pydantic/__init__.py +30 -0
  8. wandb/_pydantic/base.py +108 -0
  9. wandb/_pydantic/field_types.py +29 -0
  10. wandb/_pydantic/utils.py +80 -0
  11. wandb/_pydantic/v1_compat.py +301 -0
  12. wandb/_strutils.py +40 -0
  13. wandb/agents/__init__.py +0 -0
  14. wandb/agents/pyagent.py +386 -0
  15. wandb/analytics/__init__.py +3 -0
  16. wandb/analytics/sentry.py +267 -0
  17. wandb/apis/__init__.py +50 -0
  18. wandb/apis/attrs.py +52 -0
  19. wandb/apis/importers/__init__.py +1 -0
  20. wandb/apis/importers/internals/internal.py +375 -0
  21. wandb/apis/importers/internals/protocols.py +103 -0
  22. wandb/apis/importers/internals/util.py +78 -0
  23. wandb/apis/importers/mlflow.py +254 -0
  24. wandb/apis/importers/validation.py +108 -0
  25. wandb/apis/importers/wandb.py +1608 -0
  26. wandb/apis/internal.py +241 -0
  27. wandb/apis/normalize.py +83 -0
  28. wandb/apis/paginator.py +138 -0
  29. wandb/apis/public/__init__.py +78 -0
  30. wandb/apis/public/api.py +2513 -0
  31. wandb/apis/public/artifacts.py +1050 -0
  32. wandb/apis/public/automations.py +86 -0
  33. wandb/apis/public/const.py +6 -0
  34. wandb/apis/public/files.py +411 -0
  35. wandb/apis/public/history.py +203 -0
  36. wandb/apis/public/integrations.py +203 -0
  37. wandb/apis/public/jobs.py +744 -0
  38. wandb/apis/public/projects.py +278 -0
  39. wandb/apis/public/query_generator.py +179 -0
  40. wandb/apis/public/registries/__init__.py +7 -0
  41. wandb/apis/public/registries/_freezable_list.py +176 -0
  42. wandb/apis/public/registries/_utils.py +139 -0
  43. wandb/apis/public/registries/registries_search.py +353 -0
  44. wandb/apis/public/registries/registry.py +370 -0
  45. wandb/apis/public/reports.py +597 -0
  46. wandb/apis/public/runs.py +1438 -0
  47. wandb/apis/public/sweeps.py +441 -0
  48. wandb/apis/public/teams.py +237 -0
  49. wandb/apis/public/users.py +179 -0
  50. wandb/apis/public/utils.py +211 -0
  51. wandb/apis/reports/__init__.py +1 -0
  52. wandb/apis/reports/v1/__init__.py +8 -0
  53. wandb/apis/reports/v2/__init__.py +8 -0
  54. wandb/apis/workspaces/__init__.py +8 -0
  55. wandb/automations/__init__.py +73 -0
  56. wandb/automations/_filters/__init__.py +40 -0
  57. wandb/automations/_filters/expressions.py +182 -0
  58. wandb/automations/_filters/operators.py +259 -0
  59. wandb/automations/_filters/run_metrics.py +330 -0
  60. wandb/automations/_generated/__init__.py +104 -0
  61. wandb/automations/_generated/create_automation.py +17 -0
  62. wandb/automations/_generated/create_generic_webhook_integration.py +37 -0
  63. wandb/automations/_generated/delete_automation.py +15 -0
  64. wandb/automations/_generated/enums.py +35 -0
  65. wandb/automations/_generated/fragments.py +293 -0
  66. wandb/automations/_generated/generic_webhook_integrations_by_entity.py +22 -0
  67. wandb/automations/_generated/get_automations.py +24 -0
  68. wandb/automations/_generated/get_automations_by_entity.py +26 -0
  69. wandb/automations/_generated/input_types.py +104 -0
  70. wandb/automations/_generated/integrations_by_entity.py +22 -0
  71. wandb/automations/_generated/operations.py +647 -0
  72. wandb/automations/_generated/slack_integrations_by_entity.py +22 -0
  73. wandb/automations/_generated/update_automation.py +17 -0
  74. wandb/automations/_utils.py +235 -0
  75. wandb/automations/_validators.py +185 -0
  76. wandb/automations/actions.py +220 -0
  77. wandb/automations/automations.py +85 -0
  78. wandb/automations/events.py +284 -0
  79. wandb/automations/integrations.py +45 -0
  80. wandb/automations/scopes.py +78 -0
  81. wandb/beta/workflows.py +324 -0
  82. wandb/bin/gpu_stats.exe +0 -0
  83. wandb/bin/wandb-core +0 -0
  84. wandb/cli/__init__.py +0 -0
  85. wandb/cli/beta.py +93 -0
  86. wandb/cli/beta_sync.py +224 -0
  87. wandb/cli/cli.py +2883 -0
  88. wandb/data_types.py +66 -0
  89. wandb/docker/__init__.py +290 -0
  90. wandb/docker/names.py +40 -0
  91. wandb/docker/wandb-entrypoint.sh +33 -0
  92. wandb/env.py +535 -0
  93. wandb/errors/__init__.py +17 -0
  94. wandb/errors/errors.py +40 -0
  95. wandb/errors/links.py +73 -0
  96. wandb/errors/term.py +415 -0
  97. wandb/errors/util.py +57 -0
  98. wandb/errors/warnings.py +2 -0
  99. wandb/filesync/__init__.py +0 -0
  100. wandb/filesync/dir_watcher.py +404 -0
  101. wandb/filesync/stats.py +100 -0
  102. wandb/filesync/step_checksum.py +142 -0
  103. wandb/filesync/step_prepare.py +179 -0
  104. wandb/filesync/step_upload.py +287 -0
  105. wandb/filesync/upload_job.py +142 -0
  106. wandb/integration/__init__.py +0 -0
  107. wandb/integration/catboost/__init__.py +5 -0
  108. wandb/integration/catboost/catboost.py +182 -0
  109. wandb/integration/cohere/__init__.py +3 -0
  110. wandb/integration/cohere/cohere.py +21 -0
  111. wandb/integration/cohere/resolver.py +347 -0
  112. wandb/integration/diffusers/__init__.py +3 -0
  113. wandb/integration/diffusers/autologger.py +76 -0
  114. wandb/integration/diffusers/pipeline_resolver.py +50 -0
  115. wandb/integration/diffusers/resolvers/__init__.py +9 -0
  116. wandb/integration/diffusers/resolvers/multimodal.py +881 -0
  117. wandb/integration/diffusers/resolvers/utils.py +102 -0
  118. wandb/integration/dspy/__init__.py +5 -0
  119. wandb/integration/dspy/dspy.py +422 -0
  120. wandb/integration/fastai/__init__.py +243 -0
  121. wandb/integration/gym/__init__.py +98 -0
  122. wandb/integration/huggingface/__init__.py +3 -0
  123. wandb/integration/huggingface/huggingface.py +18 -0
  124. wandb/integration/huggingface/resolver.py +213 -0
  125. wandb/integration/keras/__init__.py +11 -0
  126. wandb/integration/keras/callbacks/__init__.py +5 -0
  127. wandb/integration/keras/callbacks/metrics_logger.py +129 -0
  128. wandb/integration/keras/callbacks/model_checkpoint.py +188 -0
  129. wandb/integration/keras/callbacks/tables_builder.py +228 -0
  130. wandb/integration/keras/keras.py +1086 -0
  131. wandb/integration/kfp/__init__.py +6 -0
  132. wandb/integration/kfp/helpers.py +28 -0
  133. wandb/integration/kfp/kfp_patch.py +335 -0
  134. wandb/integration/kfp/wandb_logging.py +182 -0
  135. wandb/integration/langchain/__init__.py +3 -0
  136. wandb/integration/langchain/wandb_tracer.py +49 -0
  137. wandb/integration/lightgbm/__init__.py +239 -0
  138. wandb/integration/lightning/__init__.py +0 -0
  139. wandb/integration/lightning/fabric/__init__.py +3 -0
  140. wandb/integration/lightning/fabric/logger.py +763 -0
  141. wandb/integration/metaflow/__init__.py +9 -0
  142. wandb/integration/metaflow/data_pandas.py +74 -0
  143. wandb/integration/metaflow/data_pytorch.py +75 -0
  144. wandb/integration/metaflow/data_sklearn.py +76 -0
  145. wandb/integration/metaflow/errors.py +13 -0
  146. wandb/integration/metaflow/metaflow.py +327 -0
  147. wandb/integration/openai/__init__.py +3 -0
  148. wandb/integration/openai/fine_tuning.py +480 -0
  149. wandb/integration/openai/openai.py +22 -0
  150. wandb/integration/openai/resolver.py +240 -0
  151. wandb/integration/prodigy/__init__.py +3 -0
  152. wandb/integration/prodigy/prodigy.py +291 -0
  153. wandb/integration/sacred/__init__.py +117 -0
  154. wandb/integration/sagemaker/__init__.py +14 -0
  155. wandb/integration/sagemaker/auth.py +29 -0
  156. wandb/integration/sagemaker/config.py +58 -0
  157. wandb/integration/sagemaker/files.py +2 -0
  158. wandb/integration/sagemaker/resources.py +63 -0
  159. wandb/integration/sb3/__init__.py +3 -0
  160. wandb/integration/sb3/sb3.py +147 -0
  161. wandb/integration/sklearn/__init__.py +37 -0
  162. wandb/integration/sklearn/calculate/__init__.py +32 -0
  163. wandb/integration/sklearn/calculate/calibration_curves.py +125 -0
  164. wandb/integration/sklearn/calculate/class_proportions.py +68 -0
  165. wandb/integration/sklearn/calculate/confusion_matrix.py +93 -0
  166. wandb/integration/sklearn/calculate/decision_boundaries.py +40 -0
  167. wandb/integration/sklearn/calculate/elbow_curve.py +55 -0
  168. wandb/integration/sklearn/calculate/feature_importances.py +67 -0
  169. wandb/integration/sklearn/calculate/learning_curve.py +64 -0
  170. wandb/integration/sklearn/calculate/outlier_candidates.py +69 -0
  171. wandb/integration/sklearn/calculate/residuals.py +86 -0
  172. wandb/integration/sklearn/calculate/silhouette.py +118 -0
  173. wandb/integration/sklearn/calculate/summary_metrics.py +62 -0
  174. wandb/integration/sklearn/plot/__init__.py +35 -0
  175. wandb/integration/sklearn/plot/classifier.py +329 -0
  176. wandb/integration/sklearn/plot/clusterer.py +146 -0
  177. wandb/integration/sklearn/plot/regressor.py +121 -0
  178. wandb/integration/sklearn/plot/shared.py +91 -0
  179. wandb/integration/sklearn/utils.py +184 -0
  180. wandb/integration/tensorboard/__init__.py +10 -0
  181. wandb/integration/tensorboard/log.py +351 -0
  182. wandb/integration/tensorboard/monkeypatch.py +186 -0
  183. wandb/integration/tensorflow/__init__.py +5 -0
  184. wandb/integration/tensorflow/estimator_hook.py +54 -0
  185. wandb/integration/torch/__init__.py +0 -0
  186. wandb/integration/torch/wandb_torch.py +554 -0
  187. wandb/integration/ultralytics/__init__.py +11 -0
  188. wandb/integration/ultralytics/bbox_utils.py +215 -0
  189. wandb/integration/ultralytics/callback.py +528 -0
  190. wandb/integration/ultralytics/classification_utils.py +83 -0
  191. wandb/integration/ultralytics/mask_utils.py +202 -0
  192. wandb/integration/ultralytics/pose_utils.py +103 -0
  193. wandb/integration/weave/__init__.py +6 -0
  194. wandb/integration/weave/interface.py +49 -0
  195. wandb/integration/weave/weave.py +118 -0
  196. wandb/integration/xgboost/__init__.py +11 -0
  197. wandb/integration/xgboost/xgboost.py +189 -0
  198. wandb/integration/yolov8/__init__.py +0 -0
  199. wandb/integration/yolov8/yolov8.py +284 -0
  200. wandb/jupyter.py +538 -0
  201. wandb/mpmain/__init__.py +0 -0
  202. wandb/mpmain/__main__.py +1 -0
  203. wandb/old/__init__.py +0 -0
  204. wandb/old/core.py +53 -0
  205. wandb/old/settings.py +176 -0
  206. wandb/old/summary.py +438 -0
  207. wandb/plot/__init__.py +30 -0
  208. wandb/plot/bar.py +71 -0
  209. wandb/plot/confusion_matrix.py +185 -0
  210. wandb/plot/custom_chart.py +147 -0
  211. wandb/plot/histogram.py +66 -0
  212. wandb/plot/line.py +75 -0
  213. wandb/plot/line_series.py +173 -0
  214. wandb/plot/pr_curve.py +186 -0
  215. wandb/plot/roc_curve.py +163 -0
  216. wandb/plot/scatter.py +66 -0
  217. wandb/plot/utils.py +184 -0
  218. wandb/plot/viz.py +41 -0
  219. wandb/proto/__init__.py +0 -0
  220. wandb/proto/v3/__init__.py +0 -0
  221. wandb/proto/v3/wandb_base_pb2.py +55 -0
  222. wandb/proto/v3/wandb_internal_pb2.py +1738 -0
  223. wandb/proto/v3/wandb_server_pb2.py +209 -0
  224. wandb/proto/v3/wandb_settings_pb2.py +122 -0
  225. wandb/proto/v3/wandb_sync_pb2.py +100 -0
  226. wandb/proto/v3/wandb_telemetry_pb2.py +106 -0
  227. wandb/proto/v4/__init__.py +0 -0
  228. wandb/proto/v4/wandb_base_pb2.py +30 -0
  229. wandb/proto/v4/wandb_internal_pb2.py +384 -0
  230. wandb/proto/v4/wandb_server_pb2.py +64 -0
  231. wandb/proto/v4/wandb_settings_pb2.py +47 -0
  232. wandb/proto/v4/wandb_sync_pb2.py +42 -0
  233. wandb/proto/v4/wandb_telemetry_pb2.py +41 -0
  234. wandb/proto/v5/wandb_base_pb2.py +31 -0
  235. wandb/proto/v5/wandb_internal_pb2.py +385 -0
  236. wandb/proto/v5/wandb_server_pb2.py +65 -0
  237. wandb/proto/v5/wandb_settings_pb2.py +48 -0
  238. wandb/proto/v5/wandb_sync_pb2.py +43 -0
  239. wandb/proto/v5/wandb_telemetry_pb2.py +42 -0
  240. wandb/proto/v6/wandb_base_pb2.py +41 -0
  241. wandb/proto/v6/wandb_internal_pb2.py +395 -0
  242. wandb/proto/v6/wandb_server_pb2.py +75 -0
  243. wandb/proto/v6/wandb_settings_pb2.py +58 -0
  244. wandb/proto/v6/wandb_sync_pb2.py +53 -0
  245. wandb/proto/v6/wandb_telemetry_pb2.py +52 -0
  246. wandb/proto/wandb_base_pb2.py +12 -0
  247. wandb/proto/wandb_deprecated.py +59 -0
  248. wandb/proto/wandb_generate_deprecated.py +30 -0
  249. wandb/proto/wandb_generate_proto.py +50 -0
  250. wandb/proto/wandb_internal_pb2.py +18 -0
  251. wandb/proto/wandb_server_pb2.py +12 -0
  252. wandb/proto/wandb_settings_pb2.py +12 -0
  253. wandb/proto/wandb_sync_pb2.py +12 -0
  254. wandb/proto/wandb_telemetry_pb2.py +12 -0
  255. wandb/py.typed +0 -0
  256. wandb/sdk/__init__.py +37 -0
  257. wandb/sdk/artifacts/__init__.py +0 -0
  258. wandb/sdk/artifacts/_factories.py +22 -0
  259. wandb/sdk/artifacts/_generated/__init__.py +208 -0
  260. wandb/sdk/artifacts/_generated/add_aliases.py +21 -0
  261. wandb/sdk/artifacts/_generated/artifact_by_id.py +17 -0
  262. wandb/sdk/artifacts/_generated/artifact_by_name.py +22 -0
  263. wandb/sdk/artifacts/_generated/artifact_collection_membership_file_urls.py +43 -0
  264. wandb/sdk/artifacts/_generated/artifact_collection_membership_files.py +43 -0
  265. wandb/sdk/artifacts/_generated/artifact_created_by.py +47 -0
  266. wandb/sdk/artifacts/_generated/artifact_file_urls.py +22 -0
  267. wandb/sdk/artifacts/_generated/artifact_type.py +31 -0
  268. wandb/sdk/artifacts/_generated/artifact_used_by.py +43 -0
  269. wandb/sdk/artifacts/_generated/artifact_version_files.py +36 -0
  270. wandb/sdk/artifacts/_generated/artifact_via_membership_by_name.py +26 -0
  271. wandb/sdk/artifacts/_generated/create_artifact_collection_tag_assignments.py +36 -0
  272. wandb/sdk/artifacts/_generated/delete_aliases.py +21 -0
  273. wandb/sdk/artifacts/_generated/delete_artifact.py +28 -0
  274. wandb/sdk/artifacts/_generated/delete_artifact_collection_tag_assignments.py +25 -0
  275. wandb/sdk/artifacts/_generated/delete_artifact_portfolio.py +35 -0
  276. wandb/sdk/artifacts/_generated/delete_artifact_sequence.py +35 -0
  277. wandb/sdk/artifacts/_generated/enums.py +22 -0
  278. wandb/sdk/artifacts/_generated/fetch_artifact_manifest.py +38 -0
  279. wandb/sdk/artifacts/_generated/fetch_linked_artifacts.py +67 -0
  280. wandb/sdk/artifacts/_generated/fetch_registries.py +32 -0
  281. wandb/sdk/artifacts/_generated/fragments.py +524 -0
  282. wandb/sdk/artifacts/_generated/input_types.py +46 -0
  283. wandb/sdk/artifacts/_generated/link_artifact.py +27 -0
  284. wandb/sdk/artifacts/_generated/move_artifact_collection.py +35 -0
  285. wandb/sdk/artifacts/_generated/operations.py +1253 -0
  286. wandb/sdk/artifacts/_generated/project_artifact_collection.py +101 -0
  287. wandb/sdk/artifacts/_generated/project_artifact_collections.py +33 -0
  288. wandb/sdk/artifacts/_generated/project_artifact_type.py +24 -0
  289. wandb/sdk/artifacts/_generated/project_artifact_types.py +24 -0
  290. wandb/sdk/artifacts/_generated/project_artifacts.py +42 -0
  291. wandb/sdk/artifacts/_generated/registry_collections.py +34 -0
  292. wandb/sdk/artifacts/_generated/registry_versions.py +34 -0
  293. wandb/sdk/artifacts/_generated/run_input_artifacts.py +31 -0
  294. wandb/sdk/artifacts/_generated/run_output_artifacts.py +31 -0
  295. wandb/sdk/artifacts/_generated/type_info.py +19 -0
  296. wandb/sdk/artifacts/_generated/unlink_artifact.py +25 -0
  297. wandb/sdk/artifacts/_generated/update_artifact.py +26 -0
  298. wandb/sdk/artifacts/_generated/update_artifact_portfolio.py +35 -0
  299. wandb/sdk/artifacts/_generated/update_artifact_sequence.py +35 -0
  300. wandb/sdk/artifacts/_gqlutils.py +47 -0
  301. wandb/sdk/artifacts/_internal_artifact.py +54 -0
  302. wandb/sdk/artifacts/_models/__init__.py +4 -0
  303. wandb/sdk/artifacts/_models/base_model.py +20 -0
  304. wandb/sdk/artifacts/_validators.py +338 -0
  305. wandb/sdk/artifacts/artifact.py +2683 -0
  306. wandb/sdk/artifacts/artifact_download_logger.py +45 -0
  307. wandb/sdk/artifacts/artifact_file_cache.py +256 -0
  308. wandb/sdk/artifacts/artifact_instance_cache.py +17 -0
  309. wandb/sdk/artifacts/artifact_manifest.py +76 -0
  310. wandb/sdk/artifacts/artifact_manifest_entry.py +315 -0
  311. wandb/sdk/artifacts/artifact_manifests/__init__.py +0 -0
  312. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +94 -0
  313. wandb/sdk/artifacts/artifact_saver.py +277 -0
  314. wandb/sdk/artifacts/artifact_state.py +13 -0
  315. wandb/sdk/artifacts/artifact_ttl.py +9 -0
  316. wandb/sdk/artifacts/exceptions.py +72 -0
  317. wandb/sdk/artifacts/staging.py +27 -0
  318. wandb/sdk/artifacts/storage_handler.py +62 -0
  319. wandb/sdk/artifacts/storage_handlers/__init__.py +0 -0
  320. wandb/sdk/artifacts/storage_handlers/azure_handler.py +214 -0
  321. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +224 -0
  322. wandb/sdk/artifacts/storage_handlers/http_handler.py +112 -0
  323. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +142 -0
  324. wandb/sdk/artifacts/storage_handlers/multi_handler.py +56 -0
  325. wandb/sdk/artifacts/storage_handlers/s3_handler.py +340 -0
  326. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +68 -0
  327. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +131 -0
  328. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +74 -0
  329. wandb/sdk/artifacts/storage_layout.py +8 -0
  330. wandb/sdk/artifacts/storage_policies/__init__.py +4 -0
  331. wandb/sdk/artifacts/storage_policies/_factories.py +63 -0
  332. wandb/sdk/artifacts/storage_policies/register.py +1 -0
  333. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +525 -0
  334. wandb/sdk/artifacts/storage_policy.py +75 -0
  335. wandb/sdk/backend/__init__.py +0 -0
  336. wandb/sdk/backend/backend.py +57 -0
  337. wandb/sdk/data_types/__init__.py +0 -0
  338. wandb/sdk/data_types/_dtypes.py +914 -0
  339. wandb/sdk/data_types/_private.py +10 -0
  340. wandb/sdk/data_types/audio.py +208 -0
  341. wandb/sdk/data_types/base_types/__init__.py +0 -0
  342. wandb/sdk/data_types/base_types/json_metadata.py +55 -0
  343. wandb/sdk/data_types/base_types/media.py +339 -0
  344. wandb/sdk/data_types/base_types/wb_value.py +295 -0
  345. wandb/sdk/data_types/bokeh.py +91 -0
  346. wandb/sdk/data_types/graph.py +439 -0
  347. wandb/sdk/data_types/helper_types/__init__.py +0 -0
  348. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +327 -0
  349. wandb/sdk/data_types/helper_types/classes.py +159 -0
  350. wandb/sdk/data_types/helper_types/image_mask.py +251 -0
  351. wandb/sdk/data_types/histogram.py +107 -0
  352. wandb/sdk/data_types/html.py +165 -0
  353. wandb/sdk/data_types/image.py +985 -0
  354. wandb/sdk/data_types/molecule.py +250 -0
  355. wandb/sdk/data_types/object_3d.py +495 -0
  356. wandb/sdk/data_types/plotly.py +95 -0
  357. wandb/sdk/data_types/saved_model.py +435 -0
  358. wandb/sdk/data_types/table.py +1468 -0
  359. wandb/sdk/data_types/table_decorators.py +108 -0
  360. wandb/sdk/data_types/trace_tree.py +440 -0
  361. wandb/sdk/data_types/utils.py +260 -0
  362. wandb/sdk/data_types/video.py +303 -0
  363. wandb/sdk/integration_utils/__init__.py +0 -0
  364. wandb/sdk/integration_utils/auto_logging.py +232 -0
  365. wandb/sdk/integration_utils/data_logging.py +475 -0
  366. wandb/sdk/interface/__init__.py +0 -0
  367. wandb/sdk/interface/constants.py +4 -0
  368. wandb/sdk/interface/interface.py +1093 -0
  369. wandb/sdk/interface/interface_queue.py +50 -0
  370. wandb/sdk/interface/interface_shared.py +473 -0
  371. wandb/sdk/interface/interface_sock.py +55 -0
  372. wandb/sdk/interface/summary_record.py +67 -0
  373. wandb/sdk/internal/__init__.py +0 -0
  374. wandb/sdk/internal/_generated/__init__.py +5 -0
  375. wandb/sdk/internal/_generated/enums.py +4 -0
  376. wandb/sdk/internal/_generated/input_types.py +4 -0
  377. wandb/sdk/internal/_generated/operations.py +15 -0
  378. wandb/sdk/internal/_generated/server_features_query.py +27 -0
  379. wandb/sdk/internal/context.py +89 -0
  380. wandb/sdk/internal/datastore.py +293 -0
  381. wandb/sdk/internal/file_pusher.py +177 -0
  382. wandb/sdk/internal/file_stream.py +686 -0
  383. wandb/sdk/internal/handler.py +854 -0
  384. wandb/sdk/internal/incremental_table_util.py +53 -0
  385. wandb/sdk/internal/internal_api.py +4723 -0
  386. wandb/sdk/internal/job_builder.py +639 -0
  387. wandb/sdk/internal/profiler.py +79 -0
  388. wandb/sdk/internal/progress.py +77 -0
  389. wandb/sdk/internal/run.py +27 -0
  390. wandb/sdk/internal/sample.py +70 -0
  391. wandb/sdk/internal/sender.py +1692 -0
  392. wandb/sdk/internal/sender_config.py +203 -0
  393. wandb/sdk/internal/settings_static.py +40 -0
  394. wandb/sdk/internal/tb_watcher.py +519 -0
  395. wandb/sdk/internal/thread_local_settings.py +18 -0
  396. wandb/sdk/launch/__init__.py +15 -0
  397. wandb/sdk/launch/_launch.py +331 -0
  398. wandb/sdk/launch/_launch_add.py +255 -0
  399. wandb/sdk/launch/_project_spec.py +565 -0
  400. wandb/sdk/launch/agent/__init__.py +5 -0
  401. wandb/sdk/launch/agent/agent.py +931 -0
  402. wandb/sdk/launch/agent/config.py +296 -0
  403. wandb/sdk/launch/agent/job_status_tracker.py +55 -0
  404. wandb/sdk/launch/agent/run_queue_item_file_saver.py +39 -0
  405. wandb/sdk/launch/builder/__init__.py +0 -0
  406. wandb/sdk/launch/builder/abstract.py +156 -0
  407. wandb/sdk/launch/builder/build.py +296 -0
  408. wandb/sdk/launch/builder/context_manager.py +235 -0
  409. wandb/sdk/launch/builder/docker_builder.py +177 -0
  410. wandb/sdk/launch/builder/kaniko_builder.py +595 -0
  411. wandb/sdk/launch/builder/noop.py +58 -0
  412. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +188 -0
  413. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  414. wandb/sdk/launch/create_job.py +541 -0
  415. wandb/sdk/launch/environment/abstract.py +29 -0
  416. wandb/sdk/launch/environment/aws_environment.py +322 -0
  417. wandb/sdk/launch/environment/azure_environment.py +105 -0
  418. wandb/sdk/launch/environment/gcp_environment.py +334 -0
  419. wandb/sdk/launch/environment/local_environment.py +65 -0
  420. wandb/sdk/launch/errors.py +13 -0
  421. wandb/sdk/launch/git_reference.py +109 -0
  422. wandb/sdk/launch/inputs/files.py +148 -0
  423. wandb/sdk/launch/inputs/internal.py +315 -0
  424. wandb/sdk/launch/inputs/manage.py +113 -0
  425. wandb/sdk/launch/inputs/schema.py +70 -0
  426. wandb/sdk/launch/loader.py +249 -0
  427. wandb/sdk/launch/registry/abstract.py +48 -0
  428. wandb/sdk/launch/registry/anon.py +29 -0
  429. wandb/sdk/launch/registry/azure_container_registry.py +124 -0
  430. wandb/sdk/launch/registry/elastic_container_registry.py +192 -0
  431. wandb/sdk/launch/registry/google_artifact_registry.py +219 -0
  432. wandb/sdk/launch/registry/local_registry.py +65 -0
  433. wandb/sdk/launch/runner/__init__.py +0 -0
  434. wandb/sdk/launch/runner/abstract.py +185 -0
  435. wandb/sdk/launch/runner/kubernetes_monitor.py +473 -0
  436. wandb/sdk/launch/runner/kubernetes_runner.py +1290 -0
  437. wandb/sdk/launch/runner/local_container.py +301 -0
  438. wandb/sdk/launch/runner/local_process.py +78 -0
  439. wandb/sdk/launch/runner/sagemaker_runner.py +424 -0
  440. wandb/sdk/launch/runner/vertex_runner.py +225 -0
  441. wandb/sdk/launch/sweeps/__init__.py +37 -0
  442. wandb/sdk/launch/sweeps/scheduler.py +739 -0
  443. wandb/sdk/launch/sweeps/scheduler_sweep.py +90 -0
  444. wandb/sdk/launch/sweeps/utils.py +324 -0
  445. wandb/sdk/launch/utils.py +827 -0
  446. wandb/sdk/launch/wandb_reference.py +138 -0
  447. wandb/sdk/lib/__init__.py +5 -0
  448. wandb/sdk/lib/apikey.py +334 -0
  449. wandb/sdk/lib/asyncio_compat.py +278 -0
  450. wandb/sdk/lib/asyncio_manager.py +252 -0
  451. wandb/sdk/lib/capped_dict.py +26 -0
  452. wandb/sdk/lib/config_util.py +101 -0
  453. wandb/sdk/lib/console_capture.py +219 -0
  454. wandb/sdk/lib/credentials.py +141 -0
  455. wandb/sdk/lib/deprecate.py +27 -0
  456. wandb/sdk/lib/disabled.py +30 -0
  457. wandb/sdk/lib/exit_hooks.py +54 -0
  458. wandb/sdk/lib/file_stream_utils.py +118 -0
  459. wandb/sdk/lib/filenames.py +64 -0
  460. wandb/sdk/lib/filesystem.py +372 -0
  461. wandb/sdk/lib/fsm.py +165 -0
  462. wandb/sdk/lib/gitlib.py +240 -0
  463. wandb/sdk/lib/gql_request.py +76 -0
  464. wandb/sdk/lib/handler_util.py +21 -0
  465. wandb/sdk/lib/hashutil.py +106 -0
  466. wandb/sdk/lib/import_hooks.py +275 -0
  467. wandb/sdk/lib/interrupt.py +37 -0
  468. wandb/sdk/lib/ipython.py +126 -0
  469. wandb/sdk/lib/json_util.py +75 -0
  470. wandb/sdk/lib/lazyloader.py +63 -0
  471. wandb/sdk/lib/module.py +72 -0
  472. wandb/sdk/lib/paths.py +108 -0
  473. wandb/sdk/lib/preinit.py +42 -0
  474. wandb/sdk/lib/printer.py +567 -0
  475. wandb/sdk/lib/printer_asyncio.py +48 -0
  476. wandb/sdk/lib/progress.py +325 -0
  477. wandb/sdk/lib/proto_util.py +90 -0
  478. wandb/sdk/lib/redirect.py +876 -0
  479. wandb/sdk/lib/retry.py +395 -0
  480. wandb/sdk/lib/run_moment.py +82 -0
  481. wandb/sdk/lib/runid.py +12 -0
  482. wandb/sdk/lib/server.py +58 -0
  483. wandb/sdk/lib/service/ipc_support.py +13 -0
  484. wandb/sdk/lib/service/service_client.py +102 -0
  485. wandb/sdk/lib/service/service_connection.py +238 -0
  486. wandb/sdk/lib/service/service_port_file.py +105 -0
  487. wandb/sdk/lib/service/service_process.py +111 -0
  488. wandb/sdk/lib/service/service_token.py +181 -0
  489. wandb/sdk/lib/sparkline.py +44 -0
  490. wandb/sdk/lib/telemetry.py +100 -0
  491. wandb/sdk/lib/timed_input.py +133 -0
  492. wandb/sdk/lib/timer.py +19 -0
  493. wandb/sdk/lib/wb_logging.py +161 -0
  494. wandb/sdk/mailbox/__init__.py +23 -0
  495. wandb/sdk/mailbox/mailbox.py +143 -0
  496. wandb/sdk/mailbox/mailbox_handle.py +134 -0
  497. wandb/sdk/mailbox/response_handle.py +99 -0
  498. wandb/sdk/mailbox/wait_with_progress.py +100 -0
  499. wandb/sdk/projects/_generated/__init__.py +26 -0
  500. wandb/sdk/projects/_generated/delete_project.py +22 -0
  501. wandb/sdk/projects/_generated/enums.py +4 -0
  502. wandb/sdk/projects/_generated/fetch_registry.py +22 -0
  503. wandb/sdk/projects/_generated/fragments.py +41 -0
  504. wandb/sdk/projects/_generated/input_types.py +13 -0
  505. wandb/sdk/projects/_generated/operations.py +88 -0
  506. wandb/sdk/projects/_generated/rename_project.py +27 -0
  507. wandb/sdk/projects/_generated/upsert_registry_project.py +27 -0
  508. wandb/sdk/verify/__init__.py +0 -0
  509. wandb/sdk/verify/verify.py +555 -0
  510. wandb/sdk/wandb_alerts.py +12 -0
  511. wandb/sdk/wandb_config.py +323 -0
  512. wandb/sdk/wandb_helper.py +54 -0
  513. wandb/sdk/wandb_init.py +1601 -0
  514. wandb/sdk/wandb_login.py +358 -0
  515. wandb/sdk/wandb_metric.py +112 -0
  516. wandb/sdk/wandb_require.py +88 -0
  517. wandb/sdk/wandb_require_helpers.py +44 -0
  518. wandb/sdk/wandb_run.py +4102 -0
  519. wandb/sdk/wandb_settings.py +2197 -0
  520. wandb/sdk/wandb_setup.py +560 -0
  521. wandb/sdk/wandb_summary.py +150 -0
  522. wandb/sdk/wandb_sweep.py +120 -0
  523. wandb/sdk/wandb_sync.py +71 -0
  524. wandb/sdk/wandb_watch.py +146 -0
  525. wandb/sklearn.py +35 -0
  526. wandb/sync/__init__.py +3 -0
  527. wandb/sync/sync.py +457 -0
  528. wandb/trigger.py +29 -0
  529. wandb/util.py +2040 -0
  530. wandb/vendor/__init__.py +0 -0
  531. wandb/vendor/gql-0.2.0/setup.py +40 -0
  532. wandb/vendor/gql-0.2.0/tests/__init__.py +0 -0
  533. wandb/vendor/gql-0.2.0/tests/starwars/__init__.py +0 -0
  534. wandb/vendor/gql-0.2.0/tests/starwars/fixtures.py +96 -0
  535. wandb/vendor/gql-0.2.0/tests/starwars/schema.py +146 -0
  536. wandb/vendor/gql-0.2.0/tests/starwars/test_dsl.py +293 -0
  537. wandb/vendor/gql-0.2.0/tests/starwars/test_query.py +355 -0
  538. wandb/vendor/gql-0.2.0/tests/starwars/test_validation.py +171 -0
  539. wandb/vendor/gql-0.2.0/tests/test_client.py +31 -0
  540. wandb/vendor/gql-0.2.0/tests/test_transport.py +89 -0
  541. wandb/vendor/gql-0.2.0/wandb_gql/__init__.py +4 -0
  542. wandb/vendor/gql-0.2.0/wandb_gql/client.py +75 -0
  543. wandb/vendor/gql-0.2.0/wandb_gql/dsl.py +152 -0
  544. wandb/vendor/gql-0.2.0/wandb_gql/gql.py +10 -0
  545. wandb/vendor/gql-0.2.0/wandb_gql/transport/__init__.py +0 -0
  546. wandb/vendor/gql-0.2.0/wandb_gql/transport/http.py +6 -0
  547. wandb/vendor/gql-0.2.0/wandb_gql/transport/local_schema.py +15 -0
  548. wandb/vendor/gql-0.2.0/wandb_gql/transport/requests.py +46 -0
  549. wandb/vendor/gql-0.2.0/wandb_gql/utils.py +21 -0
  550. wandb/vendor/graphql-core-1.1/setup.py +86 -0
  551. wandb/vendor/graphql-core-1.1/wandb_graphql/__init__.py +287 -0
  552. wandb/vendor/graphql-core-1.1/wandb_graphql/error/__init__.py +6 -0
  553. wandb/vendor/graphql-core-1.1/wandb_graphql/error/base.py +42 -0
  554. wandb/vendor/graphql-core-1.1/wandb_graphql/error/format_error.py +11 -0
  555. wandb/vendor/graphql-core-1.1/wandb_graphql/error/located_error.py +29 -0
  556. wandb/vendor/graphql-core-1.1/wandb_graphql/error/syntax_error.py +36 -0
  557. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/__init__.py +26 -0
  558. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/base.py +311 -0
  559. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executor.py +398 -0
  560. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/__init__.py +0 -0
  561. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/asyncio.py +53 -0
  562. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/gevent.py +22 -0
  563. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/process.py +32 -0
  564. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/sync.py +7 -0
  565. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/thread.py +35 -0
  566. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/executors/utils.py +6 -0
  567. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/__init__.py +0 -0
  568. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/executor.py +66 -0
  569. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/fragment.py +252 -0
  570. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/resolver.py +151 -0
  571. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/experimental/utils.py +7 -0
  572. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/middleware.py +57 -0
  573. wandb/vendor/graphql-core-1.1/wandb_graphql/execution/values.py +145 -0
  574. wandb/vendor/graphql-core-1.1/wandb_graphql/graphql.py +60 -0
  575. wandb/vendor/graphql-core-1.1/wandb_graphql/language/__init__.py +0 -0
  576. wandb/vendor/graphql-core-1.1/wandb_graphql/language/ast.py +1349 -0
  577. wandb/vendor/graphql-core-1.1/wandb_graphql/language/base.py +19 -0
  578. wandb/vendor/graphql-core-1.1/wandb_graphql/language/lexer.py +435 -0
  579. wandb/vendor/graphql-core-1.1/wandb_graphql/language/location.py +30 -0
  580. wandb/vendor/graphql-core-1.1/wandb_graphql/language/parser.py +779 -0
  581. wandb/vendor/graphql-core-1.1/wandb_graphql/language/printer.py +193 -0
  582. wandb/vendor/graphql-core-1.1/wandb_graphql/language/source.py +18 -0
  583. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor.py +222 -0
  584. wandb/vendor/graphql-core-1.1/wandb_graphql/language/visitor_meta.py +82 -0
  585. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/__init__.py +0 -0
  586. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/cached_property.py +17 -0
  587. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/contain_subset.py +28 -0
  588. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/default_ordered_dict.py +40 -0
  589. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/ordereddict.py +8 -0
  590. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/pair_set.py +43 -0
  591. wandb/vendor/graphql-core-1.1/wandb_graphql/pyutils/version.py +78 -0
  592. wandb/vendor/graphql-core-1.1/wandb_graphql/type/__init__.py +67 -0
  593. wandb/vendor/graphql-core-1.1/wandb_graphql/type/definition.py +619 -0
  594. wandb/vendor/graphql-core-1.1/wandb_graphql/type/directives.py +132 -0
  595. wandb/vendor/graphql-core-1.1/wandb_graphql/type/introspection.py +440 -0
  596. wandb/vendor/graphql-core-1.1/wandb_graphql/type/scalars.py +131 -0
  597. wandb/vendor/graphql-core-1.1/wandb_graphql/type/schema.py +100 -0
  598. wandb/vendor/graphql-core-1.1/wandb_graphql/type/typemap.py +145 -0
  599. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/__init__.py +0 -0
  600. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/assert_valid_name.py +9 -0
  601. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_from_value.py +65 -0
  602. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_code.py +49 -0
  603. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/ast_to_dict.py +24 -0
  604. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/base.py +75 -0
  605. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_ast_schema.py +291 -0
  606. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/build_client_schema.py +250 -0
  607. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/concat_ast.py +9 -0
  608. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/extend_schema.py +357 -0
  609. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_field_def.py +27 -0
  610. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/get_operation_ast.py +21 -0
  611. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/introspection_query.py +90 -0
  612. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_literal_value.py +67 -0
  613. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/is_valid_value.py +66 -0
  614. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/quoted_or_list.py +21 -0
  615. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/schema_printer.py +168 -0
  616. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/suggestion_list.py +56 -0
  617. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_comparators.py +69 -0
  618. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_from_ast.py +21 -0
  619. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/type_info.py +149 -0
  620. wandb/vendor/graphql-core-1.1/wandb_graphql/utils/value_from_ast.py +69 -0
  621. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/__init__.py +4 -0
  622. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/__init__.py +79 -0
  623. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/arguments_of_correct_type.py +24 -0
  624. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/base.py +8 -0
  625. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/default_values_of_correct_type.py +44 -0
  626. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fields_on_correct_type.py +113 -0
  627. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/fragments_on_composite_types.py +33 -0
  628. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_argument_names.py +70 -0
  629. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_directives.py +97 -0
  630. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_fragment_names.py +19 -0
  631. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/known_type_names.py +43 -0
  632. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/lone_anonymous_operation.py +23 -0
  633. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_fragment_cycles.py +59 -0
  634. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_undefined_variables.py +36 -0
  635. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_fragments.py +38 -0
  636. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/no_unused_variables.py +37 -0
  637. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/overlapping_fields_can_be_merged.py +529 -0
  638. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/possible_fragment_spreads.py +44 -0
  639. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/provided_non_null_arguments.py +46 -0
  640. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/scalar_leafs.py +33 -0
  641. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_argument_names.py +32 -0
  642. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_fragment_names.py +28 -0
  643. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_input_field_names.py +33 -0
  644. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_operation_names.py +31 -0
  645. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/unique_variable_names.py +27 -0
  646. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_are_input_types.py +21 -0
  647. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/rules/variables_in_allowed_position.py +53 -0
  648. wandb/vendor/graphql-core-1.1/wandb_graphql/validation/validation.py +158 -0
  649. wandb/vendor/promise-2.3.0/conftest.py +30 -0
  650. wandb/vendor/promise-2.3.0/setup.py +64 -0
  651. wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
  652. wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
  653. wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
  654. wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
  655. wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
  656. wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
  657. wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
  658. wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
  659. wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
  660. wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
  661. wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
  662. wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
  663. wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
  664. wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
  665. wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
  666. wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
  667. wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
  668. wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
  669. wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
  670. wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
  671. wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
  672. wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
  673. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
  674. wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
  675. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
  676. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/asyncio.py +22 -0
  677. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/gevent.py +21 -0
  678. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/immediate.py +27 -0
  679. wandb/vendor/promise-2.3.0/wandb_promise/schedulers/thread.py +18 -0
  680. wandb/vendor/promise-2.3.0/wandb_promise/utils.py +56 -0
  681. wandb/vendor/pygments/__init__.py +90 -0
  682. wandb/vendor/pygments/cmdline.py +568 -0
  683. wandb/vendor/pygments/console.py +74 -0
  684. wandb/vendor/pygments/filter.py +74 -0
  685. wandb/vendor/pygments/filters/__init__.py +350 -0
  686. wandb/vendor/pygments/formatter.py +95 -0
  687. wandb/vendor/pygments/formatters/__init__.py +153 -0
  688. wandb/vendor/pygments/formatters/_mapping.py +85 -0
  689. wandb/vendor/pygments/formatters/bbcode.py +109 -0
  690. wandb/vendor/pygments/formatters/html.py +851 -0
  691. wandb/vendor/pygments/formatters/img.py +600 -0
  692. wandb/vendor/pygments/formatters/irc.py +182 -0
  693. wandb/vendor/pygments/formatters/latex.py +482 -0
  694. wandb/vendor/pygments/formatters/other.py +160 -0
  695. wandb/vendor/pygments/formatters/rtf.py +147 -0
  696. wandb/vendor/pygments/formatters/svg.py +153 -0
  697. wandb/vendor/pygments/formatters/terminal.py +136 -0
  698. wandb/vendor/pygments/formatters/terminal256.py +309 -0
  699. wandb/vendor/pygments/lexer.py +871 -0
  700. wandb/vendor/pygments/lexers/__init__.py +329 -0
  701. wandb/vendor/pygments/lexers/_asy_builtins.py +1645 -0
  702. wandb/vendor/pygments/lexers/_cl_builtins.py +232 -0
  703. wandb/vendor/pygments/lexers/_cocoa_builtins.py +72 -0
  704. wandb/vendor/pygments/lexers/_csound_builtins.py +1346 -0
  705. wandb/vendor/pygments/lexers/_lasso_builtins.py +5327 -0
  706. wandb/vendor/pygments/lexers/_lua_builtins.py +295 -0
  707. wandb/vendor/pygments/lexers/_mapping.py +500 -0
  708. wandb/vendor/pygments/lexers/_mql_builtins.py +1172 -0
  709. wandb/vendor/pygments/lexers/_openedge_builtins.py +2547 -0
  710. wandb/vendor/pygments/lexers/_php_builtins.py +4756 -0
  711. wandb/vendor/pygments/lexers/_postgres_builtins.py +621 -0
  712. wandb/vendor/pygments/lexers/_scilab_builtins.py +3094 -0
  713. wandb/vendor/pygments/lexers/_sourcemod_builtins.py +1163 -0
  714. wandb/vendor/pygments/lexers/_stan_builtins.py +532 -0
  715. wandb/vendor/pygments/lexers/_stata_builtins.py +419 -0
  716. wandb/vendor/pygments/lexers/_tsql_builtins.py +1004 -0
  717. wandb/vendor/pygments/lexers/_vim_builtins.py +1939 -0
  718. wandb/vendor/pygments/lexers/actionscript.py +240 -0
  719. wandb/vendor/pygments/lexers/agile.py +24 -0
  720. wandb/vendor/pygments/lexers/algebra.py +221 -0
  721. wandb/vendor/pygments/lexers/ambient.py +76 -0
  722. wandb/vendor/pygments/lexers/ampl.py +87 -0
  723. wandb/vendor/pygments/lexers/apl.py +101 -0
  724. wandb/vendor/pygments/lexers/archetype.py +318 -0
  725. wandb/vendor/pygments/lexers/asm.py +641 -0
  726. wandb/vendor/pygments/lexers/automation.py +374 -0
  727. wandb/vendor/pygments/lexers/basic.py +500 -0
  728. wandb/vendor/pygments/lexers/bibtex.py +160 -0
  729. wandb/vendor/pygments/lexers/business.py +612 -0
  730. wandb/vendor/pygments/lexers/c_cpp.py +252 -0
  731. wandb/vendor/pygments/lexers/c_like.py +541 -0
  732. wandb/vendor/pygments/lexers/capnproto.py +78 -0
  733. wandb/vendor/pygments/lexers/chapel.py +102 -0
  734. wandb/vendor/pygments/lexers/clean.py +288 -0
  735. wandb/vendor/pygments/lexers/compiled.py +34 -0
  736. wandb/vendor/pygments/lexers/configs.py +833 -0
  737. wandb/vendor/pygments/lexers/console.py +114 -0
  738. wandb/vendor/pygments/lexers/crystal.py +393 -0
  739. wandb/vendor/pygments/lexers/csound.py +366 -0
  740. wandb/vendor/pygments/lexers/css.py +689 -0
  741. wandb/vendor/pygments/lexers/d.py +251 -0
  742. wandb/vendor/pygments/lexers/dalvik.py +125 -0
  743. wandb/vendor/pygments/lexers/data.py +555 -0
  744. wandb/vendor/pygments/lexers/diff.py +165 -0
  745. wandb/vendor/pygments/lexers/dotnet.py +691 -0
  746. wandb/vendor/pygments/lexers/dsls.py +878 -0
  747. wandb/vendor/pygments/lexers/dylan.py +289 -0
  748. wandb/vendor/pygments/lexers/ecl.py +125 -0
  749. wandb/vendor/pygments/lexers/eiffel.py +65 -0
  750. wandb/vendor/pygments/lexers/elm.py +121 -0
  751. wandb/vendor/pygments/lexers/erlang.py +533 -0
  752. wandb/vendor/pygments/lexers/esoteric.py +277 -0
  753. wandb/vendor/pygments/lexers/ezhil.py +69 -0
  754. wandb/vendor/pygments/lexers/factor.py +344 -0
  755. wandb/vendor/pygments/lexers/fantom.py +250 -0
  756. wandb/vendor/pygments/lexers/felix.py +273 -0
  757. wandb/vendor/pygments/lexers/forth.py +177 -0
  758. wandb/vendor/pygments/lexers/fortran.py +205 -0
  759. wandb/vendor/pygments/lexers/foxpro.py +428 -0
  760. wandb/vendor/pygments/lexers/functional.py +21 -0
  761. wandb/vendor/pygments/lexers/go.py +101 -0
  762. wandb/vendor/pygments/lexers/grammar_notation.py +213 -0
  763. wandb/vendor/pygments/lexers/graph.py +80 -0
  764. wandb/vendor/pygments/lexers/graphics.py +553 -0
  765. wandb/vendor/pygments/lexers/haskell.py +843 -0
  766. wandb/vendor/pygments/lexers/haxe.py +936 -0
  767. wandb/vendor/pygments/lexers/hdl.py +382 -0
  768. wandb/vendor/pygments/lexers/hexdump.py +103 -0
  769. wandb/vendor/pygments/lexers/html.py +602 -0
  770. wandb/vendor/pygments/lexers/idl.py +270 -0
  771. wandb/vendor/pygments/lexers/igor.py +288 -0
  772. wandb/vendor/pygments/lexers/inferno.py +96 -0
  773. wandb/vendor/pygments/lexers/installers.py +322 -0
  774. wandb/vendor/pygments/lexers/int_fiction.py +1343 -0
  775. wandb/vendor/pygments/lexers/iolang.py +63 -0
  776. wandb/vendor/pygments/lexers/j.py +146 -0
  777. wandb/vendor/pygments/lexers/javascript.py +1525 -0
  778. wandb/vendor/pygments/lexers/julia.py +333 -0
  779. wandb/vendor/pygments/lexers/jvm.py +1573 -0
  780. wandb/vendor/pygments/lexers/lisp.py +2621 -0
  781. wandb/vendor/pygments/lexers/make.py +202 -0
  782. wandb/vendor/pygments/lexers/markup.py +595 -0
  783. wandb/vendor/pygments/lexers/math.py +21 -0
  784. wandb/vendor/pygments/lexers/matlab.py +663 -0
  785. wandb/vendor/pygments/lexers/ml.py +769 -0
  786. wandb/vendor/pygments/lexers/modeling.py +358 -0
  787. wandb/vendor/pygments/lexers/modula2.py +1561 -0
  788. wandb/vendor/pygments/lexers/monte.py +204 -0
  789. wandb/vendor/pygments/lexers/ncl.py +894 -0
  790. wandb/vendor/pygments/lexers/nimrod.py +159 -0
  791. wandb/vendor/pygments/lexers/nit.py +64 -0
  792. wandb/vendor/pygments/lexers/nix.py +136 -0
  793. wandb/vendor/pygments/lexers/oberon.py +105 -0
  794. wandb/vendor/pygments/lexers/objective.py +504 -0
  795. wandb/vendor/pygments/lexers/ooc.py +85 -0
  796. wandb/vendor/pygments/lexers/other.py +41 -0
  797. wandb/vendor/pygments/lexers/parasail.py +79 -0
  798. wandb/vendor/pygments/lexers/parsers.py +835 -0
  799. wandb/vendor/pygments/lexers/pascal.py +644 -0
  800. wandb/vendor/pygments/lexers/pawn.py +199 -0
  801. wandb/vendor/pygments/lexers/perl.py +620 -0
  802. wandb/vendor/pygments/lexers/php.py +267 -0
  803. wandb/vendor/pygments/lexers/praat.py +294 -0
  804. wandb/vendor/pygments/lexers/prolog.py +306 -0
  805. wandb/vendor/pygments/lexers/python.py +939 -0
  806. wandb/vendor/pygments/lexers/qvt.py +152 -0
  807. wandb/vendor/pygments/lexers/r.py +453 -0
  808. wandb/vendor/pygments/lexers/rdf.py +270 -0
  809. wandb/vendor/pygments/lexers/rebol.py +431 -0
  810. wandb/vendor/pygments/lexers/resource.py +85 -0
  811. wandb/vendor/pygments/lexers/rnc.py +67 -0
  812. wandb/vendor/pygments/lexers/roboconf.py +82 -0
  813. wandb/vendor/pygments/lexers/robotframework.py +560 -0
  814. wandb/vendor/pygments/lexers/ruby.py +519 -0
  815. wandb/vendor/pygments/lexers/rust.py +220 -0
  816. wandb/vendor/pygments/lexers/sas.py +228 -0
  817. wandb/vendor/pygments/lexers/scripting.py +1222 -0
  818. wandb/vendor/pygments/lexers/shell.py +794 -0
  819. wandb/vendor/pygments/lexers/smalltalk.py +195 -0
  820. wandb/vendor/pygments/lexers/smv.py +79 -0
  821. wandb/vendor/pygments/lexers/snobol.py +83 -0
  822. wandb/vendor/pygments/lexers/special.py +103 -0
  823. wandb/vendor/pygments/lexers/sql.py +681 -0
  824. wandb/vendor/pygments/lexers/stata.py +108 -0
  825. wandb/vendor/pygments/lexers/supercollider.py +90 -0
  826. wandb/vendor/pygments/lexers/tcl.py +145 -0
  827. wandb/vendor/pygments/lexers/templates.py +2283 -0
  828. wandb/vendor/pygments/lexers/testing.py +207 -0
  829. wandb/vendor/pygments/lexers/text.py +25 -0
  830. wandb/vendor/pygments/lexers/textedit.py +169 -0
  831. wandb/vendor/pygments/lexers/textfmts.py +297 -0
  832. wandb/vendor/pygments/lexers/theorem.py +458 -0
  833. wandb/vendor/pygments/lexers/trafficscript.py +54 -0
  834. wandb/vendor/pygments/lexers/typoscript.py +226 -0
  835. wandb/vendor/pygments/lexers/urbi.py +133 -0
  836. wandb/vendor/pygments/lexers/varnish.py +190 -0
  837. wandb/vendor/pygments/lexers/verification.py +111 -0
  838. wandb/vendor/pygments/lexers/web.py +24 -0
  839. wandb/vendor/pygments/lexers/webmisc.py +988 -0
  840. wandb/vendor/pygments/lexers/whiley.py +116 -0
  841. wandb/vendor/pygments/lexers/x10.py +69 -0
  842. wandb/vendor/pygments/modeline.py +44 -0
  843. wandb/vendor/pygments/plugin.py +68 -0
  844. wandb/vendor/pygments/regexopt.py +92 -0
  845. wandb/vendor/pygments/scanner.py +105 -0
  846. wandb/vendor/pygments/sphinxext.py +158 -0
  847. wandb/vendor/pygments/style.py +155 -0
  848. wandb/vendor/pygments/styles/__init__.py +80 -0
  849. wandb/vendor/pygments/styles/abap.py +29 -0
  850. wandb/vendor/pygments/styles/algol.py +63 -0
  851. wandb/vendor/pygments/styles/algol_nu.py +63 -0
  852. wandb/vendor/pygments/styles/arduino.py +98 -0
  853. wandb/vendor/pygments/styles/autumn.py +65 -0
  854. wandb/vendor/pygments/styles/borland.py +51 -0
  855. wandb/vendor/pygments/styles/bw.py +49 -0
  856. wandb/vendor/pygments/styles/colorful.py +81 -0
  857. wandb/vendor/pygments/styles/default.py +73 -0
  858. wandb/vendor/pygments/styles/emacs.py +72 -0
  859. wandb/vendor/pygments/styles/friendly.py +72 -0
  860. wandb/vendor/pygments/styles/fruity.py +42 -0
  861. wandb/vendor/pygments/styles/igor.py +29 -0
  862. wandb/vendor/pygments/styles/lovelace.py +97 -0
  863. wandb/vendor/pygments/styles/manni.py +75 -0
  864. wandb/vendor/pygments/styles/monokai.py +106 -0
  865. wandb/vendor/pygments/styles/murphy.py +80 -0
  866. wandb/vendor/pygments/styles/native.py +65 -0
  867. wandb/vendor/pygments/styles/paraiso_dark.py +125 -0
  868. wandb/vendor/pygments/styles/paraiso_light.py +125 -0
  869. wandb/vendor/pygments/styles/pastie.py +75 -0
  870. wandb/vendor/pygments/styles/perldoc.py +69 -0
  871. wandb/vendor/pygments/styles/rainbow_dash.py +89 -0
  872. wandb/vendor/pygments/styles/rrt.py +33 -0
  873. wandb/vendor/pygments/styles/sas.py +44 -0
  874. wandb/vendor/pygments/styles/stata.py +40 -0
  875. wandb/vendor/pygments/styles/tango.py +141 -0
  876. wandb/vendor/pygments/styles/trac.py +63 -0
  877. wandb/vendor/pygments/styles/vim.py +63 -0
  878. wandb/vendor/pygments/styles/vs.py +38 -0
  879. wandb/vendor/pygments/styles/xcode.py +51 -0
  880. wandb/vendor/pygments/token.py +213 -0
  881. wandb/vendor/pygments/unistring.py +217 -0
  882. wandb/vendor/pygments/util.py +388 -0
  883. wandb/vendor/watchdog_0_9_0/wandb_watchdog/__init__.py +17 -0
  884. wandb/vendor/watchdog_0_9_0/wandb_watchdog/events.py +615 -0
  885. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/__init__.py +98 -0
  886. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/api.py +369 -0
  887. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents.py +172 -0
  888. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/fsevents2.py +239 -0
  889. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify.py +218 -0
  890. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_buffer.py +81 -0
  891. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/inotify_c.py +575 -0
  892. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/kqueue.py +730 -0
  893. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/polling.py +145 -0
  894. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/read_directory_changes.py +133 -0
  895. wandb/vendor/watchdog_0_9_0/wandb_watchdog/observers/winapi.py +348 -0
  896. wandb/vendor/watchdog_0_9_0/wandb_watchdog/patterns.py +265 -0
  897. wandb/vendor/watchdog_0_9_0/wandb_watchdog/tricks/__init__.py +174 -0
  898. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/__init__.py +151 -0
  899. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/bricks.py +249 -0
  900. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/compat.py +29 -0
  901. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/decorators.py +198 -0
  902. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/delayed_queue.py +88 -0
  903. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/dirsnapshot.py +293 -0
  904. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/echo.py +157 -0
  905. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/event_backport.py +41 -0
  906. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/importlib2.py +40 -0
  907. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/platform.py +57 -0
  908. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/unicode_paths.py +64 -0
  909. wandb/vendor/watchdog_0_9_0/wandb_watchdog/utils/win32stat.py +123 -0
  910. wandb/vendor/watchdog_0_9_0/wandb_watchdog/version.py +28 -0
  911. wandb/vendor/watchdog_0_9_0/wandb_watchdog/watchmedo.py +577 -0
  912. wandb/wandb_agent.py +611 -0
  913. wandb/wandb_controller.py +719 -0
  914. wandb/wandb_run.py +8 -0
  915. wandb-0.22.1.dist-info/METADATA +223 -0
  916. wandb-0.22.1.dist-info/RECORD +919 -0
  917. wandb-0.22.1.dist-info/WHEEL +4 -0
  918. wandb-0.22.1.dist-info/entry_points.txt +3 -0
  919. wandb-0.22.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,2513 @@
1
+ """Use the Public API to export or update data that you have saved to W&B.
2
+
3
+ Before using this API, you'll want to log data from your script — check the
4
+ [Quickstart](https://docs.wandb.ai/quickstart) for more details.
5
+
6
+ You might use the Public API to
7
+ - update metadata or metrics for an experiment after it has been completed,
8
+ - pull down your results as a dataframe for post-hoc analysis in a Jupyter notebook, or
9
+ - check your saved model artifacts for those tagged as `ready-to-deploy`.
10
+
11
+ For more on using the Public API, check out [our guide](https://docs.wandb.com/guides/track/public-api-guide).
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import logging
18
+ import os
19
+ import urllib
20
+ from http import HTTPStatus
21
+ from typing import TYPE_CHECKING, Any, Iterator, Literal
22
+
23
+ import requests
24
+ from pydantic import ValidationError
25
+ from typing_extensions import Unpack
26
+ from wandb_gql import Client, gql
27
+ from wandb_gql.client import RetryError
28
+
29
+ import wandb
30
+ from wandb import env, util
31
+ from wandb._analytics import tracked
32
+ from wandb._iterutils import one
33
+ from wandb._strutils import nameof
34
+ from wandb.apis import public
35
+ from wandb.apis.normalize import normalize_exceptions
36
+ from wandb.apis.public.const import RETRY_TIMEDELTA
37
+ from wandb.apis.public.registries import Registries, Registry
38
+ from wandb.apis.public.registries._utils import fetch_org_entity_from_organization
39
+ from wandb.apis.public.utils import (
40
+ PathType,
41
+ fetch_org_from_settings_or_entity,
42
+ gql_compat,
43
+ parse_org_from_registry_path,
44
+ )
45
+ from wandb.proto.wandb_deprecated import Deprecated
46
+ from wandb.proto.wandb_internal_pb2 import ServerFeature
47
+ from wandb.sdk import wandb_login
48
+ from wandb.sdk.artifacts._validators import (
49
+ ArtifactPath,
50
+ FullArtifactPath,
51
+ is_artifact_registry_project,
52
+ )
53
+ from wandb.sdk.internal.internal_api import Api as InternalApi
54
+ from wandb.sdk.internal.thread_local_settings import _thread_local_api_settings
55
+ from wandb.sdk.launch.utils import LAUNCH_DEFAULT_PROJECT
56
+ from wandb.sdk.lib import retry, runid
57
+ from wandb.sdk.lib.deprecate import deprecate
58
+ from wandb.sdk.lib.gql_request import GraphQLSession
59
+
60
+ if TYPE_CHECKING:
61
+ from wandb.automations import (
62
+ ActionType,
63
+ Automation,
64
+ EventType,
65
+ Integration,
66
+ NewAutomation,
67
+ SlackIntegration,
68
+ WebhookIntegration,
69
+ )
70
+ from wandb.automations._utils import WriteAutomationsKwargs
71
+ from wandb.sdk.artifacts.artifact import Artifact
72
+
73
+ from .artifacts import (
74
+ ArtifactCollection,
75
+ ArtifactCollections,
76
+ Artifacts,
77
+ ArtifactType,
78
+ ArtifactTypes,
79
+ )
80
+ from .teams import Team
81
+ from .users import User
82
+
83
+ logger = logging.getLogger(__name__)
84
+
85
+
86
+ class RetryingClient:
87
+ """A GraphQL client that retries requests on failure.
88
+
89
+ <!-- lazydoc-ignore-class: internal -->
90
+ """
91
+
92
+ INFO_QUERY = gql(
93
+ """
94
+ query ServerInfo{
95
+ serverInfo {
96
+ cliVersionInfo
97
+ latestLocalVersionInfo {
98
+ outOfDate
99
+ latestVersionString
100
+ versionOnThisInstanceString
101
+ }
102
+ }
103
+ }
104
+ """
105
+ )
106
+
107
+ def __init__(self, client: Client):
108
+ self._server_info = None
109
+ self._client = client
110
+
111
+ @property
112
+ def app_url(self):
113
+ return util.app_url(self._client.transport.url.replace("/graphql", "")) + "/"
114
+
115
+ @retry.retriable(
116
+ retry_timedelta=RETRY_TIMEDELTA,
117
+ check_retry_fn=util.no_retry_auth,
118
+ retryable_exceptions=(RetryError, requests.RequestException),
119
+ )
120
+ def execute(
121
+ self, *args, **kwargs
122
+ ): # User not encouraged to use this class directly
123
+ try:
124
+ return self._client.execute(*args, **kwargs)
125
+ except requests.exceptions.ReadTimeout:
126
+ if "timeout" not in kwargs:
127
+ timeout = self._client.transport.default_timeout
128
+ wandb.termwarn(
129
+ f"A graphql request initiated by the public wandb API timed out (timeout={timeout} sec). "
130
+ f"Create a new API with an integer timeout larger than {timeout}, e.g., `api = wandb.Api(timeout={timeout + 10})` "
131
+ f"to increase the graphql timeout."
132
+ )
133
+ raise
134
+
135
+ @property
136
+ def server_info(self):
137
+ if self._server_info is None:
138
+ self._server_info = self.execute(self.INFO_QUERY).get("serverInfo")
139
+ return self._server_info
140
+
141
+ def version_supported(
142
+ self, min_version: str
143
+ ) -> bool: # User not encouraged to use this class directly
144
+ from packaging.version import parse
145
+
146
+ return parse(min_version) <= parse(
147
+ self.server_info["cliVersionInfo"]["max_cli_version"]
148
+ )
149
+
150
+
151
+ class Api:
152
+ """Used for querying the W&B server.
153
+
154
+ Examples:
155
+ ```python
156
+ import wandb
157
+
158
+ wandb.Api()
159
+ ```
160
+ """
161
+
162
+ _HTTP_TIMEOUT = env.get_http_timeout(19)
163
+ DEFAULT_ENTITY_QUERY = gql(
164
+ """
165
+ query Viewer{
166
+ viewer {
167
+ id
168
+ entity
169
+ }
170
+ }
171
+ """
172
+ )
173
+
174
+ VIEWER_QUERY = gql(
175
+ """
176
+ query Viewer{
177
+ viewer {
178
+ id
179
+ flags
180
+ entity
181
+ username
182
+ email
183
+ admin
184
+ apiKeys {
185
+ edges {
186
+ node {
187
+ id
188
+ name
189
+ description
190
+ }
191
+ }
192
+ }
193
+ teams {
194
+ edges {
195
+ node {
196
+ name
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ """
203
+ )
204
+ USERS_QUERY = gql(
205
+ """
206
+ query SearchUsers($query: String) {
207
+ users(query: $query) {
208
+ edges {
209
+ node {
210
+ id
211
+ flags
212
+ entity
213
+ admin
214
+ email
215
+ deletedAt
216
+ username
217
+ apiKeys {
218
+ edges {
219
+ node {
220
+ id
221
+ name
222
+ description
223
+ }
224
+ }
225
+ }
226
+ teams {
227
+ edges {
228
+ node {
229
+ name
230
+ }
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
236
+ }
237
+ """
238
+ )
239
+
240
+ CREATE_PROJECT = gql(
241
+ """
242
+ mutation upsertModel(
243
+ $description: String
244
+ $entityName: String
245
+ $id: String
246
+ $name: String
247
+ $framework: String
248
+ $access: String
249
+ $views: JSONString
250
+ ) {
251
+ upsertModel(
252
+ input: {
253
+ description: $description
254
+ entityName: $entityName
255
+ id: $id
256
+ name: $name
257
+ framework: $framework
258
+ access: $access
259
+ views: $views
260
+ }
261
+ ) {
262
+ project {
263
+ id
264
+ name
265
+ entityName
266
+ description
267
+ access
268
+ views
269
+ }
270
+ model {
271
+ id
272
+ name
273
+ entityName
274
+ description
275
+ access
276
+ views
277
+ }
278
+ inserted
279
+ }
280
+ }
281
+ """
282
+ )
283
+
284
+ def __init__(
285
+ self,
286
+ overrides: dict[str, Any] | None = None,
287
+ timeout: int | None = None,
288
+ api_key: str | None = None,
289
+ ) -> None:
290
+ """Initialize the API.
291
+
292
+ Args:
293
+ overrides: You can set `base_url` if you are
294
+ using a W&B server other than `https://api.wandb.ai`. You can also
295
+ set defaults for `entity`, `project`, and `run`.
296
+ timeout: HTTP timeout in seconds for API requests. If not
297
+ specified, the default timeout will be used.
298
+ api_key: API key to use for authentication. If not provided,
299
+ the API key from the current environment or configuration will be used.
300
+ Prompts for an API key if none is provided
301
+ or configured in the environment.
302
+ """
303
+ self.settings = InternalApi().settings()
304
+
305
+ _overrides = overrides or {}
306
+ self.settings.update(_overrides)
307
+ self.settings["base_url"] = self.settings["base_url"].rstrip("/")
308
+ if "organization" in _overrides:
309
+ self.settings["organization"] = _overrides["organization"]
310
+ if "username" in _overrides and "entity" not in _overrides:
311
+ wandb.termwarn(
312
+ 'Passing "username" to Api is deprecated. please use "entity" instead.'
313
+ )
314
+ self.settings["entity"] = _overrides["username"]
315
+
316
+ if _thread_local_api_settings.cookies is None:
317
+ self.api_key = self._load_api_key(
318
+ base_url=self.settings["base_url"],
319
+ init_api_key=api_key,
320
+ )
321
+ wandb_login._verify_login(
322
+ key=self.api_key,
323
+ base_url=self.settings["base_url"],
324
+ )
325
+
326
+ self._viewer = None
327
+ self._projects = {}
328
+ self._runs = {}
329
+ self._sweeps = {}
330
+ self._reports = {}
331
+ self._default_entity = None
332
+ self._timeout = timeout if timeout is not None else self._HTTP_TIMEOUT
333
+ auth = None
334
+ if not _thread_local_api_settings.cookies:
335
+ auth = ("api", self.api_key)
336
+ proxies = self.settings.get("_proxies") or json.loads(
337
+ os.environ.get("WANDB__PROXIES", "{}")
338
+ )
339
+ self._base_client = Client(
340
+ transport=GraphQLSession(
341
+ headers={
342
+ "User-Agent": self.user_agent,
343
+ "Use-Admin-Privileges": "true",
344
+ **(_thread_local_api_settings.headers or {}),
345
+ },
346
+ use_json=True,
347
+ # this timeout won't apply when the DNS lookup fails. in that case, it will be 60s
348
+ # https://bugs.python.org/issue22889
349
+ timeout=self._timeout,
350
+ auth=auth,
351
+ url="{}/graphql".format(self.settings["base_url"]),
352
+ cookies=_thread_local_api_settings.cookies,
353
+ proxies=proxies,
354
+ )
355
+ )
356
+ self._client = RetryingClient(self._base_client)
357
+ self._sentry = wandb.analytics.sentry.Sentry()
358
+ self._configure_sentry()
359
+
360
+ def _load_api_key(
361
+ self,
362
+ base_url: str,
363
+ init_api_key: str | None = None,
364
+ ) -> str:
365
+ """Attempts to load a configured API key or prompt if one is not found.
366
+
367
+ The API key is loaded in the following order:
368
+ 1. Thread local api key
369
+ 2. User explicitly provided api key
370
+ 3. Environment variable
371
+ 4. Netrc file
372
+ 5. Prompt for api key using wandb.login
373
+ """
374
+ # just use thread local api key if it's set
375
+ if _thread_local_api_settings.api_key:
376
+ return _thread_local_api_settings.api_key
377
+ if init_api_key is not None:
378
+ return init_api_key
379
+ if os.getenv("WANDB_API_KEY"):
380
+ return os.environ["WANDB_API_KEY"]
381
+
382
+ auth = requests.utils.get_netrc_auth(base_url)
383
+ if auth:
384
+ return auth[-1]
385
+
386
+ _, prompted_key = wandb_login._login(
387
+ host=base_url,
388
+ key=None,
389
+ # We will explicitly verify the key later
390
+ verify=False,
391
+ _silent=(
392
+ self.settings.get("silent", False) or self.settings.get("quiet", False)
393
+ ),
394
+ update_api_key=False,
395
+ _disable_warning=True,
396
+ )
397
+ return prompted_key
398
+
399
+ def _configure_sentry(self) -> None:
400
+ try:
401
+ viewer = self.viewer
402
+ except (ValueError, requests.RequestException):
403
+ # we need the viewer to configure the entity, and user email
404
+ return
405
+
406
+ email = viewer.email if viewer else None
407
+ entity = self.default_entity
408
+
409
+ self._sentry.configure_scope(
410
+ tags={
411
+ "entity": entity,
412
+ "email": email,
413
+ },
414
+ )
415
+
416
+ def create_project(self, name: str, entity: str) -> None:
417
+ """Create a new project.
418
+
419
+ Args:
420
+ name: The name of the new project.
421
+ entity: The entity of the new project.
422
+ """
423
+ self.client.execute(self.CREATE_PROJECT, {"entityName": entity, "name": name})
424
+
425
+ def create_run(
426
+ self,
427
+ *,
428
+ run_id: str | None = None,
429
+ project: str | None = None,
430
+ entity: str | None = None,
431
+ ) -> public.Run:
432
+ """Create a new run.
433
+
434
+ Args:
435
+ run_id: The ID to assign to the run. If not specified, W&B
436
+ creates a random ID.
437
+ project: The project where to log the run to. If no project is specified,
438
+ log the run to a project called "Uncategorized".
439
+ entity: The entity that owns the project. If no entity is
440
+ specified, log the run to the default entity.
441
+
442
+ Returns:
443
+ The newly created `Run`.
444
+ """
445
+ if entity is None:
446
+ entity = self.default_entity
447
+ return public.Run.create(self, run_id=run_id, project=project, entity=entity)
448
+
449
+ def create_run_queue(
450
+ self,
451
+ name: str,
452
+ type: public.RunQueueResourceType,
453
+ entity: str | None = None,
454
+ prioritization_mode: public.RunQueuePrioritizationMode | None = None,
455
+ config: dict | None = None,
456
+ template_variables: dict | None = None,
457
+ ) -> public.RunQueue:
458
+ """Create a new run queue in W&B Launch.
459
+
460
+ Args:
461
+ name: Name of the queue to create
462
+ type: Type of resource to be used for the queue. One of
463
+ "local-container", "local-process", "kubernetes","sagemaker",
464
+ or "gcp-vertex".
465
+ entity: Name of the entity to create the queue. If `None`, use
466
+ the configured or default entity.
467
+ prioritization_mode: Version of prioritization to use.
468
+ Either "V0" or `None`.
469
+ config: Default resource configuration to be used for the queue.
470
+ Use handlebars (eg. `{{var}}`) to specify template variables.
471
+ template_variables: A dictionary of template variable schemas to
472
+ use with the config.
473
+
474
+ Returns:
475
+ The newly created `RunQueue`.
476
+
477
+ Raises:
478
+ `ValueError` if any of the parameters are invalid
479
+ `wandb.Error` on wandb API errors
480
+ """
481
+ # TODO(np): Need to check server capabilities for this feature
482
+ # 0. assert params are valid/normalized
483
+ if entity is None:
484
+ entity = self.settings["entity"] or self.default_entity
485
+ if entity is None:
486
+ raise ValueError(
487
+ "entity must be passed as a parameter, or set in settings"
488
+ )
489
+
490
+ if len(name) == 0:
491
+ raise ValueError("name must be non-empty")
492
+ if len(name) > 64:
493
+ raise ValueError("name must be less than 64 characters")
494
+
495
+ if type not in [
496
+ "local-container",
497
+ "local-process",
498
+ "kubernetes",
499
+ "sagemaker",
500
+ "gcp-vertex",
501
+ ]:
502
+ raise ValueError(
503
+ "resource_type must be one of 'local-container', 'local-process', 'kubernetes', 'sagemaker', or 'gcp-vertex'"
504
+ )
505
+
506
+ if prioritization_mode:
507
+ prioritization_mode = prioritization_mode.upper()
508
+ if prioritization_mode not in ["V0"]:
509
+ raise ValueError("prioritization_mode must be 'V0' if present")
510
+
511
+ if config is None:
512
+ config = {}
513
+
514
+ # 1. create required default launch project in the entity
515
+ self.create_project(LAUNCH_DEFAULT_PROJECT, entity)
516
+
517
+ api = InternalApi(
518
+ default_settings={
519
+ "entity": entity,
520
+ "project": self.project(LAUNCH_DEFAULT_PROJECT),
521
+ },
522
+ retry_timedelta=RETRY_TIMEDELTA,
523
+ )
524
+
525
+ # 2. create default resource config, receive config id
526
+ config_json = json.dumps({"resource_args": {type: config}})
527
+ create_config_result = api.create_default_resource_config(
528
+ entity, type, config_json, template_variables
529
+ )
530
+ if not create_config_result["success"]:
531
+ raise wandb.Error("failed to create default resource config")
532
+ config_id = create_config_result["defaultResourceConfigID"]
533
+
534
+ # 3. create run queue
535
+ create_queue_result = api.create_run_queue(
536
+ entity,
537
+ LAUNCH_DEFAULT_PROJECT,
538
+ name,
539
+ "PROJECT",
540
+ prioritization_mode,
541
+ config_id,
542
+ )
543
+ if not create_queue_result["success"]:
544
+ raise wandb.Error("failed to create run queue")
545
+
546
+ return public.RunQueue(
547
+ client=self.client,
548
+ name=name,
549
+ entity=entity,
550
+ prioritization_mode=prioritization_mode,
551
+ _access="PROJECT",
552
+ _default_resource_config_id=config_id,
553
+ _default_resource_config=config,
554
+ )
555
+
556
+ def create_custom_chart(
557
+ self,
558
+ entity: str,
559
+ name: str,
560
+ display_name: str,
561
+ spec_type: Literal["vega2"],
562
+ access: Literal["private", "public"],
563
+ spec: str | dict,
564
+ ) -> str:
565
+ """Create a custom chart preset and return its id.
566
+
567
+ Args:
568
+ entity: The entity (user or team) that owns the chart
569
+ name: Unique identifier for the chart preset
570
+ display_name: Human-readable name shown in the UI
571
+ spec_type: Type of specification. Must be "vega2" for Vega-Lite v2 specifications.
572
+ access: Access level for the chart:
573
+ - "private": Chart is only accessible to the entity that created it
574
+ - "public": Chart is publicly accessible
575
+ spec: The Vega/Vega-Lite specification as a dictionary or JSON string
576
+
577
+ Returns:
578
+ The ID of the created chart preset in the format "entity/name"
579
+
580
+ Raises:
581
+ wandb.Error: If chart creation fails
582
+ UnsupportedError: If the server doesn't support custom charts
583
+
584
+ Example:
585
+ ```python
586
+ import wandb
587
+
588
+ api = wandb.Api()
589
+
590
+ # Define a simple bar chart specification
591
+ vega_spec = {
592
+ "$schema": "https://vega.github.io/schema/vega-lite/v6.json",
593
+ "mark": "bar",
594
+ "data": {"name": "wandb"},
595
+ "encoding": {
596
+ "x": {"field": "${field:x}", "type": "ordinal"},
597
+ "y": {"field": "${field:y}", "type": "quantitative"},
598
+ },
599
+ }
600
+
601
+ # Create the custom chart
602
+ chart_id = api.create_custom_chart(
603
+ entity="my-team",
604
+ name="my-bar-chart",
605
+ display_name="My Custom Bar Chart",
606
+ spec_type="vega2",
607
+ access="private",
608
+ spec=vega_spec,
609
+ )
610
+
611
+ # Use with wandb.plot_table()
612
+ chart = wandb.plot_table(
613
+ vega_spec_name=chart_id,
614
+ data_table=my_table,
615
+ fields={"x": "category", "y": "value"},
616
+ )
617
+ ```
618
+ """
619
+ # Convert user-facing lowercase access to backend uppercase
620
+ backend_access = access.upper()
621
+
622
+ api = InternalApi(retry_timedelta=RETRY_TIMEDELTA)
623
+ result = api.create_custom_chart(
624
+ entity=entity,
625
+ name=name,
626
+ display_name=display_name,
627
+ spec_type=spec_type,
628
+ access=backend_access,
629
+ spec=spec,
630
+ )
631
+ if result is None or result.get("chart") is None:
632
+ raise wandb.Error("failed to create custom chart")
633
+ return result["chart"]["id"]
634
+
635
+ def upsert_run_queue(
636
+ self,
637
+ name: str,
638
+ resource_config: dict,
639
+ resource_type: public.RunQueueResourceType,
640
+ entity: str | None = None,
641
+ template_variables: dict | None = None,
642
+ external_links: dict | None = None,
643
+ prioritization_mode: public.RunQueuePrioritizationMode | None = None,
644
+ ):
645
+ """Upsert a run queue in W&B Launch.
646
+
647
+ Args:
648
+ name: Name of the queue to create
649
+ entity: Optional name of the entity to create the queue. If `None`,
650
+ use the configured or default entity.
651
+ resource_config: Optional default resource configuration to be used
652
+ for the queue. Use handlebars (eg. `{{var}}`) to specify
653
+ template variables.
654
+ resource_type: Type of resource to be used for the queue. One of
655
+ "local-container", "local-process", "kubernetes", "sagemaker",
656
+ or "gcp-vertex".
657
+ template_variables: A dictionary of template variable schemas to
658
+ be used with the config.
659
+ external_links: Optional dictionary of external links to be used
660
+ with the queue.
661
+ prioritization_mode: Optional version of prioritization to use.
662
+ Either "V0" or None
663
+
664
+ Returns:
665
+ The upserted `RunQueue`.
666
+
667
+ Raises:
668
+ ValueError if any of the parameters are invalid
669
+ wandb.Error on wandb API errors
670
+ """
671
+ if entity is None:
672
+ entity = self.settings["entity"] or self.default_entity
673
+ if entity is None:
674
+ raise ValueError(
675
+ "entity must be passed as a parameter, or set in settings"
676
+ )
677
+
678
+ if len(name) == 0:
679
+ raise ValueError("name must be non-empty")
680
+ if len(name) > 64:
681
+ raise ValueError("name must be less than 64 characters")
682
+
683
+ prioritization_mode = prioritization_mode or "DISABLED"
684
+ prioritization_mode = prioritization_mode.upper()
685
+ if prioritization_mode not in ["V0", "DISABLED"]:
686
+ raise ValueError(
687
+ "prioritization_mode must be 'V0' or 'DISABLED' if present"
688
+ )
689
+
690
+ if resource_type not in [
691
+ "local-container",
692
+ "local-process",
693
+ "kubernetes",
694
+ "sagemaker",
695
+ "gcp-vertex",
696
+ ]:
697
+ raise ValueError(
698
+ "resource_type must be one of 'local-container', 'local-process', 'kubernetes', 'sagemaker', or 'gcp-vertex'"
699
+ )
700
+
701
+ self.create_project(LAUNCH_DEFAULT_PROJECT, entity)
702
+ api = InternalApi(
703
+ default_settings={
704
+ "entity": entity,
705
+ "project": self.project(LAUNCH_DEFAULT_PROJECT),
706
+ },
707
+ retry_timedelta=RETRY_TIMEDELTA,
708
+ )
709
+ # User provides external_links as a dict with name: url format
710
+ # but backend stores it as a list of dicts with url and label keys.
711
+ external_links = external_links or {}
712
+ external_links = {
713
+ "links": [
714
+ {
715
+ "label": key,
716
+ "url": value,
717
+ }
718
+ for key, value in external_links.items()
719
+ ]
720
+ }
721
+ upsert_run_queue_result = api.upsert_run_queue(
722
+ name,
723
+ entity,
724
+ resource_type,
725
+ {"resource_args": {resource_type: resource_config}},
726
+ template_variables=template_variables,
727
+ external_links=external_links,
728
+ prioritization_mode=prioritization_mode,
729
+ )
730
+ if not upsert_run_queue_result["success"]:
731
+ raise wandb.Error("failed to create run queue")
732
+ schema_errors = (
733
+ upsert_run_queue_result.get("configSchemaValidationErrors") or []
734
+ )
735
+ for error in schema_errors:
736
+ wandb.termwarn(f"resource config validation: {error}")
737
+
738
+ return public.RunQueue(
739
+ client=self.client,
740
+ name=name,
741
+ entity=entity,
742
+ )
743
+
744
+ def create_user(self, email: str, admin: bool | None = False) -> User:
745
+ """Create a new user.
746
+
747
+ Args:
748
+ email: The email address of the user.
749
+ admin: Set user as a global instance administrator.
750
+
751
+ Returns:
752
+ A `User` object.
753
+ """
754
+ from .users import User
755
+
756
+ return User.create(self, email, admin)
757
+
758
+ def sync_tensorboard(self, root_dir, run_id=None, project=None, entity=None):
759
+ """Sync a local directory containing tfevent files to wandb."""
760
+ from wandb.sync import SyncManager # TODO: circular import madness
761
+
762
+ run_id = run_id or runid.generate_id()
763
+ project = project or self.settings.get("project") or "uncategorized"
764
+ entity = entity or self.default_entity
765
+ # TODO: pipe through log_path to inform the user how to debug
766
+ sm = SyncManager(
767
+ project=project,
768
+ entity=entity,
769
+ run_id=run_id,
770
+ mark_synced=False,
771
+ app_url=self.client.app_url,
772
+ view=False,
773
+ verbose=False,
774
+ sync_tensorboard=True,
775
+ )
776
+ sm.add(root_dir)
777
+ sm.start()
778
+ while not sm.is_done():
779
+ _ = sm.poll()
780
+ return self.run("/".join([entity, project, run_id]))
781
+
782
+ @property
783
+ def client(self) -> RetryingClient:
784
+ """Returns the client object."""
785
+ return self._client
786
+
787
+ @property
788
+ def user_agent(self) -> str:
789
+ """Returns W&B public user agent."""
790
+ return "W&B Public Client {}".format(wandb.__version__)
791
+
792
+ @property
793
+ def default_entity(self) -> str | None:
794
+ """Returns the default W&B entity."""
795
+ if self._default_entity is None:
796
+ res = self._client.execute(self.DEFAULT_ENTITY_QUERY)
797
+ self._default_entity = (res.get("viewer") or {}).get("entity")
798
+ return self._default_entity
799
+
800
+ @property
801
+ def viewer(self) -> User:
802
+ """Returns the viewer object.
803
+
804
+ Raises:
805
+ ValueError: If viewer data is not able to be fetched from W&B.
806
+ requests.RequestException: If an error occurs while making the graphql request.
807
+ """
808
+ from .users import User
809
+
810
+ if self._viewer is None:
811
+ viewer = self._client.execute(self.VIEWER_QUERY).get("viewer")
812
+
813
+ if viewer is None:
814
+ raise ValueError(
815
+ "Unable to fetch user data from W&B,"
816
+ " please verify your API key is valid."
817
+ )
818
+
819
+ self._viewer = User(self._client, viewer)
820
+ self._default_entity = self._viewer.entity
821
+ return self._viewer
822
+
823
+ def flush(self):
824
+ """Flush the local cache.
825
+
826
+ The api object keeps a local cache of runs, so if the state of the run
827
+ may change while executing your script you must clear the local cache
828
+ with `api.flush()` to get the latest values associated with the run.
829
+ """
830
+ self._runs = {}
831
+
832
+ def from_path(self, path: str):
833
+ """Return a run, sweep, project or report from a path.
834
+
835
+ Args:
836
+ path: The path to the project, run, sweep or report
837
+
838
+ Returns:
839
+ A `Project`, `Run`, `Sweep`, or `BetaReport` instance.
840
+
841
+ Raises:
842
+ `wandb.Error` if path is invalid or the object doesn't exist.
843
+
844
+ Examples:
845
+ In the proceeding code snippets "project", "team", "run_id", "sweep_id",
846
+ and "report_name" are placeholders for the project, team, run ID,
847
+ sweep ID, and the name of a specific report, respectively.
848
+
849
+ ```python
850
+ import wandb
851
+
852
+ api = wandb.Api()
853
+
854
+ project = api.from_path("project")
855
+ team_project = api.from_path("team/project")
856
+ run = api.from_path("team/project/runs/run_id")
857
+ sweep = api.from_path("team/project/sweeps/sweep_id")
858
+ report = api.from_path("team/project/reports/report_name")
859
+ ```
860
+ """
861
+ parts = path.strip("/ ").split("/")
862
+ if len(parts) == 1:
863
+ return self.project(path)
864
+ elif len(parts) == 2:
865
+ return self.project(parts[1], parts[0])
866
+ elif len(parts) == 3:
867
+ return self.run(path)
868
+ elif len(parts) == 4:
869
+ if parts[2].startswith("run"):
870
+ return self.run(path)
871
+ elif parts[2].startswith("sweep"):
872
+ return self.sweep(path)
873
+ elif parts[2].startswith("report"):
874
+ if "--" not in parts[-1]:
875
+ if "-" in parts[-1]:
876
+ raise wandb.Error(
877
+ "Invalid report path, should be team/project/reports/Name--XXXX"
878
+ )
879
+ else:
880
+ parts[-1] = "--" + parts[-1]
881
+ name, id = parts[-1].split("--")
882
+ return public.BetaReport(
883
+ self.client,
884
+ {
885
+ "displayName": urllib.parse.unquote(name.replace("-", " ")),
886
+ "id": id,
887
+ "spec": "{}",
888
+ },
889
+ parts[0],
890
+ parts[1],
891
+ )
892
+ raise wandb.Error(
893
+ "Invalid path, should be TEAM/PROJECT/TYPE/ID where TYPE is runs, sweeps, or reports"
894
+ )
895
+
896
+ def _parse_project_path(self, path):
897
+ """Return project and entity for project specified by path."""
898
+ project = self.settings["project"] or "uncategorized"
899
+ entity = self.settings["entity"] or self.default_entity
900
+ if path is None:
901
+ return entity, project
902
+ parts = path.split("/", 1)
903
+ if len(parts) == 1:
904
+ return entity, path
905
+ return parts
906
+
907
+ def _parse_path(self, path):
908
+ """Parse url, filepath, or docker paths.
909
+
910
+ Allows paths in the following formats:
911
+ - url: entity/project/runs/id
912
+ - path: entity/project/id
913
+ - docker: entity/project:id
914
+
915
+ Entity is optional and will fall back to the current logged-in user.
916
+ """
917
+ project = self.settings["project"] or "uncategorized"
918
+ entity = self.settings["entity"] or self.default_entity
919
+ parts = (
920
+ path.replace("/runs/", "/").replace("/sweeps/", "/").strip("/ ").split("/")
921
+ )
922
+ if ":" in parts[-1]:
923
+ id = parts[-1].split(":")[-1]
924
+ parts[-1] = parts[-1].split(":")[0]
925
+ elif parts[-1]:
926
+ id = parts[-1]
927
+ if len(parts) == 1 and project != "uncategorized":
928
+ pass
929
+ elif len(parts) > 1:
930
+ project = parts[1]
931
+ if entity and id == project:
932
+ project = parts[0]
933
+ else:
934
+ entity = parts[0]
935
+ if len(parts) == 3:
936
+ entity = parts[0]
937
+ else:
938
+ project = parts[0]
939
+ return entity, project, id
940
+
941
+ def _parse_artifact_path(self, path):
942
+ """Return project, entity and artifact name for project specified by path."""
943
+ project = self.settings["project"] or "uncategorized"
944
+ entity = self.settings["entity"] or self.default_entity
945
+ if path is None:
946
+ return entity, project
947
+
948
+ parsed = ArtifactPath.from_str(path)
949
+ parsed = parsed.with_defaults(prefix=entity, project=project)
950
+ return parsed.prefix, parsed.project, parsed.name
951
+
952
+ def projects(
953
+ self, entity: str | None = None, per_page: int = 200
954
+ ) -> public.Projects:
955
+ """Get projects for a given entity.
956
+
957
+ Args:
958
+ entity: Name of the entity requested. If None, will fall back to
959
+ the default entity passed to `Api`. If no default entity,
960
+ will raise a `ValueError`.
961
+ per_page: Sets the page size for query pagination. If set to `None`,
962
+ use the default size. Usually there is no reason to change this.
963
+
964
+ Returns:
965
+ A `Projects` object which is an iterable collection of `Project`objects.
966
+ """
967
+ if entity is None:
968
+ entity = self.settings["entity"] or self.default_entity
969
+ if entity is None:
970
+ raise ValueError(
971
+ "entity must be passed as a parameter, or set in settings"
972
+ )
973
+ if entity not in self._projects:
974
+ self._projects[entity] = public.Projects(
975
+ self.client, entity, per_page=per_page
976
+ )
977
+ return self._projects[entity]
978
+
979
+ def project(self, name: str, entity: str | None = None) -> public.Project:
980
+ """Return the `Project` with the given name (and entity, if given).
981
+
982
+ Args:
983
+ name: The project name.
984
+ entity: Name of the entity requested. If None, will fall back to the
985
+ default entity passed to `Api`. If no default entity, will
986
+ raise a `ValueError`.
987
+
988
+ Returns:
989
+ A `Project` object.
990
+ """
991
+ # For registry artifacts, capture potential org user inputted before resolving entity
992
+ org = entity if is_artifact_registry_project(name) else ""
993
+
994
+ if entity is None:
995
+ entity = self.settings["entity"] or self.default_entity
996
+
997
+ # For registry artifacts, resolve org-based entity
998
+ if is_artifact_registry_project(name):
999
+ settings_entity = self.settings["entity"] or self.default_entity
1000
+ entity = InternalApi()._resolve_org_entity_name(
1001
+ entity=settings_entity, organization=org
1002
+ )
1003
+ return public.Project(self.client, entity, name, {})
1004
+
1005
+ def reports(
1006
+ self, path: str = "", name: str | None = None, per_page: int = 50
1007
+ ) -> public.Reports:
1008
+ """Get reports for a given project path.
1009
+
1010
+ Note: `wandb.Api.reports()` API is in beta and will likely change in
1011
+ future releases.
1012
+
1013
+ Args:
1014
+ path: The path to the project the report resides in. Specify the
1015
+ entity that created the project as a prefix followed by a
1016
+ forward slash.
1017
+ name: Name of the report requested.
1018
+ per_page: Sets the page size for query pagination. If set to
1019
+ `None`, use the default size. Usually there is no reason to
1020
+ change this.
1021
+
1022
+ Returns:
1023
+ A `Reports` object which is an iterable collection of
1024
+ `BetaReport` objects.
1025
+
1026
+ Examples:
1027
+ ```python
1028
+ import wandb
1029
+
1030
+ wandb.Api.reports("entity/project")
1031
+ ```
1032
+ """
1033
+ entity, project, _ = self._parse_path(path + "/fake_run")
1034
+
1035
+ if name:
1036
+ name = urllib.parse.unquote(name)
1037
+ key = "/".join([entity, project, str(name)])
1038
+ else:
1039
+ key = "/".join([entity, project])
1040
+
1041
+ if key not in self._reports:
1042
+ self._reports[key] = public.Reports(
1043
+ self.client,
1044
+ public.Project(self.client, entity, project, {}),
1045
+ name=name,
1046
+ per_page=per_page,
1047
+ )
1048
+ return self._reports[key]
1049
+
1050
+ def create_team(self, team: str, admin_username: str | None = None) -> Team:
1051
+ """Create a new team.
1052
+
1053
+ Args:
1054
+ team: The name of the team
1055
+ admin_username: Username of the admin user of the team.
1056
+ Defaults to the current user.
1057
+
1058
+ Returns:
1059
+ A `Team` object.
1060
+ """
1061
+ from .teams import Team
1062
+
1063
+ return Team.create(self, team, admin_username)
1064
+
1065
+ def team(self, team: str) -> Team:
1066
+ """Return the matching `Team` with the given name.
1067
+
1068
+ Args:
1069
+ team: The name of the team.
1070
+
1071
+ Returns:
1072
+ A `Team` object.
1073
+ """
1074
+ from .teams import Team
1075
+
1076
+ return Team(self.client, team)
1077
+
1078
+ def user(self, username_or_email: str) -> User | None:
1079
+ """Return a user from a username or email address.
1080
+
1081
+ This function only works for local administrators. Use `api.viewer`
1082
+ to get your own user object.
1083
+
1084
+ Args:
1085
+ username_or_email: The username or email address of the user.
1086
+
1087
+ Returns:
1088
+ A `User` object or None if a user is not found.
1089
+ """
1090
+ from .users import User
1091
+
1092
+ res = self._client.execute(self.USERS_QUERY, {"query": username_or_email})
1093
+ if len(res["users"]["edges"]) == 0:
1094
+ return None
1095
+ elif len(res["users"]["edges"]) > 1:
1096
+ wandb.termwarn(
1097
+ "Found multiple users, returning the first user matching {}".format(
1098
+ username_or_email
1099
+ )
1100
+ )
1101
+ return User(self._client, res["users"]["edges"][0]["node"])
1102
+
1103
+ def users(self, username_or_email: str) -> list[User]:
1104
+ """Return all users from a partial username or email address query.
1105
+
1106
+ This function only works for local administrators. Use `api.viewer`
1107
+ to get your own user object.
1108
+
1109
+ Args:
1110
+ username_or_email: The prefix or suffix of the user you want to find.
1111
+
1112
+ Returns:
1113
+ An array of `User` objects.
1114
+ """
1115
+ from .users import User
1116
+
1117
+ res = self._client.execute(self.USERS_QUERY, {"query": username_or_email})
1118
+ return [User(self._client, edge["node"]) for edge in res["users"]["edges"]]
1119
+
1120
+ def runs(
1121
+ self,
1122
+ path: str | None = None,
1123
+ filters: dict[str, Any] | None = None,
1124
+ order: str = "+created_at",
1125
+ per_page: int = 50,
1126
+ include_sweeps: bool = True,
1127
+ lazy: bool = True,
1128
+ ):
1129
+ """Returns a `Runs` object, which lazily iterates over `Run` objects.
1130
+
1131
+ Fields you can filter by include:
1132
+ - `createdAt`: The timestamp when the run was created. (in ISO 8601 format, e.g. "2023-01-01T12:00:00Z")
1133
+ - `displayName`: The human-readable display name of the run. (e.g. "eager-fox-1")
1134
+ - `duration`: The total runtime of the run in seconds.
1135
+ - `group`: The group name used to organize related runs together.
1136
+ - `host`: The hostname where the run was executed.
1137
+ - `jobType`: The type of job or purpose of the run.
1138
+ - `name`: The unique identifier of the run. (e.g. "a1b2cdef")
1139
+ - `state`: The current state of the run.
1140
+ - `tags`: The tags associated with the run.
1141
+ - `username`: The username of the user who initiated the run
1142
+
1143
+ Additionally, you can filter by items in the run config or summary metrics.
1144
+ Such as `config.experiment_name`, `summary_metrics.loss`, etc.
1145
+
1146
+ For more complex filtering, you can use MongoDB query operators.
1147
+ For details, see: https://docs.mongodb.com/manual/reference/operator/query
1148
+ The following operations are supported:
1149
+ - `$and`
1150
+ - `$or`
1151
+ - `$nor`
1152
+ - `$eq`
1153
+ - `$ne`
1154
+ - `$gt`
1155
+ - `$gte`
1156
+ - `$lt`
1157
+ - `$lte`
1158
+ - `$in`
1159
+ - `$nin`
1160
+ - `$exists`
1161
+ - `$regex`
1162
+
1163
+
1164
+
1165
+ Args:
1166
+ path: (str) path to project, should be in the form: "entity/project"
1167
+ filters: (dict) queries for specific runs using the MongoDB query language.
1168
+ You can filter by run properties such as config.key, summary_metrics.key, state, entity, createdAt, etc.
1169
+ For example: `{"config.experiment_name": "foo"}` would find runs with a config entry
1170
+ of experiment name set to "foo"
1171
+ order: (str) Order can be `created_at`, `heartbeat_at`, `config.*.value`, or `summary_metrics.*`.
1172
+ If you prepend order with a + order is ascending (default).
1173
+ If you prepend order with a - order is descending.
1174
+ The default order is run.created_at from oldest to newest.
1175
+ per_page: (int) Sets the page size for query pagination.
1176
+ include_sweeps: (bool) Whether to include the sweep runs in the results.
1177
+ lazy: (bool) Whether to use lazy loading for faster performance.
1178
+ When True (default), only essential run metadata is loaded initially.
1179
+ Heavy fields like config, summaryMetrics, and systemMetrics are loaded
1180
+ on-demand when accessed. Set to False for full data upfront.
1181
+
1182
+ Returns:
1183
+ A `Runs` object, which is an iterable collection of `Run` objects.
1184
+
1185
+ Examples:
1186
+ ```python
1187
+ # Find runs in project where config.experiment_name has been set to "foo"
1188
+ api.runs(path="my_entity/project", filters={"config.experiment_name": "foo"})
1189
+ ```
1190
+
1191
+ ```python
1192
+ # Find runs in project where config.experiment_name has been set to "foo" or "bar"
1193
+ api.runs(
1194
+ path="my_entity/project",
1195
+ filters={
1196
+ "$or": [
1197
+ {"config.experiment_name": "foo"},
1198
+ {"config.experiment_name": "bar"},
1199
+ ]
1200
+ },
1201
+ )
1202
+ ```
1203
+
1204
+ ```python
1205
+ # Find runs in project where config.experiment_name matches a regex
1206
+ # (anchors are not supported)
1207
+ api.runs(
1208
+ path="my_entity/project",
1209
+ filters={"config.experiment_name": {"$regex": "b.*"}},
1210
+ )
1211
+ ```
1212
+
1213
+ ```python
1214
+ # Find runs in project where the run name matches a regex
1215
+ # (anchors are not supported)
1216
+ api.runs(
1217
+ path="my_entity/project", filters={"display_name": {"$regex": "^foo.*"}}
1218
+ )
1219
+ ```
1220
+
1221
+ ```python
1222
+ # Find runs in project sorted by ascending loss
1223
+ api.runs(path="my_entity/project", order="+summary_metrics.loss")
1224
+ ```
1225
+ """
1226
+ entity, project = self._parse_project_path(path)
1227
+ filters = filters or {}
1228
+ key = (path or "") + str(filters) + str(order)
1229
+
1230
+ # Check if we have cached results
1231
+ if self._runs.get(key):
1232
+ cached_runs = self._runs[key]
1233
+ # If requesting full data but cached data is lazy, upgrade it
1234
+ if not lazy and cached_runs._lazy:
1235
+ cached_runs.upgrade_to_full()
1236
+ return cached_runs
1237
+
1238
+ # Create new Runs object
1239
+ self._runs[key] = public.Runs(
1240
+ self.client,
1241
+ entity,
1242
+ project,
1243
+ filters=filters,
1244
+ order=order,
1245
+ per_page=per_page,
1246
+ include_sweeps=include_sweeps,
1247
+ lazy=lazy,
1248
+ )
1249
+ return self._runs[key]
1250
+
1251
+ @normalize_exceptions
1252
+ def run(self, path=""):
1253
+ """Return a single run by parsing path in the form `entity/project/run_id`.
1254
+
1255
+ Args:
1256
+ path: Path to run in the form `entity/project/run_id`.
1257
+ If `api.entity` is set, this can be in the form `project/run_id`
1258
+ and if `api.project` is set this can just be the run_id.
1259
+
1260
+ Returns:
1261
+ A `Run` object.
1262
+ """
1263
+ entity, project, run_id = self._parse_path(path)
1264
+ if not self._runs.get(path):
1265
+ # Individual runs should load full data by default
1266
+ self._runs[path] = public.Run(
1267
+ self.client, entity, project, run_id, lazy=False
1268
+ )
1269
+ return self._runs[path]
1270
+
1271
+ def queued_run(
1272
+ self,
1273
+ entity: str,
1274
+ project: str,
1275
+ queue_name: str,
1276
+ run_queue_item_id: str,
1277
+ project_queue=None,
1278
+ priority=None,
1279
+ ):
1280
+ """Return a single queued run based on the path.
1281
+
1282
+ Parses paths of the form `entity/project/queue_id/run_queue_item_id`.
1283
+ """
1284
+ return public.QueuedRun(
1285
+ self.client,
1286
+ entity,
1287
+ project,
1288
+ queue_name,
1289
+ run_queue_item_id,
1290
+ project_queue=project_queue,
1291
+ priority=priority,
1292
+ )
1293
+
1294
+ def run_queue(
1295
+ self,
1296
+ entity: str,
1297
+ name: str,
1298
+ ):
1299
+ """Return the named `RunQueue` for entity.
1300
+
1301
+ See `Api.create_run_queue` for more information on how to create a run queue.
1302
+ """
1303
+ return public.RunQueue(
1304
+ self.client,
1305
+ name,
1306
+ entity,
1307
+ )
1308
+
1309
+ @normalize_exceptions
1310
+ def sweep(self, path=""):
1311
+ """Return a sweep by parsing path in the form `entity/project/sweep_id`.
1312
+
1313
+ Args:
1314
+ path: Path to sweep in the form entity/project/sweep_id.
1315
+ If `api.entity` is set, this can be in the form
1316
+ project/sweep_id and if `api.project` is set
1317
+ this can just be the sweep_id.
1318
+
1319
+ Returns:
1320
+ A `Sweep` object.
1321
+ """
1322
+ entity, project, sweep_id = self._parse_path(path)
1323
+ if not self._sweeps.get(path):
1324
+ self._sweeps[path] = public.Sweep(self.client, entity, project, sweep_id)
1325
+ return self._sweeps[path]
1326
+
1327
+ @normalize_exceptions
1328
+ def artifact_types(self, project: str | None = None) -> ArtifactTypes:
1329
+ """Returns a collection of matching artifact types.
1330
+
1331
+ Args:
1332
+ project: The project name or path to filter on.
1333
+
1334
+ Returns:
1335
+ An iterable `ArtifactTypes` object.
1336
+ """
1337
+ from .artifacts import ArtifactTypes
1338
+
1339
+ project_path = project
1340
+ entity, project = self._parse_project_path(project_path)
1341
+ # If its a Registry project, the entity is considered to be an org instead
1342
+ if is_artifact_registry_project(project):
1343
+ settings_entity = self.settings["entity"] or self.default_entity
1344
+ org = parse_org_from_registry_path(project_path, PathType.PROJECT)
1345
+ entity = InternalApi()._resolve_org_entity_name(
1346
+ entity=settings_entity, organization=org
1347
+ )
1348
+ return ArtifactTypes(self.client, entity, project)
1349
+
1350
+ @normalize_exceptions
1351
+ def artifact_type(self, type_name: str, project: str | None = None) -> ArtifactType:
1352
+ """Returns the matching `ArtifactType`.
1353
+
1354
+ Args:
1355
+ type_name: The name of the artifact type to retrieve.
1356
+ project: If given, a project name or path to filter on.
1357
+
1358
+ Returns:
1359
+ An `ArtifactType` object.
1360
+ """
1361
+ from .artifacts import ArtifactType
1362
+
1363
+ project_path = project
1364
+ entity, project = self._parse_project_path(project_path)
1365
+ # If its an Registry artifact, the entity is an org instead
1366
+ if is_artifact_registry_project(project):
1367
+ org = parse_org_from_registry_path(project_path, PathType.PROJECT)
1368
+ settings_entity = self.settings["entity"] or self.default_entity
1369
+ entity = InternalApi()._resolve_org_entity_name(
1370
+ entity=settings_entity, organization=org
1371
+ )
1372
+ return ArtifactType(self.client, entity, project, type_name)
1373
+
1374
+ @normalize_exceptions
1375
+ def artifact_collections(
1376
+ self, project_name: str, type_name: str, per_page: int = 50
1377
+ ) -> ArtifactCollections:
1378
+ """Returns a collection of matching artifact collections.
1379
+
1380
+ Args:
1381
+ project_name: The name of the project to filter on.
1382
+ type_name: The name of the artifact type to filter on.
1383
+ per_page: Sets the page size for query pagination. None will use the default size.
1384
+ Usually there is no reason to change this.
1385
+
1386
+ Returns:
1387
+ An iterable `ArtifactCollections` object.
1388
+ """
1389
+ from .artifacts import ArtifactCollections
1390
+
1391
+ entity, project = self._parse_project_path(project_name)
1392
+ # If iterating through Registry project, the entity is considered to be an org instead
1393
+ if is_artifact_registry_project(project):
1394
+ org = parse_org_from_registry_path(project_name, PathType.PROJECT)
1395
+ settings_entity = self.settings["entity"] or self.default_entity
1396
+ entity = InternalApi()._resolve_org_entity_name(
1397
+ entity=settings_entity, organization=org
1398
+ )
1399
+ return ArtifactCollections(
1400
+ self.client, entity, project, type_name, per_page=per_page
1401
+ )
1402
+
1403
+ @normalize_exceptions
1404
+ def artifact_collection(self, type_name: str, name: str) -> ArtifactCollection:
1405
+ """Returns a single artifact collection by type.
1406
+
1407
+ You can use the returned `ArtifactCollection` object to retrieve
1408
+ information about specific artifacts in that collection, and more.
1409
+
1410
+ Args:
1411
+ type_name: The type of artifact collection to fetch.
1412
+ name: An artifact collection name. Optionally append the entity
1413
+ that logged the artifact as a prefix followed by a forward
1414
+ slash.
1415
+
1416
+ Returns:
1417
+ An `ArtifactCollection` object.
1418
+
1419
+ Examples:
1420
+ In the proceeding code snippet "type", "entity", "project", and
1421
+ "artifact_name" are placeholders for the collection type, your W&B
1422
+ entity, name of the project the artifact is in, and the name of
1423
+ the artifact, respectively.
1424
+
1425
+ ```python
1426
+ import wandb
1427
+
1428
+ collections = wandb.Api().artifact_collection(
1429
+ type_name="type", name="entity/project/artifact_name"
1430
+ )
1431
+
1432
+ # Get the first artifact in the collection
1433
+ artifact_example = collections.artifacts()[0]
1434
+
1435
+ # Download the contents of the artifact to the specified root directory.
1436
+ artifact_example.download()
1437
+ ```
1438
+ """
1439
+ from .artifacts import ArtifactCollection
1440
+
1441
+ entity, project, collection_name = self._parse_artifact_path(name)
1442
+ # If its an Registry artifact, the entity is considered to be an org instead
1443
+ if is_artifact_registry_project(project):
1444
+ org = parse_org_from_registry_path(name, PathType.ARTIFACT)
1445
+ settings_entity = self.settings["entity"] or self.default_entity
1446
+ entity = InternalApi()._resolve_org_entity_name(
1447
+ entity=settings_entity, organization=org
1448
+ )
1449
+
1450
+ if entity is None:
1451
+ raise ValueError(
1452
+ "Could not determine entity. Please include the entity as part of the collection name path."
1453
+ )
1454
+
1455
+ return ArtifactCollection(
1456
+ self.client, entity, project, collection_name, type_name
1457
+ )
1458
+
1459
+ @normalize_exceptions
1460
+ def artifact_versions(self, type_name, name, per_page=50):
1461
+ """Deprecated. Use `Api.artifacts(type_name, name)` method instead."""
1462
+ deprecate(
1463
+ field_name=Deprecated.api__artifact_versions,
1464
+ warning_message=(
1465
+ "Api.artifact_versions(type_name, name) is deprecated, "
1466
+ "use Api.artifacts(type_name, name) instead."
1467
+ ),
1468
+ )
1469
+ return self.artifacts(type_name, name, per_page=per_page)
1470
+
1471
+ @normalize_exceptions
1472
+ def artifacts(
1473
+ self,
1474
+ type_name: str,
1475
+ name: str,
1476
+ per_page: int = 50,
1477
+ tags: list[str] | None = None,
1478
+ ) -> Artifacts:
1479
+ """Return an `Artifacts` collection.
1480
+
1481
+ Args:
1482
+ type_name: The type of artifacts to fetch.
1483
+ name: The artifact's collection name. Optionally append the
1484
+ entity that logged the artifact as a prefix followed by
1485
+ a forward slash.
1486
+ per_page: Sets the page size for query pagination. If set to
1487
+ `None`, use the default size. Usually there is no reason
1488
+ to change this.
1489
+ tags: Only return artifacts with all of these tags.
1490
+
1491
+ Returns:
1492
+ An iterable `Artifacts` object.
1493
+
1494
+ Examples:
1495
+ In the proceeding code snippet, "type", "entity", "project", and
1496
+ "artifact_name" are placeholders for the artifact type, W&B entity,
1497
+ name of the project the artifact was logged to,
1498
+ and the name of the artifact, respectively.
1499
+
1500
+ ```python
1501
+ import wandb
1502
+
1503
+ wandb.Api().artifacts(type_name="type", name="entity/project/artifact_name")
1504
+ ```
1505
+ """
1506
+ from .artifacts import Artifacts
1507
+
1508
+ entity, project, collection_name = self._parse_artifact_path(name)
1509
+ # If its an Registry project, the entity is considered to be an org instead
1510
+ if is_artifact_registry_project(project):
1511
+ org = parse_org_from_registry_path(name, PathType.ARTIFACT)
1512
+ settings_entity = self.settings["entity"] or self.default_entity
1513
+ entity = InternalApi()._resolve_org_entity_name(
1514
+ entity=settings_entity, organization=org
1515
+ )
1516
+ return Artifacts(
1517
+ self.client,
1518
+ entity,
1519
+ project,
1520
+ collection_name,
1521
+ type_name,
1522
+ per_page=per_page,
1523
+ tags=tags,
1524
+ )
1525
+
1526
+ @normalize_exceptions
1527
+ def _artifact(
1528
+ self, name: str, type: str | None = None, enable_tracking: bool = False
1529
+ ) -> Artifact:
1530
+ from wandb.sdk.artifacts.artifact import Artifact
1531
+
1532
+ if name is None:
1533
+ raise ValueError("You must specify name= to fetch an artifact.")
1534
+ entity, project, artifact_name = self._parse_artifact_path(name)
1535
+
1536
+ # If its an Registry artifact, the entity is an org instead
1537
+ if is_artifact_registry_project(project):
1538
+ organization = (
1539
+ name.split("/")[0]
1540
+ if name.count("/") == 2
1541
+ else self.settings["organization"]
1542
+ )
1543
+ # set entity to match the settings since in above code it was potentially set to an org
1544
+ settings_entity = self.settings["entity"] or self.default_entity
1545
+ # Registry artifacts are under the org entity. Because we offer a shorthand and alias for this path,
1546
+ # we need to fetch the org entity to for the user behind the scenes.
1547
+ entity = InternalApi()._resolve_org_entity_name(
1548
+ entity=settings_entity, organization=organization
1549
+ )
1550
+
1551
+ if entity is None:
1552
+ raise ValueError(
1553
+ "Could not determine entity. Please include the entity as part of the artifact name path."
1554
+ )
1555
+
1556
+ path = FullArtifactPath(prefix=entity, project=project, name=artifact_name)
1557
+ artifact = Artifact._from_name(
1558
+ path=path,
1559
+ client=self.client,
1560
+ enable_tracking=enable_tracking,
1561
+ )
1562
+ if type is not None and artifact.type != type:
1563
+ raise ValueError(
1564
+ f"type {type} specified but this artifact is of type {artifact.type}"
1565
+ )
1566
+ return artifact
1567
+
1568
+ @normalize_exceptions
1569
+ def artifact(self, name: str, type: str | None = None):
1570
+ """Returns a single artifact.
1571
+
1572
+ Args:
1573
+ name: The artifact's name. The name of an artifact resembles a
1574
+ filepath that consists, at a minimum, the name of the project
1575
+ the artifact was logged to, the name of the artifact, and the
1576
+ artifact's version or alias. Optionally append the entity that
1577
+ logged the artifact as a prefix followed by a forward slash.
1578
+ If no entity is specified in the name, the Run or API
1579
+ setting's entity is used.
1580
+ type: The type of artifact to fetch.
1581
+
1582
+ Returns:
1583
+ An `Artifact` object.
1584
+
1585
+ Raises:
1586
+ ValueError: If the artifact name is not specified.
1587
+ ValueError: If the artifact type is specified but does not
1588
+ match the type of the fetched artifact.
1589
+
1590
+ Examples:
1591
+ In the proceeding code snippets "entity", "project", "artifact",
1592
+ "version", and "alias" are placeholders for your W&B entity, name
1593
+ of the project the artifact is in, the name of the artifact,
1594
+ and artifact's version, respectively.
1595
+
1596
+ ```python
1597
+ import wandb
1598
+
1599
+ # Specify the project, artifact's name, and the artifact's alias
1600
+ wandb.Api().artifact(name="project/artifact:alias")
1601
+
1602
+ # Specify the project, artifact's name, and a specific artifact version
1603
+ wandb.Api().artifact(name="project/artifact:version")
1604
+
1605
+ # Specify the entity, project, artifact's name, and the artifact's alias
1606
+ wandb.Api().artifact(name="entity/project/artifact:alias")
1607
+
1608
+ # Specify the entity, project, artifact's name, and a specific artifact version
1609
+ wandb.Api().artifact(name="entity/project/artifact:version")
1610
+ ```
1611
+
1612
+ Note:
1613
+ This method is intended for external use only. Do not call `api.artifact()` within the wandb repository code.
1614
+ """
1615
+ return self._artifact(name=name, type=type, enable_tracking=True)
1616
+
1617
+ @normalize_exceptions
1618
+ def job(self, name: str | None, path: str | None = None) -> public.Job:
1619
+ """Return a `Job` object.
1620
+
1621
+ Args:
1622
+ name: The name of the job.
1623
+ path: The root path to download the job artifact.
1624
+
1625
+ Returns:
1626
+ A `Job` object.
1627
+ """
1628
+ if name is None:
1629
+ raise ValueError("You must specify name= to fetch a job.")
1630
+ elif name.count("/") != 2 or ":" not in name:
1631
+ raise ValueError(
1632
+ "Invalid job specification. A job must be of the form: <entity>/<project>/<job-name>:<alias-or-version>"
1633
+ )
1634
+ return public.Job(self, name, path)
1635
+
1636
+ @normalize_exceptions
1637
+ def list_jobs(self, entity: str, project: str) -> list[dict[str, Any]]:
1638
+ """Return a list of jobs, if any, for the given entity and project.
1639
+
1640
+ Args:
1641
+ entity: The entity for the listed jobs.
1642
+ project: The project for the listed jobs.
1643
+
1644
+ Returns:
1645
+ A list of matching jobs.
1646
+ """
1647
+ if entity is None:
1648
+ raise ValueError("Specify an entity when listing jobs")
1649
+ if project is None:
1650
+ raise ValueError("Specify a project when listing jobs")
1651
+
1652
+ query = gql(
1653
+ """
1654
+ query ArtifactOfType(
1655
+ $entityName: String!,
1656
+ $projectName: String!,
1657
+ $artifactTypeName: String!,
1658
+ ) {
1659
+ project(name: $projectName, entityName: $entityName) {
1660
+ artifactType(name: $artifactTypeName) {
1661
+ artifactCollections {
1662
+ edges {
1663
+ node {
1664
+ artifacts {
1665
+ edges {
1666
+ node {
1667
+ id
1668
+ state
1669
+ aliases {
1670
+ alias
1671
+ }
1672
+ artifactSequence {
1673
+ name
1674
+ }
1675
+ }
1676
+ }
1677
+ }
1678
+ }
1679
+ }
1680
+ }
1681
+ }
1682
+ }
1683
+ }
1684
+ """
1685
+ )
1686
+
1687
+ try:
1688
+ artifact_query = self._client.execute(
1689
+ query,
1690
+ {
1691
+ "projectName": project,
1692
+ "entityName": entity,
1693
+ "artifactTypeName": "job",
1694
+ },
1695
+ )
1696
+
1697
+ if not artifact_query or not artifact_query["project"]:
1698
+ wandb.termerror(
1699
+ f"Project: '{project}' not found in entity: '{entity}' or access denied."
1700
+ )
1701
+ return []
1702
+
1703
+ if artifact_query["project"]["artifactType"] is None:
1704
+ return []
1705
+
1706
+ artifacts = artifact_query["project"]["artifactType"][
1707
+ "artifactCollections"
1708
+ ]["edges"]
1709
+
1710
+ return [x["node"]["artifacts"] for x in artifacts]
1711
+ except requests.exceptions.HTTPError:
1712
+ return False
1713
+
1714
+ @normalize_exceptions
1715
+ def artifact_exists(self, name: str, type: str | None = None) -> bool:
1716
+ """Whether an artifact version exists within the specified project and entity.
1717
+
1718
+ Args:
1719
+ name: The name of artifact. Add the artifact's entity and project
1720
+ as a prefix. Append the version or the alias of the artifact
1721
+ with a colon. If the entity or project is not specified,
1722
+ W&B uses override parameters if populated. Otherwise, the
1723
+ entity is pulled from the user settings and the project is
1724
+ set to "Uncategorized".
1725
+ type: The type of artifact.
1726
+
1727
+ Returns:
1728
+ True if the artifact version exists, False otherwise.
1729
+
1730
+ Examples:
1731
+ In the proceeding code snippets "entity", "project", "artifact",
1732
+ "version", and "alias" are placeholders for your W&B entity, name of
1733
+ the project the artifact is in, the name of the artifact, and
1734
+ artifact's version, respectively.
1735
+
1736
+ ```python
1737
+ import wandb
1738
+
1739
+ wandb.Api().artifact_exists("entity/project/artifact:version")
1740
+ wandb.Api().artifact_exists("entity/project/artifact:alias")
1741
+ ```
1742
+
1743
+ """
1744
+ try:
1745
+ self._artifact(name, type)
1746
+ except wandb.errors.CommError as e:
1747
+ if isinstance(e.exc, requests.Timeout):
1748
+ raise
1749
+ return False
1750
+ return True
1751
+
1752
+ @normalize_exceptions
1753
+ def artifact_collection_exists(self, name: str, type: str) -> bool:
1754
+ """Whether an artifact collection exists within a specified project and entity.
1755
+
1756
+ Args:
1757
+ name: An artifact collection name. Optionally append the
1758
+ entity that logged the artifact as a prefix followed by
1759
+ a forward slash. If entity or project is not specified,
1760
+ infer the collection from the override params if they exist.
1761
+ Otherwise, entity is pulled from the user settings and project
1762
+ will default to "uncategorized".
1763
+ type: The type of artifact collection.
1764
+
1765
+ Returns:
1766
+ True if the artifact collection exists, False otherwise.
1767
+
1768
+ Examples:
1769
+ In the proceeding code snippet "type", and "collection_name" refer to the type
1770
+ of the artifact collection and the name of the collection, respectively.
1771
+
1772
+ ```python
1773
+ import wandb
1774
+
1775
+ wandb.Api.artifact_collection_exists(type="type", name="collection_name")
1776
+ ```
1777
+ """
1778
+ try:
1779
+ self.artifact_collection(type, name)
1780
+ except wandb.errors.CommError as e:
1781
+ if isinstance(e.exc, requests.Timeout):
1782
+ raise
1783
+ return False
1784
+ return True
1785
+
1786
+ @tracked
1787
+ def registries(
1788
+ self,
1789
+ organization: str | None = None,
1790
+ filter: dict[str, Any] | None = None,
1791
+ ) -> Registries:
1792
+ """Returns a lazy iterator of `Registry` objects.
1793
+
1794
+ Use the iterator to search and filter registries, collections,
1795
+ or artifact versions across your organization's registry.
1796
+
1797
+ Args:
1798
+ organization: (str, optional) The organization of the registry to fetch.
1799
+ If not specified, use the organization specified in the user's settings.
1800
+ filter: (dict, optional) MongoDB-style filter to apply to each object in the lazy registry iterator.
1801
+ Fields available to filter for registries are
1802
+ `name`, `description`, `created_at`, `updated_at`.
1803
+ Fields available to filter for collections are
1804
+ `name`, `tag`, `description`, `created_at`, `updated_at`
1805
+ Fields available to filter for versions are
1806
+ `tag`, `alias`, `created_at`, `updated_at`, `metadata`
1807
+
1808
+ Returns:
1809
+ A lazy iterator of `Registry` objects.
1810
+
1811
+ Examples:
1812
+ Find all registries with the names that contain "model"
1813
+
1814
+ ```python
1815
+ import wandb
1816
+
1817
+ api = wandb.Api() # specify an org if your entity belongs to multiple orgs
1818
+ api.registries(filter={"name": {"$regex": "model"}})
1819
+ ```
1820
+
1821
+ Find all collections in the registries with the name "my_collection" and the tag "my_tag"
1822
+
1823
+ ```python
1824
+ api.registries().collections(filter={"name": "my_collection", "tag": "my_tag"})
1825
+ ```
1826
+
1827
+ Find all artifact versions in the registries with a collection name that contains "my_collection" and a version that has the alias "best"
1828
+
1829
+ ```python
1830
+ api.registries().collections(
1831
+ filter={"name": {"$regex": "my_collection"}}
1832
+ ).versions(filter={"alias": "best"})
1833
+ ```
1834
+
1835
+ Find all artifact versions in the registries that contain "model" and have the tag "prod" or alias "best"
1836
+
1837
+ ```python
1838
+ api.registries(filter={"name": {"$regex": "model"}}).versions(
1839
+ filter={"$or": [{"tag": "prod"}, {"alias": "best"}]}
1840
+ )
1841
+ ```
1842
+ """
1843
+ if not InternalApi()._server_supports(ServerFeature.ARTIFACT_REGISTRY_SEARCH):
1844
+ raise RuntimeError(
1845
+ "Registry search API is not enabled on this wandb server version. "
1846
+ "Please upgrade your server version or contact support at support@wandb.com."
1847
+ )
1848
+
1849
+ organization = organization or fetch_org_from_settings_or_entity(
1850
+ self.settings, self.default_entity
1851
+ )
1852
+ return Registries(self.client, organization, filter)
1853
+
1854
+ @tracked
1855
+ def registry(self, name: str, organization: str | None = None) -> Registry:
1856
+ """Return a registry given a registry name.
1857
+
1858
+ Args:
1859
+ name: The name of the registry. This is without the `wandb-registry-`
1860
+ prefix.
1861
+ organization: The organization of the registry.
1862
+ If no organization is set in the settings, the organization will be
1863
+ fetched from the entity if the entity only belongs to one
1864
+ organization.
1865
+
1866
+ Returns:
1867
+ A registry object.
1868
+
1869
+ Examples:
1870
+ Fetch and update a registry
1871
+
1872
+ ```python
1873
+ import wandb
1874
+
1875
+ api = wandb.Api()
1876
+ registry = api.registry(name="my-registry", organization="my-org")
1877
+ registry.description = "This is an updated description"
1878
+ registry.save()
1879
+ ```
1880
+ """
1881
+ if not InternalApi()._server_supports(ServerFeature.ARTIFACT_REGISTRY_SEARCH):
1882
+ raise RuntimeError(
1883
+ "api.registry() is not enabled on this wandb server version. "
1884
+ "Please upgrade your server version or contact support at support@wandb.com."
1885
+ )
1886
+ organization = organization or fetch_org_from_settings_or_entity(
1887
+ self.settings, self.default_entity
1888
+ )
1889
+ org_entity = fetch_org_entity_from_organization(self.client, organization)
1890
+ registry = Registry(self.client, organization, org_entity, name)
1891
+ registry.load()
1892
+ return registry
1893
+
1894
+ @tracked
1895
+ def create_registry(
1896
+ self,
1897
+ name: str,
1898
+ visibility: Literal["organization", "restricted"],
1899
+ organization: str | None = None,
1900
+ description: str | None = None,
1901
+ artifact_types: list[str] | None = None,
1902
+ ) -> Registry:
1903
+ """Create a new registry.
1904
+
1905
+ Args:
1906
+ name: The name of the registry. Name must be unique within the organization.
1907
+ visibility: The visibility of the registry.
1908
+ organization: Anyone in the organization can view this registry. You can
1909
+ edit their roles later from the settings in the UI.
1910
+ restricted: Only invited members via the UI can access this registry.
1911
+ Public sharing is disabled.
1912
+ organization: The organization of the registry.
1913
+ If no organization is set in the settings, the organization will be
1914
+ fetched from the entity if the entity only belongs to one organization.
1915
+ description: The description of the registry.
1916
+ artifact_types: The accepted artifact types of the registry. A type is no
1917
+ more than 128 characters and do not include characters `/` or `:`. If
1918
+ not specified, all types are accepted.
1919
+ Allowed types added to the registry cannot be removed later.
1920
+
1921
+ Returns:
1922
+ A registry object.
1923
+
1924
+ Examples:
1925
+ ```python
1926
+ import wandb
1927
+
1928
+ api = wandb.Api()
1929
+ registry = api.create_registry(
1930
+ name="my-registry",
1931
+ visibility="restricted",
1932
+ organization="my-org",
1933
+ description="This is a test registry",
1934
+ artifact_types=["model"],
1935
+ )
1936
+ ```
1937
+ """
1938
+ if not InternalApi()._server_supports(
1939
+ ServerFeature.INCLUDE_ARTIFACT_TYPES_IN_REGISTRY_CREATION
1940
+ ):
1941
+ raise RuntimeError(
1942
+ "create_registry api is not enabled on this wandb server version. "
1943
+ "Please upgrade your server version or contact support at support@wandb.com."
1944
+ )
1945
+
1946
+ organization = organization or fetch_org_from_settings_or_entity(
1947
+ self.settings, self.default_entity
1948
+ )
1949
+
1950
+ try:
1951
+ existing_registry = self.registry(name=name, organization=organization)
1952
+ except ValueError:
1953
+ existing_registry = None
1954
+ if existing_registry:
1955
+ raise ValueError(
1956
+ f"Registry {name!r} already exists in organization {organization!r},"
1957
+ " please use a different name."
1958
+ )
1959
+
1960
+ return Registry.create(
1961
+ self.client,
1962
+ organization,
1963
+ name,
1964
+ visibility,
1965
+ description,
1966
+ artifact_types,
1967
+ )
1968
+
1969
+ @tracked
1970
+ def integrations(
1971
+ self,
1972
+ entity: str | None = None,
1973
+ *,
1974
+ per_page: int = 50,
1975
+ ) -> Iterator[Integration]:
1976
+ """Return an iterator of all integrations for an entity.
1977
+
1978
+ Args:
1979
+ entity: The entity (e.g. team name) for which to
1980
+ fetch integrations. If not provided, the user's default entity
1981
+ will be used.
1982
+ per_page: Number of integrations to fetch per page.
1983
+ Defaults to 50. Usually there is no reason to change this.
1984
+
1985
+ Yields:
1986
+ Iterator[SlackIntegration | WebhookIntegration]: An iterator of any supported integrations.
1987
+ """
1988
+ from wandb.apis.public.integrations import Integrations
1989
+
1990
+ params = {"entityName": entity or self.default_entity}
1991
+ return Integrations(client=self.client, variables=params, per_page=per_page)
1992
+
1993
+ @tracked
1994
+ def webhook_integrations(
1995
+ self, entity: str | None = None, *, per_page: int = 50
1996
+ ) -> Iterator[WebhookIntegration]:
1997
+ """Returns an iterator of webhook integrations for an entity.
1998
+
1999
+ Args:
2000
+ entity: The entity (e.g. team name) for which to
2001
+ fetch integrations. If not provided, the user's default entity
2002
+ will be used.
2003
+ per_page: Number of integrations to fetch per page.
2004
+ Defaults to 50. Usually there is no reason to change this.
2005
+
2006
+ Yields:
2007
+ Iterator[WebhookIntegration]: An iterator of webhook integrations.
2008
+
2009
+ Examples:
2010
+ Get all registered webhook integrations for the team "my-team":
2011
+
2012
+ ```python
2013
+ import wandb
2014
+
2015
+ api = wandb.Api()
2016
+ webhook_integrations = api.webhook_integrations(entity="my-team")
2017
+ ```
2018
+
2019
+ Find only webhook integrations that post requests to "https://my-fake-url.com":
2020
+
2021
+ ```python
2022
+ webhook_integrations = api.webhook_integrations(entity="my-team")
2023
+ my_webhooks = [
2024
+ ig
2025
+ for ig in webhook_integrations
2026
+ if ig.url_endpoint.startswith("https://my-fake-url.com")
2027
+ ]
2028
+ ```
2029
+ """
2030
+ from wandb.apis.public.integrations import WebhookIntegrations
2031
+
2032
+ params = {"entityName": entity or self.default_entity}
2033
+ return WebhookIntegrations(
2034
+ client=self.client, variables=params, per_page=per_page
2035
+ )
2036
+
2037
+ @tracked
2038
+ def slack_integrations(
2039
+ self, *, entity: str | None = None, per_page: int = 50
2040
+ ) -> Iterator[SlackIntegration]:
2041
+ """Returns an iterator of Slack integrations for an entity.
2042
+
2043
+ Args:
2044
+ entity: The entity (e.g. team name) for which to
2045
+ fetch integrations. If not provided, the user's default entity
2046
+ will be used.
2047
+ per_page: Number of integrations to fetch per page.
2048
+ Defaults to 50. Usually there is no reason to change this.
2049
+
2050
+ Yields:
2051
+ Iterator[SlackIntegration]: An iterator of Slack integrations.
2052
+
2053
+ Examples:
2054
+ Get all registered Slack integrations for the team "my-team":
2055
+
2056
+ ```python
2057
+ import wandb
2058
+
2059
+ api = wandb.Api()
2060
+ slack_integrations = api.slack_integrations(entity="my-team")
2061
+ ```
2062
+
2063
+ Find only Slack integrations that post to channel names starting with "team-alerts-":
2064
+
2065
+ ```python
2066
+ slack_integrations = api.slack_integrations(entity="my-team")
2067
+ team_alert_integrations = [
2068
+ ig
2069
+ for ig in slack_integrations
2070
+ if ig.channel_name.startswith("team-alerts-")
2071
+ ]
2072
+ ```
2073
+ """
2074
+ from wandb.apis.public.integrations import SlackIntegrations
2075
+
2076
+ params = {"entityName": entity or self.default_entity}
2077
+ return SlackIntegrations(
2078
+ client=self.client, variables=params, per_page=per_page
2079
+ )
2080
+
2081
+ def _supports_automation(
2082
+ self,
2083
+ *,
2084
+ event: EventType | None = None,
2085
+ action: ActionType | None = None,
2086
+ ) -> bool:
2087
+ """Returns whether the server recognizes the automation event and/or action."""
2088
+ from wandb.automations._utils import (
2089
+ ALWAYS_SUPPORTED_ACTIONS,
2090
+ ALWAYS_SUPPORTED_EVENTS,
2091
+ )
2092
+
2093
+ api = InternalApi()
2094
+ supports_event = (
2095
+ (event is None)
2096
+ or (event in ALWAYS_SUPPORTED_EVENTS)
2097
+ or api._server_supports(f"AUTOMATION_EVENT_{event.value}")
2098
+ )
2099
+ supports_action = (
2100
+ (action is None)
2101
+ or (action in ALWAYS_SUPPORTED_ACTIONS)
2102
+ or api._server_supports(f"AUTOMATION_ACTION_{action.value}")
2103
+ )
2104
+ return supports_event and supports_action
2105
+
2106
+ def _omitted_automation_fragments(self) -> set[str]:
2107
+ """Returns the names of unsupported automation-related fragments.
2108
+
2109
+ Older servers won't recognize newer GraphQL types, so a valid request may
2110
+ unnecessarily error out because it won't recognize fragments defined on those types.
2111
+
2112
+ So e.g. if a server does not support `NO_OP` action types, then the following need to be
2113
+ removed from the body of the GraphQL request:
2114
+
2115
+ - Fragment definition:
2116
+ ```
2117
+ fragment NoOpActionFields on NoOpTriggeredAction {
2118
+ noOp
2119
+ }
2120
+ ```
2121
+
2122
+ - Fragment spread in selection set:
2123
+ ```
2124
+ {
2125
+ ...NoOpActionFields
2126
+ # ... other fields ...
2127
+ }
2128
+ ```
2129
+ """
2130
+ from wandb.automations import ActionType
2131
+ from wandb.automations._generated import (
2132
+ GenericWebhookActionFields,
2133
+ NoOpActionFields,
2134
+ NotificationActionFields,
2135
+ QueueJobActionFields,
2136
+ )
2137
+
2138
+ # Note: we can't currently define this as a constant outside the method
2139
+ # and still keep it nearby in this module, because it relies on pydantic v2-only imports
2140
+ fragment_names: dict[ActionType, str] = {
2141
+ ActionType.NO_OP: nameof(NoOpActionFields),
2142
+ ActionType.QUEUE_JOB: nameof(QueueJobActionFields),
2143
+ ActionType.NOTIFICATION: nameof(NotificationActionFields),
2144
+ ActionType.GENERIC_WEBHOOK: nameof(GenericWebhookActionFields),
2145
+ }
2146
+
2147
+ return set(
2148
+ name
2149
+ for action in ActionType
2150
+ if (not self._supports_automation(action=action))
2151
+ and (name := fragment_names.get(action))
2152
+ )
2153
+
2154
+ @tracked
2155
+ def automation(
2156
+ self,
2157
+ name: str,
2158
+ *,
2159
+ entity: str | None = None,
2160
+ ) -> Automation:
2161
+ """Returns the only Automation matching the parameters.
2162
+
2163
+ Args:
2164
+ name: The name of the automation to fetch.
2165
+ entity: The entity to fetch the automation for.
2166
+
2167
+ Raises:
2168
+ ValueError: If zero or multiple Automations match the search criteria.
2169
+
2170
+ Examples:
2171
+ Get an existing automation named "my-automation":
2172
+
2173
+ ```python
2174
+ import wandb
2175
+
2176
+ api = wandb.Api()
2177
+ automation = api.automation(name="my-automation")
2178
+ ```
2179
+
2180
+ Get an existing automation named "other-automation", from the entity "my-team":
2181
+
2182
+ ```python
2183
+ automation = api.automation(name="other-automation", entity="my-team")
2184
+ ```
2185
+ """
2186
+ return one(
2187
+ self.automations(entity=entity, name=name),
2188
+ too_short=ValueError("No automations found"),
2189
+ too_long=ValueError("Multiple automations found"),
2190
+ )
2191
+
2192
+ @tracked
2193
+ def automations(
2194
+ self,
2195
+ entity: str | None = None,
2196
+ *,
2197
+ name: str | None = None,
2198
+ per_page: int = 50,
2199
+ ) -> Iterator[Automation]:
2200
+ """Returns an iterator over all Automations that match the given parameters.
2201
+
2202
+ If no parameters are provided, the returned iterator will contain all
2203
+ Automations that the user has access to.
2204
+
2205
+ Args:
2206
+ entity: The entity to fetch the automations for.
2207
+ name: The name of the automation to fetch.
2208
+ per_page: The number of automations to fetch per page.
2209
+ Defaults to 50. Usually there is no reason to change this.
2210
+
2211
+ Returns:
2212
+ A list of automations.
2213
+
2214
+ Examples:
2215
+ Fetch all existing automations for the entity "my-team":
2216
+
2217
+ ```python
2218
+ import wandb
2219
+
2220
+ api = wandb.Api()
2221
+ automations = api.automations(entity="my-team")
2222
+ ```
2223
+ """
2224
+ from wandb.apis.public.automations import Automations
2225
+ from wandb.automations._generated import (
2226
+ GET_AUTOMATIONS_BY_ENTITY_GQL,
2227
+ GET_AUTOMATIONS_GQL,
2228
+ )
2229
+
2230
+ # For now, we need to use different queries depending on whether entity is given
2231
+ variables = {"entityName": entity}
2232
+ if entity is None:
2233
+ gql_str = GET_AUTOMATIONS_GQL # Automations for viewer
2234
+ else:
2235
+ gql_str = GET_AUTOMATIONS_BY_ENTITY_GQL # Automations for entity
2236
+
2237
+ # If needed, rewrite the GraphQL field selection set to omit unsupported fields/fragments/types
2238
+ omit_fragments = self._omitted_automation_fragments()
2239
+ query = gql_compat(gql_str, omit_fragments=omit_fragments)
2240
+ iterator = Automations(
2241
+ client=self.client, variables=variables, per_page=per_page, _query=query
2242
+ )
2243
+
2244
+ # FIXME: this is crude, move this client-side filtering logic into backend
2245
+ if name is not None:
2246
+ iterator = filter(lambda x: x.name == name, iterator)
2247
+ yield from iterator
2248
+
2249
+ @normalize_exceptions
2250
+ @tracked
2251
+ def create_automation(
2252
+ self,
2253
+ obj: NewAutomation,
2254
+ *,
2255
+ fetch_existing: bool = False,
2256
+ **kwargs: Unpack[WriteAutomationsKwargs],
2257
+ ) -> Automation:
2258
+ """Create a new Automation.
2259
+
2260
+ Args:
2261
+ obj:
2262
+ The automation to create.
2263
+ fetch_existing:
2264
+ If True, and a conflicting automation already exists, attempt
2265
+ to fetch the existing automation instead of raising an error.
2266
+ **kwargs:
2267
+ Any additional values to assign to the automation before
2268
+ creating it. If given, these will override any values that may
2269
+ already be set on the automation:
2270
+ - `name`: The name of the automation.
2271
+ - `description`: The description of the automation.
2272
+ - `enabled`: Whether the automation is enabled.
2273
+ - `scope`: The scope of the automation.
2274
+ - `event`: The event that triggers the automation.
2275
+ - `action`: The action that is triggered by the automation.
2276
+
2277
+ Returns:
2278
+ The saved Automation.
2279
+
2280
+ Examples:
2281
+ Create a new automation named "my-automation" that sends a Slack notification
2282
+ when a run within a specific project logs a metric exceeding a custom threshold:
2283
+
2284
+ ```python
2285
+ import wandb
2286
+ from wandb.automations import OnRunMetric, RunEvent, SendNotification
2287
+
2288
+ api = wandb.Api()
2289
+
2290
+ project = api.project("my-project", entity="my-team")
2291
+
2292
+ # Use the first Slack integration for the team
2293
+ slack_hook = next(api.slack_integrations(entity="my-team"))
2294
+
2295
+ event = OnRunMetric(
2296
+ scope=project,
2297
+ filter=RunEvent.metric("custom-metric") > 10,
2298
+ )
2299
+ action = SendNotification.from_integration(slack_hook)
2300
+
2301
+ automation = api.create_automation(
2302
+ event >> action,
2303
+ name="my-automation",
2304
+ description="Send a Slack message whenever 'custom-metric' exceeds 10.",
2305
+ )
2306
+ ```
2307
+ """
2308
+ from wandb.automations import Automation
2309
+ from wandb.automations._generated import CREATE_AUTOMATION_GQL, CreateAutomation
2310
+ from wandb.automations._utils import prepare_to_create
2311
+
2312
+ gql_input = prepare_to_create(obj, **kwargs)
2313
+
2314
+ if not self._supports_automation(
2315
+ event=(event := gql_input.triggering_event_type),
2316
+ action=(action := gql_input.triggered_action_type),
2317
+ ):
2318
+ raise ValueError(
2319
+ f"Automation event or action ({event!r} -> {action!r}) "
2320
+ "is not supported on this wandb server version. "
2321
+ "Please upgrade your server version, or contact support at "
2322
+ "support@wandb.com."
2323
+ )
2324
+
2325
+ # If needed, rewrite the GraphQL field selection set to omit unsupported fields/fragments/types
2326
+ omit_fragments = self._omitted_automation_fragments()
2327
+ mutation = gql_compat(CREATE_AUTOMATION_GQL, omit_fragments=omit_fragments)
2328
+ variables = {"params": gql_input.model_dump(exclude_none=True)}
2329
+
2330
+ name = gql_input.name
2331
+ try:
2332
+ data = self.client.execute(mutation, variable_values=variables)
2333
+ except requests.HTTPError as e:
2334
+ status = HTTPStatus(e.response.status_code)
2335
+ if status is HTTPStatus.CONFLICT: # 409
2336
+ if fetch_existing:
2337
+ wandb.termlog(f"Automation {name!r} exists. Fetching it instead.")
2338
+ return self.automation(name=name)
2339
+
2340
+ raise ValueError(
2341
+ f"Automation {name!r} exists. Unable to create another with the same name."
2342
+ ) from None
2343
+ raise
2344
+
2345
+ try:
2346
+ result = CreateAutomation.model_validate(data).result
2347
+ except ValidationError as e:
2348
+ msg = f"Invalid response while creating automation {name!r}"
2349
+ raise RuntimeError(msg) from e
2350
+
2351
+ if (result is None) or (result.trigger is None):
2352
+ msg = f"Empty response while creating automation {name!r}"
2353
+ raise RuntimeError(msg)
2354
+
2355
+ return Automation.model_validate(result.trigger)
2356
+
2357
+ @normalize_exceptions
2358
+ @tracked
2359
+ def update_automation(
2360
+ self,
2361
+ obj: Automation,
2362
+ *,
2363
+ create_missing: bool = False,
2364
+ **kwargs: Unpack[WriteAutomationsKwargs],
2365
+ ) -> Automation:
2366
+ """Update an existing automation.
2367
+
2368
+ Args:
2369
+ obj: The automation to update. Must be an existing automation.
2370
+ create_missing (bool):
2371
+ If True, and the automation does not exist, create it.
2372
+ **kwargs:
2373
+ Any additional values to assign to the automation before
2374
+ updating it. If given, these will override any values that may
2375
+ already be set on the automation:
2376
+ - `name`: The name of the automation.
2377
+ - `description`: The description of the automation.
2378
+ - `enabled`: Whether the automation is enabled.
2379
+ - `scope`: The scope of the automation.
2380
+ - `event`: The event that triggers the automation.
2381
+ - `action`: The action that is triggered by the automation.
2382
+
2383
+ Returns:
2384
+ The updated automation.
2385
+
2386
+ Examples:
2387
+ Disable and edit the description of an existing automation ("my-automation"):
2388
+
2389
+ ```python
2390
+ import wandb
2391
+
2392
+ api = wandb.Api()
2393
+
2394
+ automation = api.automation(name="my-automation")
2395
+ automation.enabled = False
2396
+ automation.description = "Kept for reference, but no longer used."
2397
+
2398
+ updated_automation = api.update_automation(automation)
2399
+ ```
2400
+
2401
+ OR
2402
+
2403
+ ```python
2404
+ import wandb
2405
+
2406
+ api = wandb.Api()
2407
+
2408
+ automation = api.automation(name="my-automation")
2409
+
2410
+ updated_automation = api.update_automation(
2411
+ automation,
2412
+ enabled=False,
2413
+ description="Kept for reference, but no longer used.",
2414
+ )
2415
+ ```
2416
+ """
2417
+ from wandb.automations import ActionType, Automation
2418
+ from wandb.automations._generated import UPDATE_AUTOMATION_GQL, UpdateAutomation
2419
+ from wandb.automations._utils import prepare_to_update
2420
+
2421
+ # Check if the server even supports updating automations.
2422
+ #
2423
+ # NOTE: Unfortunately, there is no current server feature flag for this. As a workaround,
2424
+ # we check whether the server supports the NO_OP action, which is a reasonably safe proxy
2425
+ # for whether it supports updating automations.
2426
+ if not self._supports_automation(action=ActionType.NO_OP):
2427
+ raise RuntimeError(
2428
+ "Updating existing automations is not enabled on this wandb server version. "
2429
+ "Please upgrade your server version, or contact support at support@wandb.com."
2430
+ )
2431
+
2432
+ gql_input = prepare_to_update(obj, **kwargs)
2433
+
2434
+ if not self._supports_automation(
2435
+ event=(event := gql_input.triggering_event_type),
2436
+ action=(action := gql_input.triggered_action_type),
2437
+ ):
2438
+ raise ValueError(
2439
+ f"Automation event or action ({event.value} -> {action.value}) "
2440
+ "is not supported on this wandb server version. "
2441
+ "Please upgrade your server version, or contact support at "
2442
+ "support@wandb.com."
2443
+ )
2444
+
2445
+ # If needed, rewrite the GraphQL field selection set to omit unsupported fields/fragments/types
2446
+ omit_fragments = self._omitted_automation_fragments()
2447
+ mutation = gql_compat(UPDATE_AUTOMATION_GQL, omit_fragments=omit_fragments)
2448
+ variables = {"params": gql_input.model_dump(exclude_none=True)}
2449
+
2450
+ name = gql_input.name
2451
+ try:
2452
+ data = self.client.execute(mutation, variable_values=variables)
2453
+ except requests.HTTPError as e:
2454
+ status = HTTPStatus(e.response.status_code)
2455
+ if status is HTTPStatus.NOT_FOUND: # 404
2456
+ if create_missing:
2457
+ wandb.termlog(f"Automation {name!r} not found. Creating it.")
2458
+ return self.create_automation(obj)
2459
+
2460
+ raise ValueError(
2461
+ f"Automation {name!r} not found. Unable to edit it."
2462
+ ) from e
2463
+
2464
+ # Not a (known) recoverable HTTP error
2465
+ wandb.termerror(f"Got response status {status!r}: {e.response.text!r}")
2466
+ raise
2467
+
2468
+ try:
2469
+ result = UpdateAutomation.model_validate(data).result
2470
+ except ValidationError as e:
2471
+ msg = f"Invalid response while updating automation {name!r}"
2472
+ raise RuntimeError(msg) from e
2473
+
2474
+ if (result is None) or (result.trigger is None):
2475
+ msg = f"Empty response while updating automation {name!r}"
2476
+ raise RuntimeError(msg)
2477
+
2478
+ return Automation.model_validate(result.trigger)
2479
+
2480
+ @normalize_exceptions
2481
+ @tracked
2482
+ def delete_automation(self, obj: Automation | str) -> Literal[True]:
2483
+ """Delete an automation.
2484
+
2485
+ Args:
2486
+ obj: The automation to delete, or its ID.
2487
+
2488
+ Returns:
2489
+ True if the automation was deleted successfully.
2490
+ """
2491
+ from wandb.automations._generated import DELETE_AUTOMATION_GQL, DeleteAutomation
2492
+ from wandb.automations._utils import extract_id
2493
+
2494
+ id_ = extract_id(obj)
2495
+ mutation = gql(DELETE_AUTOMATION_GQL)
2496
+ variables = {"id": id_}
2497
+
2498
+ data = self.client.execute(mutation, variable_values=variables)
2499
+
2500
+ try:
2501
+ result = DeleteAutomation.model_validate(data).result
2502
+ except ValidationError as e:
2503
+ msg = f"Invalid response while deleting automation {id_!r}"
2504
+ raise RuntimeError(msg) from e
2505
+
2506
+ if result is None:
2507
+ msg = f"Empty response while deleting automation {id_!r}"
2508
+ raise RuntimeError(msg)
2509
+
2510
+ if not result.success:
2511
+ raise RuntimeError(f"Failed to delete automation: {id_!r}")
2512
+
2513
+ return result.success