datalab-python-sdk 0.9.0__tar.gz → 0.9.1__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_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/CHANGELOG.md +10 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/PKG-INFO +2 -2
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/README.md +1 -1
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/client.py +25 -2
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/pyproject.toml +1 -1
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_client_methods.py +54 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/uv.lock +1 -1
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/.github/workflows/ci.yml +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/.gitignore +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/.pre-commit-config.yaml +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/.python-version +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/LICENSE +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/08-Lambda-Calculus.pptx +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/adversarial.pdf +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/bid_evaluation.docx +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/book_review.ppt +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/book_store.xls +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/chi_hind.png +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/how_to_read.doc +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/normandy.epub +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/sample-1-sheet.xlsx +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/thinkpython.pdf +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/data/vibe.html +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/__init__.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/auth.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/cli.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/exceptions.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/mimetypes.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/models.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/datalab_sdk/settings.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/integration/README.md +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/integration/__init__.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/integration/test_live_api.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/integration/test_readme_examples.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/pytest.ini +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/README.md +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/end_to_end_workflow.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/1_get_step_types.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/2_get_workflows.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/3_create_workflow.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/4_execute_workflow.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/5_poll_workflow.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_api_tutorial/README.md +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_definitions/README.md +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_definitions/eval_segmentation.json +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_definitions/parse_segment.json +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_definitions/segment_parallel_extract.json +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/workflow_definitions/slack_alert.json +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/__init__.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/conftest.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_api_consistency.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_cli_options.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_cli_simple.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_device_login.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_errors.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_new_endpoints.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_progress.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_results.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_transport_audit.py +0 -0
- {datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/tests/test_workflows.py +0 -0
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
The newest release is at the top. Each export to this repository uses the
|
|
4
4
|
top section as its commit message.
|
|
5
5
|
|
|
6
|
+
## 0.9.1
|
|
7
|
+
|
|
8
|
+
Changed:
|
|
9
|
+
|
|
10
|
+
- Result polls check every 0.3 seconds for the first 8 seconds of a request,
|
|
11
|
+
then every `poll_interval`. Most single-page results are ready within a few
|
|
12
|
+
seconds, so they arrive sooner. The polling budget is unchanged: the waits
|
|
13
|
+
between polls add up to `max_polls * poll_interval` seconds. A
|
|
14
|
+
`poll_interval` above 1 second turns the fast phase off.
|
|
15
|
+
|
|
6
16
|
## 0.9.0
|
|
7
17
|
|
|
8
18
|
New:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datalab-python-sdk
|
|
3
|
-
Version: 0.9.
|
|
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
|
|
|
@@ -150,7 +150,7 @@ Published-agent execution is in open beta; the API may change. Processor design
|
|
|
150
150
|
## Inputs, polling and errors
|
|
151
151
|
|
|
152
152
|
- 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`.
|
|
153
|
-
- 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.
|
|
153
|
+
- 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.
|
|
154
154
|
- 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.
|
|
155
155
|
- 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`.
|
|
156
156
|
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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"
|
|
@@ -7,7 +7,7 @@ readme = "README.md"
|
|
|
7
7
|
license = "MIT"
|
|
8
8
|
repository = "https://github.com/datalab-to/sdk"
|
|
9
9
|
keywords = ["datalab", "sdk", "document-intelligence", "api"]
|
|
10
|
-
version = "0.9.
|
|
10
|
+
version = "0.9.1"
|
|
11
11
|
description = "SDK for the Datalab document intelligence API"
|
|
12
12
|
requires-python = ">=3.11"
|
|
13
13
|
dependencies = [
|
|
@@ -795,6 +795,60 @@ class TestPollingLoop:
|
|
|
795
795
|
)
|
|
796
796
|
|
|
797
797
|
|
|
798
|
+
class TestFastPolling:
|
|
799
|
+
@pytest.mark.asyncio
|
|
800
|
+
async def test_first_polls_are_fast(self):
|
|
801
|
+
async with AsyncDatalabClient(api_key="test-key") as client:
|
|
802
|
+
with (
|
|
803
|
+
patch.object(
|
|
804
|
+
client, "_make_request", new_callable=AsyncMock
|
|
805
|
+
) as mock_req,
|
|
806
|
+
patch("asyncio.sleep", new_callable=AsyncMock) as mock_sleep,
|
|
807
|
+
):
|
|
808
|
+
mock_req.side_effect = [
|
|
809
|
+
{"status": "processing", "success": True}
|
|
810
|
+
] * 2 + [{"status": "complete", "success": True, "markdown": "x"}]
|
|
811
|
+
await client._poll_result(
|
|
812
|
+
"https://api.example.com/check", max_polls=300, poll_interval=1
|
|
813
|
+
)
|
|
814
|
+
assert [c.args[0] for c in mock_sleep.await_args_list] == [0.3, 0.3]
|
|
815
|
+
|
|
816
|
+
@pytest.mark.asyncio
|
|
817
|
+
async def test_slow_interval_has_no_fast_phase(self):
|
|
818
|
+
async with AsyncDatalabClient(api_key="test-key") as client:
|
|
819
|
+
with (
|
|
820
|
+
patch.object(
|
|
821
|
+
client, "_make_request", new_callable=AsyncMock
|
|
822
|
+
) as mock_req,
|
|
823
|
+
patch("asyncio.sleep", new_callable=AsyncMock) as mock_sleep,
|
|
824
|
+
):
|
|
825
|
+
mock_req.side_effect = [{"status": "processing", "success": True}] + [
|
|
826
|
+
{"status": "complete", "success": True, "markdown": "x"}
|
|
827
|
+
]
|
|
828
|
+
await client._poll_result(
|
|
829
|
+
"https://api.example.com/check", max_polls=300, poll_interval=2
|
|
830
|
+
)
|
|
831
|
+
assert [c.args[0] for c in mock_sleep.await_args_list] == [2]
|
|
832
|
+
|
|
833
|
+
@pytest.mark.asyncio
|
|
834
|
+
async def test_budget_is_max_polls_times_interval(self):
|
|
835
|
+
async with AsyncDatalabClient(api_key="test-key") as client:
|
|
836
|
+
with (
|
|
837
|
+
patch.object(
|
|
838
|
+
client, "_make_request", new_callable=AsyncMock
|
|
839
|
+
) as mock_req,
|
|
840
|
+
patch("asyncio.sleep", new_callable=AsyncMock) as mock_sleep,
|
|
841
|
+
):
|
|
842
|
+
mock_req.return_value = {"status": "processing", "success": True}
|
|
843
|
+
with pytest.raises(DatalabTimeoutError):
|
|
844
|
+
await client._poll_result(
|
|
845
|
+
"https://api.example.com/check", max_polls=3, poll_interval=1
|
|
846
|
+
)
|
|
847
|
+
assert sum(
|
|
848
|
+
c.args[0] for c in mock_sleep.await_args_list
|
|
849
|
+
) == pytest.approx(3)
|
|
850
|
+
|
|
851
|
+
|
|
798
852
|
class TestExtractWithSchemaId:
|
|
799
853
|
"""Test extract with schema_id support"""
|
|
800
854
|
|
|
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
|
|
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
|
|
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
|
{datalab_python_sdk-0.9.0 → datalab_python_sdk-0.9.1}/recipes/workflows/end_to_end_workflow.py
RENAMED
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|