datalab-api 0.3.1__tar.gz → 0.3.2__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.3.1
3
+ Version: 0.3.2
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-Expression: MIT
@@ -61,7 +61,7 @@ A simple Python API that can interact with [*datalab*](https://github.com/datala
61
61
 
62
62
  The idea here is to provide a set of utility functions and models for manipulating samples, cells, inventory, files, users and metadata associated with *datalab* entries in an automated way.
63
63
 
64
- This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io/en/stable/rest_api/).
64
+ This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io).
65
65
  This means that the API is primarily *functional* in nature, as opposed to object-oriented, since *datalab* instances are free to use their own custom data models.
66
66
  The available schemas are reported as instance metadata and in the future object-oriented models may be able to be genereated directly in the client (so e.g., the returned data would be Python objects like `Sample` rather than JSON data).
67
67
 
@@ -14,7 +14,7 @@ A simple Python API that can interact with [*datalab*](https://github.com/datala
14
14
 
15
15
  The idea here is to provide a set of utility functions and models for manipulating samples, cells, inventory, files, users and metadata associated with *datalab* entries in an automated way.
16
16
 
17
- This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io/en/stable/rest_api/).
17
+ This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io).
18
18
  This means that the API is primarily *functional* in nature, as opposed to object-oriented, since *datalab* instances are free to use their own custom data models.
19
19
  The available schemas are reported as instance metadata and in the future object-oriented models may be able to be genereated directly in the client (so e.g., the returned data would be Python objects like `Sample` rather than JSON data).
20
20
 
@@ -5,7 +5,7 @@ from collections.abc import Iterable
5
5
  from pathlib import Path
6
6
  from typing import Any, Optional, Union
7
7
 
8
- from ._base import BaseDatalabClient, DuplicateItemError, __version__
8
+ from ._base import BaseDatalabClient, DatalabAPIError, DuplicateItemError, __version__
9
9
 
10
10
  __all__ = ("DatalabClient", "DuplicateItemError", "__version__")
11
11
 
@@ -150,6 +150,9 @@ class DatalabClient(BaseDatalabClient):
150
150
  except RuntimeError:
151
151
  self.create_collection(collection_id)
152
152
  collection_immutable_id = self.get_collection(collection_id)[0]["immutable_id"]
153
+ except DatalabAPIError:
154
+ self.create_collection(collection_id)
155
+ collection_immutable_id = self.get_collection(collection_id)[0]["immutable_id"]
153
156
  new_item["collections"] = new_item.get("collections", [])
154
157
  new_item["collections"].append({"immutable_id": collection_immutable_id})
155
158
 
@@ -2,6 +2,7 @@ import logging
2
2
  import os
3
3
  import re
4
4
  import warnings
5
+ from getpass import getpass
5
6
  from importlib.metadata import version
6
7
  from typing import Any, Optional
7
8
 
@@ -37,6 +38,11 @@ class BaseDatalabClient(metaclass=AutoPrettyPrint):
37
38
  _headers: dict[str, str] = {}
38
39
  _timeout: httpx.Timeout = httpx.Timeout(10.0, read=60.0)
39
40
 
41
+ interactive: bool = True
42
+ """Whether the client is being used in an interactive context (e.g., CLI or notebook) or not.
43
+ Set to false if you want the script to error if no API key is found in the environment variables,
44
+ rather than prompting for input."""
45
+
40
46
  info: dict[str, Any] = {}
41
47
  """The `data` response from the `/info` endpoint of the Datalab API."""
42
48
 
@@ -189,9 +195,14 @@ class BaseDatalabClient(metaclass=AutoPrettyPrint):
189
195
  api_key = api_key.strip("'").strip('"')
190
196
 
191
197
  if api_key is None:
192
- raise ValueError(
193
- f"No API key found in environment variables {key_env_var}/<prefix>_{key_env_var}."
194
- )
198
+ if self.interactive:
199
+ api_key = getpass(
200
+ f"Enter your API key for {self.datalab_api_url} (input will be hidden): "
201
+ )
202
+ else:
203
+ raise ValueError(
204
+ f"No API key found in environment variables {key_env_var}/<prefix>_{key_env_var}."
205
+ )
195
206
 
196
207
  self._api_key = api_key
197
208
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datalab-api
3
- Version: 0.3.1
3
+ Version: 0.3.2
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-Expression: MIT
@@ -61,7 +61,7 @@ A simple Python API that can interact with [*datalab*](https://github.com/datala
61
61
 
62
62
  The idea here is to provide a set of utility functions and models for manipulating samples, cells, inventory, files, users and metadata associated with *datalab* entries in an automated way.
63
63
 
64
- This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io/en/stable/rest_api/).
64
+ This API may not expose all the functionality available in a given *datalab* instance, and the idea would be that this package can support multiple versions of the underlying [*datalab* REST API](https://docs.datalab-org.io).
65
65
  This means that the API is primarily *functional* in nature, as opposed to object-oriented, since *datalab* instances are free to use their own custom data models.
66
66
  The available schemas are reported as instance metadata and in the future object-oriented models may be able to be genereated directly in the client (so e.g., the returned data would be Python objects like `Sample` rather than JSON data).
67
67
 
File without changes
File without changes
File without changes