datalab-api 0.2.11__tar.gz → 0.2.13__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,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datalab-api
3
- Version: 0.2.11
3
+ Version: 0.2.13
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
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: homepage, https://github.com/datalab-org/datalab-api
8
8
  Project-URL: repository, https://github.com/datalab-org/datalab-api
9
9
  Project-URL: documentation, https://datalab-python-api.readthedocs.io
@@ -7,7 +7,7 @@ name = "datalab-api"
7
7
  readme = "README.md"
8
8
  description = "A Python API for instances of the datalab data management platform (https://github.com/datalab-org/datalab)."
9
9
  keywords = []
10
- license = { text = "MIT" }
10
+ license = "MIT"
11
11
  authors = [{ name = "Matthew Evans", email = "matthew@ml-evs.science" }]
12
12
  dynamic = ["version"]
13
13
  classifiers = [
@@ -83,9 +83,17 @@ class DatalabClient(BaseDatalabClient):
83
83
  A list of items of the given type.
84
84
 
85
85
  """
86
+ endpoint_type_map = {
87
+ "cells": "samples",
88
+ "samples": "samples",
89
+ "starting_materials": "starting-materials",
90
+ "equipment": "equipment",
91
+ }
92
+
86
93
  if item_type is None:
87
94
  item_type = "samples"
88
- items_url = f"{self.datalab_api_url}/{item_type}"
95
+
96
+ items_url = f"{self.datalab_api_url}/{endpoint_type_map.get(item_type, item_type.replace('_', '-'))}"
89
97
  items_resp = self.session.get(items_url, follow_redirects=True)
90
98
  if items_resp.status_code != 200:
91
99
  raise RuntimeError(
@@ -94,7 +102,15 @@ class DatalabClient(BaseDatalabClient):
94
102
  items = items_resp.json()
95
103
  if items["status"] != "success":
96
104
  raise RuntimeError(f"Failed to list items at {items_url}: {items['status']!r}.")
97
- return items[item_type]
105
+
106
+ if item_type in items:
107
+ # Old approach
108
+ return items[item_type]
109
+ if "items" in items:
110
+ return items["items"]
111
+
112
+ else:
113
+ return items
98
114
 
99
115
  def search_items(
100
116
  self, query: str, item_types: Iterable[str] | str = ("samples", "cells")
@@ -238,9 +254,11 @@ class DatalabClient(BaseDatalabClient):
238
254
  raise ValueError("Must provide only one of `item_id` or `refcode`.")
239
255
 
240
256
  if refcode is not None:
241
- raise NotImplementedError("Searching by `refcode` is not yet implemented.")
257
+ item_url = f"{self.datalab_api_url}/items/{refcode}"
258
+
259
+ else:
260
+ item_url = f"{self.datalab_api_url}/get-item-data/{item_id}"
242
261
 
243
- item_url = f"{self.datalab_api_url}/get-item-data/{item_id}"
244
262
  item_resp = self.session.get(item_url, follow_redirects=True)
245
263
 
246
264
  if item_resp.status_code != 200:
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datalab-api
3
- Version: 0.2.11
3
+ Version: 0.2.13
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
- License: MIT
6
+ License-Expression: MIT
7
7
  Project-URL: homepage, https://github.com/datalab-org/datalab-api
8
8
  Project-URL: repository, https://github.com/datalab-org/datalab-api
9
9
  Project-URL: documentation, https://datalab-python-api.readthedocs.io
File without changes
File without changes
File without changes