datalab-python-sdk 0.9.0__py3-none-any.whl → 0.9.2__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.2
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
 
@@ -0,0 +1,13 @@
1
+ datalab_sdk/__init__.py,sha256=O95y4a-N34dxyDak6YWrUjEG4kdtVirgBqShh1L6z_Q,2475
2
+ datalab_sdk/auth.py,sha256=X2eccKzpdxogFEDoS4geOHIOeECQ8u3kANxKoqF0PVk,4388
3
+ datalab_sdk/cli.py,sha256=6tYZhkx1f4enOU2tvqC43aDW1dI_agJrOCBG5RAJwvg,54490
4
+ datalab_sdk/client.py,sha256=NaGY8NKAcOjaBIV0adS_n6diOu710Az581zYdt4jwKM,141435
5
+ datalab_sdk/exceptions.py,sha256=5-lzlfvB7FKGOhvgyacceTFRRUxton_JqcIyuB8k_mU,2625
6
+ datalab_sdk/mimetypes.py,sha256=a4ULJmHxoR_RMsD0j51hx0t2Q7In_PzNm7UlWX07eEE,932
7
+ datalab_sdk/models.py,sha256=tr5pGsbI9x7GDrN4BAyWMEMWLcF1goJ5Ot8X4pFeT5k,35081
8
+ datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
9
+ datalab_python_sdk-0.9.2.dist-info/METADATA,sha256=_6OLIHKgM0EZAh0BUC5-0VcuxXCHO3DV4mXRrBEwQYQ,9236
10
+ datalab_python_sdk-0.9.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ datalab_python_sdk-0.9.2.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
12
+ datalab_python_sdk-0.9.2.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
13
+ datalab_python_sdk-0.9.2.dist-info/RECORD,,
datalab_sdk/cli.py CHANGED
@@ -658,6 +658,12 @@ def convert(
658
658
  default=None,
659
659
  help="Extraction mode (the API default is balanced)",
660
660
  )
661
+ @click.option(
662
+ "--citation_granularity",
663
+ type=click.Choice(["block", "phrase"]),
664
+ default=None,
665
+ help="Citation detail: block ids (the API default) or the exact phrase of each value (open beta)",
666
+ )
661
667
  @click.option(
662
668
  "--save_checkpoint", is_flag=True, help="Save a checkpoint for later calls"
663
669
  )
@@ -672,6 +678,7 @@ def extract(
672
678
  output_format: str,
673
679
  mode: Optional[str],
674
680
  extraction_mode: Optional[str],
681
+ citation_granularity: Optional[str],
675
682
  save_checkpoint: bool,
676
683
  webhook_url: Optional[str],
677
684
  api_key: str,
@@ -695,6 +702,7 @@ def extract(
695
702
  checkpoint_id=checkpoint_id,
696
703
  output_format=output_format or "markdown",
697
704
  extraction_mode=extraction_mode,
705
+ citation_granularity=citation_granularity,
698
706
  save_checkpoint=save_checkpoint,
699
707
  webhook_url=webhook_url,
700
708
  max_pages=max_pages,
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"
datalab_sdk/models.py CHANGED
@@ -141,6 +141,10 @@ class ExtractOptions(ProcessingOptions):
141
141
  # Extraction mode: turbo, fast, balanced, accurate. None lets the API
142
142
  # choose (the default is balanced). Turbo needs a file, not a checkpoint.
143
143
  extraction_mode: Optional[str] = None
144
+ # Citation granularity: "block" (the API default) returns block ids;
145
+ # "phrase" (open beta) returns the words, offsets, match score and box of
146
+ # each value.
147
+ citation_granularity: Optional[str] = None
144
148
  output_format: str = "markdown" # markdown, json, html, chunks
145
149
  save_checkpoint: bool = False
146
150
  webhook_url: Optional[str] = None
@@ -1,13 +0,0 @@
1
- datalab_sdk/__init__.py,sha256=O95y4a-N34dxyDak6YWrUjEG4kdtVirgBqShh1L6z_Q,2475
2
- datalab_sdk/auth.py,sha256=X2eccKzpdxogFEDoS4geOHIOeECQ8u3kANxKoqF0PVk,4388
3
- datalab_sdk/cli.py,sha256=icUy91brz0J8hzvC1G-pBtZPszc5oRd4H3sEpYhKr7Y,54186
4
- datalab_sdk/client.py,sha256=xbDyjCs_B8a3hugVBM7PG7dqzT1UWTm-lAGFspTdW6s,140223
5
- datalab_sdk/exceptions.py,sha256=5-lzlfvB7FKGOhvgyacceTFRRUxton_JqcIyuB8k_mU,2625
6
- datalab_sdk/mimetypes.py,sha256=a4ULJmHxoR_RMsD0j51hx0t2Q7In_PzNm7UlWX07eEE,932
7
- datalab_sdk/models.py,sha256=K5VVGyaqUPpZFLkZbQa76gkR-HIIgqm5f_bcO42SnHI,34865
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,,