datalab-python-sdk 0.9.0__py3-none-any.whl → 0.9.1__py3-none-any.whl

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.5
2
2
  Name: datalab-python-sdk
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: SDK for the Datalab document intelligence API
5
5
  Project-URL: Homepage, https://www.datalab.to
6
6
  Project-URL: Documentation, https://documentation.datalab.to
@@ -171,7 +171,7 @@ Published-agent execution is in open beta; the API may change. Processor design
171
171
  ## Inputs, polling and errors
172
172
 
173
173
  - Send a local file with `file_path`, or a URL or a `datalab://file-...` reference with `file_url`. When you set `processing_location`, send the document as `file_url`.
174
- - Processing methods poll until the result is ready. Set `max_polls` and `poll_interval` to change the limit (default: 300 polls, 1 second apart). Use `stream_response_to` to write a large result straight to disk.
174
+ - Processing methods poll until the result is ready. The first 8 seconds poll every 0.3 seconds. Set `max_polls` and `poll_interval` to change the limit (default: 300 polls, 1 second apart). Use `stream_response_to` to write a large result straight to disk.
175
175
  - The SDK retries a submission that gets HTTP 429 or 503, and polls that get 408, 429, 5xx or a connection error. It waits for the `Retry-After` header when the API sends one.
176
176
  - API errors raise `DatalabAPIError` (with `status_code` and `response_data`) or one of its subclasses: `DatalabAuthenticationError` (401, 403), `DatalabPaymentRequiredError` (402), `DatalabNotFoundError` (404), `DatalabRateLimitError` (429) and `DatalabServerError` (5xx). Invalid arguments raise `DatalabValidationError`, which is also a `ValueError`.
177
177
 
@@ -1,13 +1,13 @@
1
1
  datalab_sdk/__init__.py,sha256=O95y4a-N34dxyDak6YWrUjEG4kdtVirgBqShh1L6z_Q,2475
2
2
  datalab_sdk/auth.py,sha256=X2eccKzpdxogFEDoS4geOHIOeECQ8u3kANxKoqF0PVk,4388
3
3
  datalab_sdk/cli.py,sha256=icUy91brz0J8hzvC1G-pBtZPszc5oRd4H3sEpYhKr7Y,54186
4
- datalab_sdk/client.py,sha256=xbDyjCs_B8a3hugVBM7PG7dqzT1UWTm-lAGFspTdW6s,140223
4
+ datalab_sdk/client.py,sha256=NaGY8NKAcOjaBIV0adS_n6diOu710Az581zYdt4jwKM,141435
5
5
  datalab_sdk/exceptions.py,sha256=5-lzlfvB7FKGOhvgyacceTFRRUxton_JqcIyuB8k_mU,2625
6
6
  datalab_sdk/mimetypes.py,sha256=a4ULJmHxoR_RMsD0j51hx0t2Q7In_PzNm7UlWX07eEE,932
7
7
  datalab_sdk/models.py,sha256=K5VVGyaqUPpZFLkZbQa76gkR-HIIgqm5f_bcO42SnHI,34865
8
8
  datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
9
- datalab_python_sdk-0.9.0.dist-info/METADATA,sha256=L3KJ_KaRXFykDKtFyP4hHh7qhzBk5bj15t90pl9QHiI,9192
10
- datalab_python_sdk-0.9.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
- datalab_python_sdk-0.9.0.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
12
- datalab_python_sdk-0.9.0.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
13
- datalab_python_sdk-0.9.0.dist-info/RECORD,,
9
+ datalab_python_sdk-0.9.1.dist-info/METADATA,sha256=a9tFtEiBMugSi4m9cyRg1c0h8oUQxxGadMx3EOt65bg,9236
10
+ datalab_python_sdk-0.9.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ datalab_python_sdk-0.9.1.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
12
+ datalab_python_sdk-0.9.1.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
13
+ datalab_python_sdk-0.9.1.dist-info/RECORD,,
datalab_sdk/client.py CHANGED
@@ -97,6 +97,12 @@ class _ProgressReporter:
97
97
  _SUBMIT_RETRY_STATUSES = (429, 503)
98
98
  _BACKOFF = wait_exponential_jitter(initial=5, max=120)
99
99
  _MAX_RETRY_AFTER_SECONDS = 120.0
100
+ # The first FAST_POLL_SECONDS of a result poll check every FAST_POLL_INTERVAL
101
+ # seconds, then every poll_interval.
102
+ FAST_POLL_INTERVAL = 0.3
103
+ FAST_POLL_SECONDS = 8.0
104
+ # Hard stop on poll requests, in case the time budget never runs out.
105
+ _MAX_POLL_REQUESTS = 100_000
100
106
 
101
107
 
102
108
  def _wait_retry_after_or_backoff(retry_state) -> float:
@@ -330,7 +336,16 @@ class AsyncDatalabClient:
330
336
  )
331
337
 
332
338
  progress = _ProgressReporter(on_progress)
333
- for i in range(max_polls):
339
+ # Most single-page results are ready within a few seconds, so the first
340
+ # FAST_POLL_SECONDS poll every FAST_POLL_INTERVAL. After that the loop
341
+ # polls every poll_interval. The budget is unchanged: the sleeps add up
342
+ # to max_polls * poll_interval seconds, as in the plain loop. A caller
343
+ # that asks for a poll_interval above 1 second gets no fast phase.
344
+ loop = asyncio.get_running_loop()
345
+ fast_until = loop.time() + FAST_POLL_SECONDS if 0 < poll_interval <= 1 else 0.0
346
+ budget = max_polls * poll_interval
347
+ slept = 0.0
348
+ for i in range(max_polls if poll_interval <= 0 else _MAX_POLL_REQUESTS):
334
349
  if stream_response_to:
335
350
  result = await self._poll_get_streaming(full_url, stream_response_to)
336
351
  status, success, error = result.status, result.success, result.error
@@ -357,7 +372,15 @@ class AsyncDatalabClient:
357
372
  if not success and status != "processing":
358
373
  raise DatalabAPIError(f"Processing failed: {error or 'Unknown error'}")
359
374
 
360
- await asyncio.sleep(poll_interval)
375
+ if poll_interval <= 0:
376
+ await asyncio.sleep(poll_interval)
377
+ continue
378
+ if slept >= budget:
379
+ break
380
+ delay = FAST_POLL_INTERVAL if loop.time() < fast_until else poll_interval
381
+ delay = min(delay, budget - slept)
382
+ await asyncio.sleep(delay)
383
+ slept += delay
361
384
 
362
385
  raise DatalabTimeoutError(
363
386
  f"Polling timed out after {max_polls * poll_interval} seconds"