datalab-api 0.2.10__tar.gz → 0.2.11__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datalab-api
3
- Version: 0.2.10
3
+ Version: 0.2.11
4
4
  Summary: A Python API for instances of the datalab data management platform (https://github.com/datalab-org/datalab).
5
5
  Author-email: Matthew Evans <matthew@ml-evs.science>
6
6
  License: MIT
@@ -153,10 +153,10 @@ class DatalabClient(BaseDatalabClient):
153
153
 
154
154
  if collection_id is not None:
155
155
  try:
156
- collection_immutable_id = self.get_collection(collection_id)["immutable_id"]
156
+ collection_immutable_id = self.get_collection(collection_id)[0]["immutable_id"]
157
157
  except RuntimeError:
158
158
  self.create_collection(collection_id)
159
- collection_immutable_id = self.get_collection(collection_id)["immutable_id"]
159
+ collection_immutable_id = self.get_collection(collection_id)[0]["immutable_id"]
160
160
  new_item["collections"] = new_item.get("collections", [])
161
161
  new_item["collections"].append({"immutable_id": collection_immutable_id})
162
162
 
@@ -173,6 +173,10 @@ class DatalabClient(BaseDatalabClient):
173
173
  f"Item {item_id=} already exists at {create_item_url}: {created_item['status']!r}."
174
174
  )
175
175
  if created_item["status"] != "success":
176
+ if "DuplicateKeyError" in created_item["message"]:
177
+ raise DuplicateItemError(
178
+ f"Item {item_id=} already exists at {create_item_url}: {created_item['status']!r}."
179
+ )
176
180
  raise RuntimeError(f"Failed to create item at {create_item_url}: {created_item}.")
177
181
  return created_item["sample_list_entry"]
178
182
 
@@ -468,14 +472,15 @@ class DatalabClient(BaseDatalabClient):
468
472
 
469
473
  return resp.json()["new_block_data"]
470
474
 
471
- def get_collection(self, collection_id: str) -> dict[str, Any]:
475
+ def get_collection(self, collection_id: str) -> tuple[dict[str, Any], list[dict[str, Any]]]:
472
476
  """Get a collection with a given ID.
473
477
 
474
478
  Parameters:
475
479
  collection_id: The ID of the collection to search for.
476
480
 
477
481
  Returns:
478
- A dictionary of collection data for the collection with the given ID.
482
+ A dictionary of collection data for the collection with the given ID,
483
+ and a list of the member items.
479
484
 
480
485
  """
481
486
  collection_url = f"{self.datalab_api_url}/collections/{collection_id}"
@@ -489,7 +494,7 @@ class DatalabClient(BaseDatalabClient):
489
494
  raise RuntimeError(
490
495
  f"Failed to get collection at {collection_url}: {collection['status']!r}."
491
496
  )
492
- return collection["data"]
497
+ return collection["data"], collection["child_items"]
493
498
 
494
499
  def create_collection(
495
500
  self, collection_id: str, collection_data: dict | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datalab-api
3
- Version: 0.2.10
3
+ Version: 0.2.11
4
4
  Summary: A Python API for instances of the datalab data management platform (https://github.com/datalab-org/datalab).
5
5
  Author-email: Matthew Evans <matthew@ml-evs.science>
6
6
  License: MIT
@@ -55,3 +55,27 @@ def test_sample_list(fake_samples_json, fake_info_json, fake_sample_json, fake_b
55
55
  sample = client.get_item("KUVEKJ", display=True)
56
56
  assert fake_item_api.called
57
57
  assert sample["item_id"] == "KUVEKJ"
58
+
59
+
60
+ @respx.mock
61
+ def test_collection_get(fake_info_json, fake_block_info_json, fake_collection_json):
62
+ fake_api = respx.get("https://api.datalab.industries/").mock(
63
+ return_value=Response(200, content="<!doctype html></html>")
64
+ )
65
+ fake_info_api = respx.get("https://api.datalab.industries/info").mock(
66
+ return_value=Response(200, json=fake_info_json)
67
+ )
68
+ fake_block_info_api = respx.get("https://api.datalab.industries/info/blocks").mock(
69
+ return_value=Response(200, json=fake_block_info_json)
70
+ )
71
+
72
+ fake_collection_api = respx.get(
73
+ "https://api.datalab.industries/collections/test_collection"
74
+ ).mock(return_value=Response(200, json=fake_collection_json))
75
+
76
+ with DatalabClient("https://api.datalab.industries") as client:
77
+ collection, children = client.get_collection("test_collection")
78
+ assert fake_api.called
79
+ assert fake_info_api.called
80
+ assert fake_block_info_api.called
81
+ assert fake_collection_api.called
File without changes
File without changes
File without changes