datalab-api 0.2.4__tar.gz → 0.2.6__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.
- {datalab_api-0.2.4/src/datalab_api.egg-info → datalab_api-0.2.6}/PKG-INFO +4 -4
- {datalab_api-0.2.4 → datalab_api-0.2.6}/README.md +3 -3
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api/__init__.py +21 -16
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api/_base.py +2 -2
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api/helpers.py +6 -4
- {datalab_api-0.2.4 → datalab_api-0.2.6/src/datalab_api.egg-info}/PKG-INFO +4 -4
- {datalab_api-0.2.4 → datalab_api-0.2.6}/LICENSE +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/pyproject.toml +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/setup.cfg +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api/cli.py +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api.egg-info/SOURCES.txt +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api.egg-info/dependency_links.txt +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api.egg-info/entry_points.txt +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api.egg-info/requires.txt +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/src/datalab_api.egg-info/top_level.txt +0 -0
- {datalab_api-0.2.4 → datalab_api-0.2.6}/tests/test_client.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datalab-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: A Python API for instances of the datalab data management platform (https://github.com/the-grey-group/datalab).
|
|
5
5
|
Author-email: Matthew Evans <matthew@ml-evs.science>
|
|
6
6
|
License: MIT
|
|
@@ -99,7 +99,7 @@ You can generate one for your account for a given *datalab* instance by visiting
|
|
|
99
99
|
|
|
100
100
|
This API key can be set via the environment variable `DATALAB_API_KEY`.
|
|
101
101
|
To suport the use case of needing to interact with multiple datalab instances, the client will also check prefixed environment variables that use the [`IDENTIFIER_PREFIX` of the chosen datalab instance](https://the-datalab.readthedocs.io/en/latest/config/#mandatory-settings), e.g., `GREY_DATALAB_API_KEY` or `PUBLIC_DATALAB_API_KEY`.
|
|
102
|
-
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://
|
|
102
|
+
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://demo.datalab-org.io)).
|
|
103
103
|
|
|
104
104
|
### Python API
|
|
105
105
|
|
|
@@ -108,7 +108,7 @@ This package implements basic functionality for displaying and manipulating entr
|
|
|
108
108
|
```python
|
|
109
109
|
from datalab_api import DatalabClient
|
|
110
110
|
|
|
111
|
-
with DatalabClient("https://
|
|
111
|
+
with DatalabClient("https://demo-api.datalab-org.io") as client:
|
|
112
112
|
|
|
113
113
|
# List all items of a given type
|
|
114
114
|
items = client.get_items()
|
|
@@ -167,7 +167,7 @@ datalab > help get
|
|
|
167
167
|
│ --help Show this message and exit. │
|
|
168
168
|
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
169
169
|
|
|
170
|
-
datalab > get samples api.
|
|
170
|
+
datalab > get samples demo-api.datalab-org.io --page-limit 2
|
|
171
171
|
/samples/
|
|
172
172
|
┏━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
|
|
173
173
|
┃ type ┃ ID ┃ refcode ┃ name ┃ nblocks ┃ collections ┃ creators ┃
|
|
@@ -53,7 +53,7 @@ You can generate one for your account for a given *datalab* instance by visiting
|
|
|
53
53
|
|
|
54
54
|
This API key can be set via the environment variable `DATALAB_API_KEY`.
|
|
55
55
|
To suport the use case of needing to interact with multiple datalab instances, the client will also check prefixed environment variables that use the [`IDENTIFIER_PREFIX` of the chosen datalab instance](https://the-datalab.readthedocs.io/en/latest/config/#mandatory-settings), e.g., `GREY_DATALAB_API_KEY` or `PUBLIC_DATALAB_API_KEY`.
|
|
56
|
-
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://
|
|
56
|
+
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://demo.datalab-org.io)).
|
|
57
57
|
|
|
58
58
|
### Python API
|
|
59
59
|
|
|
@@ -62,7 +62,7 @@ This package implements basic functionality for displaying and manipulating entr
|
|
|
62
62
|
```python
|
|
63
63
|
from datalab_api import DatalabClient
|
|
64
64
|
|
|
65
|
-
with DatalabClient("https://
|
|
65
|
+
with DatalabClient("https://demo-api.datalab-org.io") as client:
|
|
66
66
|
|
|
67
67
|
# List all items of a given type
|
|
68
68
|
items = client.get_items()
|
|
@@ -121,7 +121,7 @@ datalab > help get
|
|
|
121
121
|
│ --help Show this message and exit. │
|
|
122
122
|
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
123
123
|
|
|
124
|
-
datalab > get samples api.
|
|
124
|
+
datalab > get samples demo-api.datalab-org.io --page-limit 2
|
|
125
125
|
/samples/
|
|
126
126
|
┏━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
|
|
127
127
|
┃ type ┃ ID ┃ refcode ┃ name ┃ nblocks ┃ collections ┃ creators ┃
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
import warnings
|
|
2
4
|
from collections.abc import Iterable
|
|
3
5
|
from pathlib import Path
|
|
@@ -19,7 +21,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
19
21
|
amenable for use as a context manager, e.g.,
|
|
20
22
|
|
|
21
23
|
```python
|
|
22
|
-
with DatalabClient("https://
|
|
24
|
+
with DatalabClient("https://demo-api.datalab-org.io") as client:
|
|
23
25
|
client.get_items()
|
|
24
26
|
```
|
|
25
27
|
|
|
@@ -46,7 +48,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
46
48
|
)
|
|
47
49
|
return user_resp.json()
|
|
48
50
|
|
|
49
|
-
def get_items(self, item_type:
|
|
51
|
+
def get_items(self, item_type: str | None = "samples") -> list[dict[str, Any]]:
|
|
50
52
|
"""List items of the given type available to the authenticated user.
|
|
51
53
|
|
|
52
54
|
Parameters:
|
|
@@ -71,7 +73,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
71
73
|
return items[item_type]
|
|
72
74
|
|
|
73
75
|
def search_items(
|
|
74
|
-
self, query: str, item_types:
|
|
76
|
+
self, query: str, item_types: Iterable[str] | str = ("samples", "cells")
|
|
75
77
|
) -> list[dict[str, Any]]:
|
|
76
78
|
"""Search for items of the given types that match the query.
|
|
77
79
|
|
|
@@ -102,15 +104,15 @@ class DatalabClient(BaseDatalabClient):
|
|
|
102
104
|
|
|
103
105
|
def create_item(
|
|
104
106
|
self,
|
|
105
|
-
item_id: str,
|
|
106
|
-
item_type: str,
|
|
107
|
-
item_data:
|
|
108
|
-
collection_id:
|
|
107
|
+
item_id: str | None = None,
|
|
108
|
+
item_type: str = "samples",
|
|
109
|
+
item_data: dict[str, Any] | None = None,
|
|
110
|
+
collection_id: str | None = None,
|
|
109
111
|
) -> dict[str, Any]:
|
|
110
112
|
"""Create an item with a given ID and item data.
|
|
111
113
|
|
|
112
114
|
Parameters:
|
|
113
|
-
item_id: The ID of the item to create.
|
|
115
|
+
item_id: The ID of the item to create, if set to `None`, the server will generate one.
|
|
114
116
|
item_type: The type of item to create, e.g., 'samples', 'cells'.
|
|
115
117
|
item_data: The data for the item.
|
|
116
118
|
collection_id: The ID of the collection to add the item to (optional).
|
|
@@ -122,6 +124,9 @@ class DatalabClient(BaseDatalabClient):
|
|
|
122
124
|
new_item = item_data
|
|
123
125
|
new_item.update({"item_id": item_id, "type": item_type})
|
|
124
126
|
|
|
127
|
+
if new_item["item_id"] is None:
|
|
128
|
+
new_item.pop("item_id")
|
|
129
|
+
|
|
125
130
|
if collection_id is not None:
|
|
126
131
|
try:
|
|
127
132
|
collection_immutable_id = self.get_collection(collection_id)["immutable_id"]
|
|
@@ -133,7 +138,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
133
138
|
create_item_url = f"{self.datalab_api_url}/new-sample/"
|
|
134
139
|
create_item_resp = self.session.post(
|
|
135
140
|
create_item_url,
|
|
136
|
-
json=new_item,
|
|
141
|
+
json={"new_sample_data": new_item, "generate_id_automatically": item_id is None},
|
|
137
142
|
follow_redirects=True,
|
|
138
143
|
)
|
|
139
144
|
try:
|
|
@@ -182,8 +187,8 @@ class DatalabClient(BaseDatalabClient):
|
|
|
182
187
|
|
|
183
188
|
def get_item(
|
|
184
189
|
self,
|
|
185
|
-
item_id:
|
|
186
|
-
refcode:
|
|
190
|
+
item_id: str | None = None,
|
|
191
|
+
refcode: str | None = None,
|
|
187
192
|
load_blocks: bool = False,
|
|
188
193
|
) -> dict[str, Any]:
|
|
189
194
|
"""Get an item with a given ID or refcode.
|
|
@@ -287,7 +292,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
287
292
|
raise RuntimeError(f"Failed to get block at {block_url}: {block['status']!r}.")
|
|
288
293
|
return block["new_block_data"]
|
|
289
294
|
|
|
290
|
-
def upload_file(self, item_id: str, file_path:
|
|
295
|
+
def upload_file(self, item_id: str, file_path: Path | str) -> dict[str, Any]:
|
|
291
296
|
"""Upload a file to an item with a given ID.
|
|
292
297
|
|
|
293
298
|
Parameters:
|
|
@@ -327,8 +332,8 @@ class DatalabClient(BaseDatalabClient):
|
|
|
327
332
|
self,
|
|
328
333
|
item_id: str,
|
|
329
334
|
block_type: str,
|
|
330
|
-
file_ids:
|
|
331
|
-
file_paths:
|
|
335
|
+
file_ids: str | list[str] | None = None,
|
|
336
|
+
file_paths: Path | list[Path] | None = None,
|
|
332
337
|
) -> dict[str, Any]:
|
|
333
338
|
"""Creates a data block for an item with the given block type and file ID.
|
|
334
339
|
|
|
@@ -385,7 +390,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
385
390
|
return block_data
|
|
386
391
|
|
|
387
392
|
def _update_data_block(
|
|
388
|
-
self, block_type: str, block_data: dict, file_ids:
|
|
393
|
+
self, block_type: str, block_data: dict, file_ids: str | list[str] | None = None
|
|
389
394
|
) -> dict[str, Any]:
|
|
390
395
|
"""Attaches files to blocks: should only be used via wrapper methods."""
|
|
391
396
|
if file_ids and isinstance(file_ids, str):
|
|
@@ -436,7 +441,7 @@ class DatalabClient(BaseDatalabClient):
|
|
|
436
441
|
return collection["data"]
|
|
437
442
|
|
|
438
443
|
def create_collection(
|
|
439
|
-
self, collection_id: str, collection_data:
|
|
444
|
+
self, collection_id: str, collection_data: dict | None = None
|
|
440
445
|
) -> dict[str, Any]:
|
|
441
446
|
"""Create a collection with a given ID and collection data.
|
|
442
447
|
|
|
@@ -113,8 +113,8 @@ class BaseDatalabClient(metaclass=AutoPrettyPrint):
|
|
|
113
113
|
Parameters:
|
|
114
114
|
datalab_api_url: The URL of the Datalab API.
|
|
115
115
|
TODO: If the URL of a datalab *UI* is provided, a request will be made to attempt
|
|
116
|
-
to resolve the underlying API URL (e.g., `https://
|
|
117
|
-
will 'redirect' to `https://
|
|
116
|
+
to resolve the underlying API URL (e.g., `https://demo-api.datalab-org.io`
|
|
117
|
+
will 'redirect' to `https://demo-api.datalab-org.io`).
|
|
118
118
|
log_level: The logging level to use for the client. Defaults to "WARNING".
|
|
119
119
|
|
|
120
120
|
|
|
@@ -31,13 +31,11 @@ def import_cheminventory(filename: Path, client: DatalabClient):
|
|
|
31
31
|
inventory_df["item_id"] = inventory_df["Barcode"]
|
|
32
32
|
# Fill missing barcodes
|
|
33
33
|
inventory_df["item_id"] = inventory_df["item_id"].fillna(
|
|
34
|
-
inventory_df["item_id"].apply(lambda _: _generate_random_startingmaterial_id())
|
|
34
|
+
inventory_df["item_id"].apply(lambda _: next(_generate_random_startingmaterial_id()))
|
|
35
35
|
)
|
|
36
36
|
inventory_df["Molecular Weight"] = inventory_df["Molecular Weight"].replace(" ", float("nan"))
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
counts = {"success": 0, "duplicate": 0}
|
|
38
|
+
counts = {"success": 0, "duplicate": 0, "failed": 0}
|
|
41
39
|
|
|
42
40
|
for item in inventory_df.to_dict(orient="records"):
|
|
43
41
|
try:
|
|
@@ -47,5 +45,9 @@ def import_cheminventory(filename: Path, client: DatalabClient):
|
|
|
47
45
|
counts["success"] += 1
|
|
48
46
|
except DuplicateItemError:
|
|
49
47
|
counts["duplicate"] += 1
|
|
48
|
+
except Exception as exc:
|
|
49
|
+
counts["failed"] += 1
|
|
50
|
+
print(f"Failed to import item: {item}. Error: {exc}")
|
|
51
|
+
continue
|
|
50
52
|
|
|
51
53
|
print(f"Done: {counts=}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: datalab-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: A Python API for instances of the datalab data management platform (https://github.com/the-grey-group/datalab).
|
|
5
5
|
Author-email: Matthew Evans <matthew@ml-evs.science>
|
|
6
6
|
License: MIT
|
|
@@ -99,7 +99,7 @@ You can generate one for your account for a given *datalab* instance by visiting
|
|
|
99
99
|
|
|
100
100
|
This API key can be set via the environment variable `DATALAB_API_KEY`.
|
|
101
101
|
To suport the use case of needing to interact with multiple datalab instances, the client will also check prefixed environment variables that use the [`IDENTIFIER_PREFIX` of the chosen datalab instance](https://the-datalab.readthedocs.io/en/latest/config/#mandatory-settings), e.g., `GREY_DATALAB_API_KEY` or `PUBLIC_DATALAB_API_KEY`.
|
|
102
|
-
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://
|
|
102
|
+
Only keys that match will be read (e.g., other environment variables starting with `PUBLIC_` will be ignored, when connecting to the [public demo datalab](https://demo.datalab-org.io)).
|
|
103
103
|
|
|
104
104
|
### Python API
|
|
105
105
|
|
|
@@ -108,7 +108,7 @@ This package implements basic functionality for displaying and manipulating entr
|
|
|
108
108
|
```python
|
|
109
109
|
from datalab_api import DatalabClient
|
|
110
110
|
|
|
111
|
-
with DatalabClient("https://
|
|
111
|
+
with DatalabClient("https://demo-api.datalab-org.io") as client:
|
|
112
112
|
|
|
113
113
|
# List all items of a given type
|
|
114
114
|
items = client.get_items()
|
|
@@ -167,7 +167,7 @@ datalab > help get
|
|
|
167
167
|
│ --help Show this message and exit. │
|
|
168
168
|
╰─────────────────────────────────────────────────────────────────────────────────────────────────────╯
|
|
169
169
|
|
|
170
|
-
datalab > get samples api.
|
|
170
|
+
datalab > get samples demo-api.datalab-org.io --page-limit 2
|
|
171
171
|
/samples/
|
|
172
172
|
┏━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
|
|
173
173
|
┃ type ┃ ID ┃ refcode ┃ name ┃ nblocks ┃ collections ┃ creators ┃
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|