datalab-api 0.2.5__tar.gz → 0.2.7__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.1
2
2
  Name: datalab-api
3
- Version: 0.2.5
3
+ Version: 0.2.7
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
@@ -124,11 +124,15 @@ class DatalabClient(BaseDatalabClient):
124
124
  new_item = item_data
125
125
  new_item.update({"item_id": item_id, "type": item_type})
126
126
 
127
+ if new_item["item_id"] is None:
128
+ new_item.pop("item_id")
129
+
127
130
  if collection_id is not None:
128
131
  try:
129
132
  collection_immutable_id = self.get_collection(collection_id)["immutable_id"]
130
133
  except RuntimeError:
131
- collection_immutable_id = self.create_collection(collection_id)["immutable_id"]
134
+ self.create_collection(collection_id)
135
+ collection_immutable_id = self.get_collection(collection_id)["immutable_id"]
132
136
  new_item["collections"] = new_item.get("collections", [])
133
137
  new_item["collections"].append({"immutable_id": collection_immutable_id})
134
138
 
@@ -386,6 +390,33 @@ class DatalabClient(BaseDatalabClient):
386
390
 
387
391
  return block_data
388
392
 
393
+ def update_data_block(
394
+ self, item_id: str, block_id: str, block_type: str, block_data: dict
395
+ ) -> dict[str, Any]:
396
+ """Attempts to update a block with the given payload of data,
397
+ returning the updated block.
398
+
399
+ Parameters:
400
+ item_id: The ID of the item that the block is attached to.
401
+ block_id: The ID of existing block.
402
+ block_type: The type of block to update.
403
+ block_data: The payload of block data to update; will be used to selectively update
404
+ any fields present, with validation performed by the remote block code itself.
405
+
406
+ Returns:
407
+ If successful, the updated block data.
408
+
409
+ Raises:
410
+ RuntimeError: If the block update fails.
411
+
412
+ """
413
+ payload = {k: v for k, v in block_data.items()}
414
+ payload["block_id"] = block_id
415
+ payload["blocktype"] = block_type
416
+ payload["item_id"] = item_id
417
+
418
+ return self._update_data_block(block_type=block_type, block_data=payload)
419
+
389
420
  def _update_data_block(
390
421
  self, block_type: str, block_data: dict, file_ids: str | list[str] | None = None
391
422
  ) -> dict[str, Any]:
@@ -398,7 +429,6 @@ class DatalabClient(BaseDatalabClient):
398
429
  raise RuntimeError(
399
430
  "API does not currently support attaching multiple files in a block."
400
431
  )
401
-
402
432
  block_data["file_id"] = file_ids[0]
403
433
 
404
434
  blocks_url = f"{self.datalab_api_url}/update-block/"
@@ -95,6 +95,7 @@ class BaseDatalabClient(metaclass=AutoPrettyPrint):
95
95
  _api_key: Optional[str] = None
96
96
  _session: Optional[httpx.Client] = None
97
97
  _headers: dict[str, str] = {}
98
+ _timeout: httpx.Timeout = httpx.Timeout(10.0, read=60.0)
98
99
 
99
100
  bad_server_versions: Optional[tuple[tuple[int, int, int]]] = ((0, 2, 0),)
100
101
  """Any known server versions that are not supported by this client."""
@@ -172,13 +173,19 @@ class BaseDatalabClient(metaclass=AutoPrettyPrint):
172
173
  @property
173
174
  def session(self) -> httpx.Client:
174
175
  if self._session is None:
175
- return self._http_client(headers=self.headers)
176
+ return self._http_client(headers=self.headers, timeout=self.timeout)
176
177
  return self._session
177
178
 
178
179
  @property
179
- def headers(self):
180
+ def headers(self) -> dict[str, str]:
181
+ """Any headers to send with each request to the datalab API."""
180
182
  return self._headers
181
183
 
184
+ @property
185
+ def timeout(self) -> httpx.Timeout:
186
+ """A timeout object to use for the datalab API session."""
187
+ return self._timeout
188
+
182
189
  def _version_negotiation(self):
183
190
  """Check whether this client is expected to work with this instance.
184
191
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datalab-api
3
- Version: 0.2.5
3
+ Version: 0.2.7
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
File without changes
File without changes
File without changes
File without changes