datalab-python-sdk 0.7.1__py3-none-any.whl → 0.9.0__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.7.1
3
+ Version: 0.9.0
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
@@ -63,6 +63,32 @@ print(result.markdown)
63
63
 
64
64
  `AsyncDatalabClient` has the same methods as `DatalabClient`, as coroutines.
65
65
 
66
+ ## Progress callbacks
67
+
68
+ With SDK 0.8.0 or later, pass `on_progress` to processing calls:
69
+
70
+ ```python
71
+ result = client.convert(
72
+ "document.pdf",
73
+ on_progress=lambda percent: print(f"Processing: {percent}%"),
74
+ )
75
+ ```
76
+
77
+ The same argument works with `extract`, `segment`, `run_agent`, `track_changes`,
78
+ `create_document`, `ocr`, `fill`, and `form_fields`, including `stream_response_to`.
79
+ `run_pipeline` and `get_pipeline_execution` also support it; set `max_polls`
80
+ above 1 to keep polling a pipeline. Result models expose `progress_percent`
81
+ when the API supplies it.
82
+
83
+ Callbacks receive increasing integer percentages from existing polls, skipping
84
+ missing values and duplicates. Percentages may pause or jump and are not an ETA.
85
+ A callback receives 100 only after successful completion and any signed-result
86
+ download. Check the returned status and success to determine the outcome.
87
+ `AsyncDatalabClient` also accepts async callbacks, which it awaits. Keep callbacks
88
+ short: they run inline, and their exceptions propagate to your call. Callback
89
+ errors stop local polling; they do not cancel the server request. No extra API
90
+ requests are made, and polling intervals are unchanged.
91
+
66
92
  ## Conversion options
67
93
 
68
94
  ```python
@@ -99,6 +125,30 @@ print(result.extraction_schema_json, result.extraction_score_average)
99
125
 
100
126
  When you do not set the parse `mode`, the API picks the parse mode that matches `extraction_mode`.
101
127
 
128
+ ## Redaction
129
+
130
+ **Open beta (SDK 0.9.0):** the redaction API may change.
131
+
132
+ ```python
133
+ from datalab_sdk import RedactOptions
134
+
135
+ result = client.redact(
136
+ "document.pdf",
137
+ options=RedactOptions(preset="personal_information"),
138
+ )
139
+ # A PDF can be returned even when verification fails. Review these first.
140
+ print(result.verdict, result.failing_checks)
141
+ if result.success and result.verdict == "PASS" and not result.withheld and result.output_base64:
142
+ result.save_output("redacted.pdf")
143
+ ```
144
+
145
+ `get_redaction_presets()` returns the built-in preset IDs and specifications.
146
+ Use `redaction_spec` to supply a custom spec. Redaction processes the whole
147
+ PDF or image; page subsets are not supported. Completed requests are charged
148
+ even if verification fails. `save_output` on `redact()` saves any available
149
+ PDF, including one with failed verification. Redaction returns a typed result;
150
+ `stream_response_to` is not supported for this helper.
151
+
102
152
  ## Other endpoints
103
153
 
104
154
  | Method | Endpoint |
@@ -109,7 +159,6 @@ When you do not set the parse `mode`, the API picks the parse mode that matches
109
159
  | `form_fields()` | Find the fillable fields in a PDF or image |
110
160
  | `track_changes()` | Read tracked changes and comments from DOCX or PDF |
111
161
  | `create_document()` | Make a DOCX from markdown with track changes markup |
112
- | `generate_extraction_schemas()` | Suggest extraction schemas for a saved checkpoint |
113
162
  | `delete_result()` | Result deletion, by `result.request_id` |
114
163
  | `upload_files()`, `list_files()`, ... | File storage. Pass the returned `datalab://file-...` reference as `file_url` |
115
164
  | `create_extraction_schema()`, ... | Saved extraction schemas |
@@ -126,6 +175,10 @@ Published-agent execution is in open beta; the API may change. Processor design
126
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.
127
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`.
128
177
 
178
+ With SDK 0.9.0, `upload_files(paths, max_concurrency=5)` streams
179
+ files from disk and limits the number of active uploads. Results retain the
180
+ input order. Use `AsyncDatalabClient` inside an existing async event loop.
181
+
129
182
  ## Workflows
130
183
 
131
184
  The Datalab API removed the Workflows API. The workflow methods and CLI commands in this SDK are deprecated, and the API does not answer them. Use pipelines instead.
@@ -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=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,,
datalab_sdk/__init__.py CHANGED
@@ -30,6 +30,8 @@ from .models import (
30
30
  CustomPipelineOptions,
31
31
  TrackChangesOptions,
32
32
  OCROptions,
33
+ RedactOptions,
34
+ RedactResult,
33
35
  FormFillingOptions,
34
36
  FormFillingResult,
35
37
  FormFieldsOptions,
@@ -78,6 +80,8 @@ __all__ = [
78
80
  "CustomPipelineOptions",
79
81
  "TrackChangesOptions",
80
82
  "OCROptions",
83
+ "RedactOptions",
84
+ "RedactResult",
81
85
  "FormFillingOptions",
82
86
  "FormFillingResult",
83
87
  "FormFieldsOptions",
datalab_sdk/client.py CHANGED
@@ -3,6 +3,7 @@ Datalab API client - async core with sync wrapper
3
3
  """
4
4
 
5
5
  import asyncio
6
+ import inspect
6
7
  import json as jsonlib
7
8
  import mimetypes
8
9
  import os
@@ -20,7 +21,7 @@ from tenacity import (
20
21
  wait_exponential_jitter,
21
22
  )
22
23
  from pathlib import Path
23
- from typing import Union, Optional, Dict, Any
24
+ from typing import Union, Optional, Dict, Any, Callable, Awaitable
24
25
 
25
26
  from datalab_sdk.exceptions import (
26
27
  DatalabAPIError,
@@ -42,6 +43,8 @@ from datalab_sdk.models import (
42
43
  CustomProcessorOptions,
43
44
  TrackChangesOptions,
44
45
  OCROptions,
46
+ RedactOptions,
47
+ RedactResult,
45
48
  FormFillingOptions,
46
49
  FormFillingResult,
47
50
  FormFieldsOptions,
@@ -66,6 +69,29 @@ from datalab_sdk.models import (
66
69
  from datalab_sdk.settings import settings
67
70
 
68
71
 
72
+ ProgressCallback = Callable[[int], Optional[Awaitable[None]]]
73
+
74
+
75
+ class _ProgressReporter:
76
+ """Deliver increasing, valid percentages within one polling operation."""
77
+
78
+ def __init__(self, callback: Optional[ProgressCallback]):
79
+ self.callback = callback
80
+ self.last = -1
81
+
82
+ async def report(self, percent: Any, *, complete: bool = False) -> None:
83
+ if complete:
84
+ percent = 100
85
+ if type(percent) is not int or not 0 <= percent <= (100 if complete else 99):
86
+ return
87
+ if self.callback is None or percent <= self.last:
88
+ return
89
+ self.last = percent
90
+ result = self.callback(percent)
91
+ if inspect.isawaitable(result):
92
+ await result
93
+
94
+
69
95
  # HTTP status codes that a POST submission can safely retry. The API sends
70
96
  # 429 for rate limits and 503 when it cannot queue the job ("please retry").
71
97
  _SUBMIT_RETRY_STATUSES = (429, 503)
@@ -293,6 +319,8 @@ class AsyncDatalabClient:
293
319
  max_polls: int = 300,
294
320
  poll_interval: int = 1,
295
321
  stream_response_to: Optional[Path] = None,
322
+ on_progress: Optional[ProgressCallback] = None,
323
+ result_transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
296
324
  ) -> Union[Dict[str, Any], FileResult]:
297
325
  """Poll for result completion"""
298
326
  full_url = (
@@ -301,20 +329,30 @@ class AsyncDatalabClient:
301
329
  else f"{self.base_url}/{check_url.lstrip('/')}"
302
330
  )
303
331
 
332
+ progress = _ProgressReporter(on_progress)
304
333
  for i in range(max_polls):
305
334
  if stream_response_to:
306
335
  result = await self._poll_get_streaming(full_url, stream_response_to)
307
336
  status, success, error = result.status, result.success, result.error
337
+ percent = result.progress_percent
308
338
  else:
309
339
  data = await self._poll_get_with_retry(full_url)
310
340
  status = data.get("status")
311
341
  success = data.get("success", True)
312
342
  error = data.get("error")
343
+ percent = data.get("progress_percent")
313
344
 
314
345
  if status == "complete":
315
- if stream_response_to:
316
- return result
317
- return await self._resolve_signed_result(data)
346
+ if not stream_response_to:
347
+ result = await self._resolve_signed_result(data)
348
+ if result_transform is not None:
349
+ result = result_transform(result)
350
+ success = result.get("success", False)
351
+ percent = result.get("progress_percent")
352
+ await progress.report(percent, complete=bool(success))
353
+ return result
354
+
355
+ await progress.report(percent)
318
356
 
319
357
  if not success and status != "processing":
320
358
  raise DatalabAPIError(f"Processing failed: {error or 'Unknown error'}")
@@ -449,6 +487,7 @@ class AsyncDatalabClient:
449
487
  success = None
450
488
  error = None
451
489
  result_url = None
490
+ progress_percent = None
452
491
 
453
492
  tee_reader = _AsyncIterableReader(
454
493
  self._tee_stream_to_file(resp.content, fd)
@@ -462,6 +501,8 @@ class AsyncDatalabClient:
462
501
  error = value
463
502
  elif prefix == "result_url" and event == "string":
464
503
  result_url = value
504
+ elif prefix == "progress_percent" and event == "number":
505
+ progress_percent = value
465
506
  finally:
466
507
  resp.release()
467
508
 
@@ -488,6 +529,7 @@ class AsyncDatalabClient:
488
529
  status=status,
489
530
  output_path=stream_response_to,
490
531
  error=error,
532
+ progress_percent=progress_percent,
491
533
  )
492
534
  else:
493
535
  return FileResult(
@@ -495,6 +537,7 @@ class AsyncDatalabClient:
495
537
  status=status,
496
538
  output_path=stream_response_to,
497
539
  error=error,
540
+ progress_percent=progress_percent,
498
541
  )
499
542
  finally:
500
543
  if fd is not None:
@@ -597,6 +640,7 @@ class AsyncDatalabClient:
597
640
  extraction_mode=result_data.get("extraction_mode"),
598
641
  segmentation_schema=result_data.get("segmentation_schema"),
599
642
  checkpoint_reused=result_data.get("checkpoint_reused"),
643
+ progress_percent=result_data.get("progress_percent"),
600
644
  )
601
645
 
602
646
  async def _submit_and_poll(
@@ -607,6 +651,8 @@ class AsyncDatalabClient:
607
651
  poll_interval: int = 1,
608
652
  stream_response_to: Optional[Path] = None,
609
653
  json: Optional[Dict[str, Any]] = None,
654
+ on_progress: Optional[ProgressCallback] = None,
655
+ result_transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
610
656
  ) -> Union[Dict[str, Any], FileResult]:
611
657
  """Submit a request and poll for the result.
612
658
 
@@ -624,7 +670,13 @@ class AsyncDatalabClient:
624
670
  initial_data["request_check_url"],
625
671
  max_polls=max_polls,
626
672
  poll_interval=poll_interval,
673
+ on_progress=on_progress,
627
674
  stream_response_to=stream_response_to,
675
+ **(
676
+ {"result_transform": result_transform}
677
+ if result_transform is not None
678
+ else {}
679
+ ),
628
680
  )
629
681
  if isinstance(result, dict):
630
682
  result = dict(result)
@@ -680,6 +732,7 @@ class AsyncDatalabClient:
680
732
  stream_response_to: Optional[Union[str, Path]] = None,
681
733
  max_polls: int = 300,
682
734
  poll_interval: int = 1,
735
+ on_progress: Optional[ProgressCallback] = None,
683
736
  ) -> Union[ConversionResult, FileResult]:
684
737
  """
685
738
  Convert a document to markdown, HTML, JSON, or chunks
@@ -693,6 +746,7 @@ class AsyncDatalabClient:
693
746
  stream_response_to: Optional path to stream raw JSON response to disk
694
747
  max_polls: Maximum number of polling attempts
695
748
  poll_interval: Seconds between polling attempts
749
+ on_progress: Optional callback for increasing estimated percentages (0-100).
696
750
  """
697
751
  resolved_stream_response_to = self._resolve_stream_path(
698
752
  save_output, stream_response_to
@@ -708,6 +762,7 @@ class AsyncDatalabClient:
708
762
  ),
709
763
  max_polls=max_polls,
710
764
  poll_interval=poll_interval,
765
+ on_progress=on_progress,
711
766
  stream_response_to=resolved_stream_response_to,
712
767
  )
713
768
 
@@ -727,6 +782,7 @@ class AsyncDatalabClient:
727
782
  stream_response_to: Optional[Union[str, Path]] = None,
728
783
  max_polls: int = 300,
729
784
  poll_interval: int = 1,
785
+ on_progress: Optional[ProgressCallback] = None,
730
786
  ) -> Union[ConversionResult, FileResult]:
731
787
  """
732
788
  Extract structured data from a document using a JSON schema or saved extraction schema
@@ -742,6 +798,7 @@ class AsyncDatalabClient:
742
798
  stream_response_to: Optional path to stream raw JSON response to disk
743
799
  max_polls: Maximum number of polling attempts
744
800
  poll_interval: Seconds between polling attempts
801
+ on_progress: Optional callback for increasing estimated percentages (0-100).
745
802
  """
746
803
  resolved_stream_response_to = self._resolve_stream_path(
747
804
  save_output, stream_response_to
@@ -780,6 +837,7 @@ class AsyncDatalabClient:
780
837
  ),
781
838
  max_polls=max_polls,
782
839
  poll_interval=poll_interval,
840
+ on_progress=on_progress,
783
841
  stream_response_to=resolved_stream_response_to,
784
842
  )
785
843
 
@@ -799,6 +857,7 @@ class AsyncDatalabClient:
799
857
  stream_response_to: Optional[Union[str, Path]] = None,
800
858
  max_polls: int = 300,
801
859
  poll_interval: int = 1,
860
+ on_progress: Optional[ProgressCallback] = None,
802
861
  ) -> Union[ConversionResult, FileResult]:
803
862
  """
804
863
  Segment a document into sections using a schema
@@ -814,6 +873,7 @@ class AsyncDatalabClient:
814
873
  stream_response_to: Optional path to stream raw JSON response to disk
815
874
  max_polls: Maximum number of polling attempts
816
875
  poll_interval: Seconds between polling attempts
876
+ on_progress: Optional callback for increasing estimated percentages (0-100).
817
877
  """
818
878
  resolved_stream_response_to = self._resolve_stream_path(
819
879
  save_output, stream_response_to
@@ -836,6 +896,7 @@ class AsyncDatalabClient:
836
896
  ),
837
897
  max_polls=max_polls,
838
898
  poll_interval=poll_interval,
899
+ on_progress=on_progress,
839
900
  stream_response_to=resolved_stream_response_to,
840
901
  )
841
902
 
@@ -855,6 +916,7 @@ class AsyncDatalabClient:
855
916
  stream_response_to: Optional[Union[str, Path]] = None,
856
917
  max_polls: int = 300,
857
918
  poll_interval: int = 1,
919
+ on_progress: Optional[ProgressCallback] = None,
858
920
  ) -> Union[AgentResult, FileResult]:
859
921
  """
860
922
  Run a published agent processor on a document (open beta; API may change).
@@ -871,6 +933,7 @@ class AsyncDatalabClient:
871
933
  stream_response_to: Optional path to stream raw JSON response to disk
872
934
  max_polls: Maximum number of polling attempts
873
935
  poll_interval: Seconds between polling attempts
936
+ on_progress: Optional callback for increasing estimated percentages (0-100).
874
937
  """
875
938
  resolved_stream_response_to = self._resolve_stream_path(
876
939
  save_output, stream_response_to
@@ -886,6 +949,7 @@ class AsyncDatalabClient:
886
949
  ),
887
950
  max_polls=max_polls,
888
951
  poll_interval=poll_interval,
952
+ on_progress=on_progress,
889
953
  stream_response_to=resolved_stream_response_to,
890
954
  )
891
955
 
@@ -919,6 +983,7 @@ class AsyncDatalabClient:
919
983
  request_id=result_data.get("request_id"),
920
984
  result_url=result_data.get("result_url"),
921
985
  expires_in=result_data.get("expires_in"),
986
+ progress_percent=result_data.get("progress_percent"),
922
987
  )
923
988
  self._save_if_requested(result, save_output)
924
989
  return result
@@ -932,6 +997,7 @@ class AsyncDatalabClient:
932
997
  stream_response_to: Optional[Union[str, Path]] = None,
933
998
  max_polls: int = 300,
934
999
  poll_interval: int = 1,
1000
+ on_progress: Optional[ProgressCallback] = None,
935
1001
  ) -> Union[ConversionResult, FileResult]:
936
1002
  """
937
1003
  Execute a custom processor on a document
@@ -947,6 +1013,7 @@ class AsyncDatalabClient:
947
1013
  stream_response_to: Optional path to stream raw JSON response to disk
948
1014
  max_polls: Maximum number of polling attempts
949
1015
  poll_interval: Seconds between polling attempts
1016
+ on_progress: Optional callback for increasing estimated percentages (0-100).
950
1017
  """
951
1018
  warnings.warn(
952
1019
  "run_custom_processor() uses the deprecated /custom-processor endpoint. "
@@ -962,6 +1029,7 @@ class AsyncDatalabClient:
962
1029
  stream_response_to=stream_response_to,
963
1030
  max_polls=max_polls,
964
1031
  poll_interval=poll_interval,
1032
+ on_progress=on_progress,
965
1033
  )
966
1034
 
967
1035
  async def _run_custom_processor(
@@ -973,6 +1041,7 @@ class AsyncDatalabClient:
973
1041
  stream_response_to: Optional[Union[str, Path]] = None,
974
1042
  max_polls: int = 300,
975
1043
  poll_interval: int = 1,
1044
+ on_progress: Optional[ProgressCallback] = None,
976
1045
  ) -> Union[ConversionResult, FileResult]:
977
1046
  resolved_stream_response_to = self._resolve_stream_path(
978
1047
  save_output, stream_response_to
@@ -988,6 +1057,7 @@ class AsyncDatalabClient:
988
1057
  ),
989
1058
  max_polls=max_polls,
990
1059
  poll_interval=poll_interval,
1060
+ on_progress=on_progress,
991
1061
  stream_response_to=resolved_stream_response_to,
992
1062
  )
993
1063
 
@@ -1007,6 +1077,7 @@ class AsyncDatalabClient:
1007
1077
  stream_response_to: Optional[Union[str, Path]] = None,
1008
1078
  max_polls: int = 300,
1009
1079
  poll_interval: int = 1,
1080
+ on_progress: Optional[ProgressCallback] = None,
1010
1081
  ) -> Union[ConversionResult, FileResult]:
1011
1082
  """Execute a custom processor on a document
1012
1083
 
@@ -1027,6 +1098,7 @@ class AsyncDatalabClient:
1027
1098
  stream_response_to=stream_response_to,
1028
1099
  max_polls=max_polls,
1029
1100
  poll_interval=poll_interval,
1101
+ on_progress=on_progress,
1030
1102
  )
1031
1103
 
1032
1104
  async def track_changes(
@@ -1038,6 +1110,7 @@ class AsyncDatalabClient:
1038
1110
  stream_response_to: Optional[Union[str, Path]] = None,
1039
1111
  max_polls: int = 300,
1040
1112
  poll_interval: int = 1,
1113
+ on_progress: Optional[ProgressCallback] = None,
1041
1114
  ) -> Union[ConversionResult, FileResult]:
1042
1115
  """
1043
1116
  Extract tracked changes and comments from DOCX or PDF documents
@@ -1050,6 +1123,7 @@ class AsyncDatalabClient:
1050
1123
  stream_response_to: Optional path to stream raw JSON response to disk
1051
1124
  max_polls: Maximum number of polling attempts
1052
1125
  poll_interval: Seconds between polling attempts
1126
+ on_progress: Optional callback for increasing estimated percentages (0-100).
1053
1127
  """
1054
1128
  resolved_stream_response_to = self._resolve_stream_path(
1055
1129
  save_output, stream_response_to
@@ -1065,6 +1139,7 @@ class AsyncDatalabClient:
1065
1139
  ),
1066
1140
  max_polls=max_polls,
1067
1141
  poll_interval=poll_interval,
1142
+ on_progress=on_progress,
1068
1143
  stream_response_to=resolved_stream_response_to,
1069
1144
  )
1070
1145
 
@@ -1085,6 +1160,7 @@ class AsyncDatalabClient:
1085
1160
  max_polls: int = 300,
1086
1161
  poll_interval: int = 1,
1087
1162
  processing_location: Optional[str] = None,
1163
+ on_progress: Optional[ProgressCallback] = None,
1088
1164
  ) -> Union[CreateDocumentResult, FileResult]:
1089
1165
  """
1090
1166
  Create a DOCX document from markdown with track changes support
@@ -1102,6 +1178,7 @@ class AsyncDatalabClient:
1102
1178
  stream_response_to: Optional path to stream raw JSON response to disk
1103
1179
  max_polls: Maximum number of polling attempts
1104
1180
  poll_interval: Seconds between polling attempts
1181
+ on_progress: Optional callback for increasing estimated percentages (0-100).
1105
1182
  processing_location: Optional residency region, e.g. "eu"
1106
1183
  """
1107
1184
  resolved_stream_response_to = self._resolve_stream_path(
@@ -1122,6 +1199,7 @@ class AsyncDatalabClient:
1122
1199
  json=payload,
1123
1200
  max_polls=max_polls,
1124
1201
  poll_interval=poll_interval,
1202
+ on_progress=on_progress,
1125
1203
  stream_response_to=resolved_stream_response_to,
1126
1204
  )
1127
1205
 
@@ -1141,6 +1219,7 @@ class AsyncDatalabClient:
1141
1219
  request_id=result_data.get("request_id"),
1142
1220
  result_url=result_data.get("result_url"),
1143
1221
  expires_in=result_data.get("expires_in"),
1222
+ progress_percent=result_data.get("progress_percent"),
1144
1223
  )
1145
1224
  self._save_if_requested(result, save_output, bool(result.output_base64))
1146
1225
  return result
@@ -1153,6 +1232,7 @@ class AsyncDatalabClient:
1153
1232
  stream_response_to: Optional[Union[str, Path]] = None,
1154
1233
  max_polls: int = 300,
1155
1234
  poll_interval: int = 1,
1235
+ on_progress: Optional[ProgressCallback] = None,
1156
1236
  ) -> Union[OCRResult, FileResult]:
1157
1237
  """Perform OCR on a document
1158
1238
 
@@ -1177,6 +1257,7 @@ class AsyncDatalabClient:
1177
1257
  data=self.get_form_params(file_path=file_path, options=options),
1178
1258
  max_polls=max_polls,
1179
1259
  poll_interval=poll_interval,
1260
+ on_progress=on_progress,
1180
1261
  stream_response_to=resolved_stream_response_to,
1181
1262
  )
1182
1263
 
@@ -1192,10 +1273,109 @@ class AsyncDatalabClient:
1192
1273
  versions=result_data.get("versions"),
1193
1274
  cost_breakdown=result_data.get("cost_breakdown"),
1194
1275
  request_id=result_data.get("request_id"),
1276
+ progress_percent=result_data.get("progress_percent"),
1195
1277
  )
1196
1278
  self._save_if_requested(result, save_output)
1197
1279
  return result
1198
1280
 
1281
+ @staticmethod
1282
+ def _normalize_redaction_result(data: Dict[str, Any]) -> Dict[str, Any]:
1283
+ """Project inline and signed worker results onto the public redaction contract."""
1284
+ result = {
1285
+ key: value
1286
+ for key, value in data.items()
1287
+ if key in RedactResult.__dataclass_fields__
1288
+ }
1289
+ document = (
1290
+ data.get("redacted_document")
1291
+ if "redacted_document" in data
1292
+ else data.get("output_base64")
1293
+ )
1294
+ result["output_base64"] = document or None
1295
+ result["withheld"] = not bool(document)
1296
+ if "redacted_document" in data:
1297
+ checks = [
1298
+ metric
1299
+ for metric in (data.get("verifier_metrics") or [])
1300
+ if isinstance(metric, dict)
1301
+ and metric.get("status") != "pass"
1302
+ and metric.get("severity", "blocking") != "advisory"
1303
+ ]
1304
+ else:
1305
+ checks = data.get("failing_checks") or []
1306
+ result["failing_checks"] = [
1307
+ {"id": check["id"]}
1308
+ for check in checks
1309
+ if isinstance(check, dict) and isinstance(check.get("id"), str)
1310
+ ]
1311
+ for field in ("targets_removed", "targets_not_found"):
1312
+ if result.get(f"{field}_count") is None and isinstance(
1313
+ data.get(field), list
1314
+ ):
1315
+ result[f"{field}_count"] = len(data[field])
1316
+ result["success"] = (
1317
+ bool(document)
1318
+ and data.get("verdict") == "PASS"
1319
+ and not checks
1320
+ and data.get("success") is not False
1321
+ )
1322
+ if result["success"]:
1323
+ result["error"] = None
1324
+ else:
1325
+ result["error"] = (
1326
+ "The PDF is available but did not pass all verification checks. Review failing_checks before using it."
1327
+ if document
1328
+ else "No redacted PDF is available. See failing_checks for verification results."
1329
+ )
1330
+ if result.get("progress_percent") == 100:
1331
+ result["progress_percent"] = None
1332
+ return result
1333
+
1334
+ async def redact(
1335
+ self,
1336
+ file_path: Optional[Union[str, Path]] = None,
1337
+ file_url: Optional[str] = None,
1338
+ options: Optional[RedactOptions] = None,
1339
+ save_output: Optional[Union[str, Path]] = None,
1340
+ max_polls: int = 300,
1341
+ poll_interval: int = 1,
1342
+ on_progress: Optional[ProgressCallback] = None,
1343
+ ) -> RedactResult:
1344
+ """Redact a PDF or image. Inspect verdict/failing_checks before use.
1345
+
1346
+ A completed request can return success=False and an available PDF.
1347
+ save_output saves that PDF too. Completed runs are charged even when
1348
+ verification fails. Redaction reviews the whole document.
1349
+ """
1350
+ result_data = await self._submit_and_poll(
1351
+ "/api/v1/redact",
1352
+ data=self.get_form_params(
1353
+ file_path=file_path,
1354
+ file_url=file_url,
1355
+ options=options if options is not None else RedactOptions(),
1356
+ ),
1357
+ max_polls=max_polls,
1358
+ poll_interval=poll_interval,
1359
+ result_transform=self._normalize_redaction_result,
1360
+ on_progress=on_progress,
1361
+ )
1362
+ result = RedactResult(
1363
+ **{
1364
+ key: value
1365
+ for key, value in result_data.items()
1366
+ if key in RedactResult.__dataclass_fields__
1367
+ }
1368
+ )
1369
+ if save_output and result.output_base64:
1370
+ output_path = Path(save_output)
1371
+ output_path.parent.mkdir(parents=True, exist_ok=True)
1372
+ result.save_output(output_path)
1373
+ return result
1374
+
1375
+ async def get_redaction_presets(self) -> Dict[str, Any]:
1376
+ """Get built-in redaction preset IDs, labels, and specifications."""
1377
+ return await self._make_request("GET", "/api/v1/redact/presets")
1378
+
1199
1379
  async def fill(
1200
1380
  self,
1201
1381
  file_path: Optional[Union[str, Path]] = None,
@@ -1205,6 +1385,7 @@ class AsyncDatalabClient:
1205
1385
  stream_response_to: Optional[Union[str, Path]] = None,
1206
1386
  max_polls: int = 300,
1207
1387
  poll_interval: int = 1,
1388
+ on_progress: Optional[ProgressCallback] = None,
1208
1389
  ) -> Union[FormFillingResult, FileResult]:
1209
1390
  """
1210
1391
  Fill PDF or image forms with provided field data
@@ -1217,6 +1398,7 @@ class AsyncDatalabClient:
1217
1398
  stream_response_to: Optional path to stream raw JSON response to disk
1218
1399
  max_polls: Maximum number of polling attempts
1219
1400
  poll_interval: Seconds between polling attempts
1401
+ on_progress: Optional callback for increasing estimated percentages (0-100).
1220
1402
  """
1221
1403
  resolved_stream_response_to = self._resolve_stream_path(
1222
1404
  save_output, stream_response_to
@@ -1232,6 +1414,7 @@ class AsyncDatalabClient:
1232
1414
  ),
1233
1415
  max_polls=max_polls,
1234
1416
  poll_interval=poll_interval,
1417
+ on_progress=on_progress,
1235
1418
  stream_response_to=resolved_stream_response_to,
1236
1419
  )
1237
1420
 
@@ -1254,6 +1437,7 @@ class AsyncDatalabClient:
1254
1437
  request_id=result_data.get("request_id"),
1255
1438
  result_url=result_data.get("result_url"),
1256
1439
  expires_in=result_data.get("expires_in"),
1440
+ progress_percent=result_data.get("progress_percent"),
1257
1441
  )
1258
1442
  self._save_if_requested(result, save_output, bool(result.output_base64))
1259
1443
  return result
@@ -1267,6 +1451,7 @@ class AsyncDatalabClient:
1267
1451
  stream_response_to: Optional[Union[str, Path]] = None,
1268
1452
  max_polls: int = 300,
1269
1453
  poll_interval: int = 1,
1454
+ on_progress: Optional[ProgressCallback] = None,
1270
1455
  ) -> Union[FormFieldsResult, FileResult]:
1271
1456
  """
1272
1457
  Find the fillable fields on each page of a PDF or image
@@ -1282,6 +1467,7 @@ class AsyncDatalabClient:
1282
1467
  stream_response_to: Optional path to stream raw JSON response to disk
1283
1468
  max_polls: Maximum number of polling attempts
1284
1469
  poll_interval: Seconds between polling attempts
1470
+ on_progress: Optional callback for increasing estimated percentages (0-100).
1285
1471
  """
1286
1472
  resolved_stream_response_to = self._resolve_stream_path(
1287
1473
  save_output, stream_response_to
@@ -1297,6 +1483,7 @@ class AsyncDatalabClient:
1297
1483
  ),
1298
1484
  max_polls=max_polls,
1299
1485
  poll_interval=poll_interval,
1486
+ on_progress=on_progress,
1300
1487
  stream_response_to=resolved_stream_response_to,
1301
1488
  )
1302
1489
 
@@ -1315,6 +1502,7 @@ class AsyncDatalabClient:
1315
1502
  request_id=result_data.get("request_id"),
1316
1503
  result_url=result_data.get("result_url"),
1317
1504
  expires_in=result_data.get("expires_in"),
1505
+ progress_percent=result_data.get("progress_percent"),
1318
1506
  )
1319
1507
  self._save_if_requested(result, save_output)
1320
1508
  return result
@@ -1747,6 +1935,7 @@ class AsyncDatalabClient:
1747
1935
  self,
1748
1936
  file_path: Union[str, Path],
1749
1937
  processing_location: Optional[str] = None,
1938
+ upload_session: Optional[aiohttp.ClientSession] = None,
1750
1939
  ) -> UploadedFileMetadata:
1751
1940
  """
1752
1941
  Internal method to upload a single file to Datalab storage
@@ -1794,14 +1983,23 @@ class AsyncDatalabClient:
1794
1983
 
1795
1984
  # Step 2: Upload file to presigned URL
1796
1985
  try:
1797
- file_data = file_path.read_bytes()
1798
- async with aiohttp.ClientSession() as session:
1799
- async with session.put(
1800
- upload_url,
1801
- data=file_data,
1802
- headers={"Content-Type": mime_type},
1803
- ) as upload_response:
1804
- upload_response.raise_for_status()
1986
+ if upload_session is None:
1987
+ async with self._signed_url_session() as session:
1988
+ with file_path.open("rb") as file_data:
1989
+ async with session.put(
1990
+ upload_url,
1991
+ data=file_data,
1992
+ headers={"Content-Type": mime_type},
1993
+ ) as upload_response:
1994
+ upload_response.raise_for_status()
1995
+ else:
1996
+ with file_path.open("rb") as file_data:
1997
+ async with upload_session.put(
1998
+ upload_url,
1999
+ data=file_data,
2000
+ headers={"Content-Type": mime_type},
2001
+ ) as upload_response:
2002
+ upload_response.raise_for_status()
1805
2003
  except Exception as e:
1806
2004
  raise DatalabFileError(f"Failed to upload file to storage: {str(e)}")
1807
2005
 
@@ -1829,6 +2027,8 @@ class AsyncDatalabClient:
1829
2027
  self,
1830
2028
  file_paths: Union[str, Path, list[Union[str, Path]]],
1831
2029
  processing_location: Optional[str] = None,
2030
+ *,
2031
+ max_concurrency: int = 5,
1832
2032
  ) -> Union[UploadedFileMetadata, list[UploadedFileMetadata]]:
1833
2033
  """
1834
2034
  Upload one or more files to Datalab storage
@@ -1838,10 +2038,12 @@ class AsyncDatalabClient:
1838
2038
  2. Upload the file to the presigned URL
1839
2039
  3. Confirm the upload with the API
1840
2040
 
1841
- Multiple files are uploaded concurrently for better performance.
2041
+ Files stream from disk, with at most max_concurrency uploads in flight.
2042
+ Results preserve the input order.
1842
2043
 
1843
2044
  Args:
1844
2045
  file_paths: Single file path or list of file paths to upload
2046
+ max_concurrency: Maximum concurrent uploads (default: 5, minimum: 1)
1845
2047
  processing_location: Optional residency region (e.g. "eu") for
1846
2048
  the stored file. Use the returned reference as file_url in a
1847
2049
  request with the same processing_location.
@@ -1857,16 +2059,36 @@ class AsyncDatalabClient:
1857
2059
  # Upload multiple files
1858
2060
  metadatas = client.upload_files(["doc1.pdf", "doc2.pdf"])
1859
2061
  """
1860
- # Handle single file path
2062
+ if type(max_concurrency) is not int or max_concurrency < 1:
2063
+ raise DatalabValidationError("max_concurrency must be a positive integer")
2064
+
1861
2065
  if isinstance(file_paths, (str, Path)):
1862
2066
  return await self._upload_single_file(file_paths, processing_location)
2067
+ if not file_paths:
2068
+ return []
1863
2069
 
1864
- # Handle list of file paths
1865
- tasks = [
1866
- self._upload_single_file(file_path, processing_location)
1867
- for file_path in file_paths
1868
- ]
1869
- return await asyncio.gather(*tasks)
2070
+ results = [None] * len(file_paths)
2071
+ pending = iter(enumerate(file_paths))
2072
+ async with self._signed_url_session() as session:
2073
+
2074
+ async def upload_worker():
2075
+ for index, file_path in pending:
2076
+ results[index] = await self._upload_single_file(
2077
+ file_path, processing_location, upload_session=session
2078
+ )
2079
+
2080
+ workers = [
2081
+ asyncio.create_task(upload_worker())
2082
+ for _ in range(min(max_concurrency, len(file_paths)))
2083
+ ]
2084
+ try:
2085
+ await asyncio.gather(*workers)
2086
+ finally:
2087
+ # Do not leave uploads running after a failure or cancellation.
2088
+ for worker in workers:
2089
+ worker.cancel()
2090
+ await asyncio.gather(*workers, return_exceptions=True)
2091
+ return results
1870
2092
 
1871
2093
  async def list_files(
1872
2094
  self,
@@ -2331,6 +2553,7 @@ class AsyncDatalabClient:
2331
2553
  poll_interval: int = 1,
2332
2554
  checkpoint_id: Optional[str] = None,
2333
2555
  processing_location: Optional[str] = None,
2556
+ on_progress: Optional[ProgressCallback] = None,
2334
2557
  ) -> PipelineExecution:
2335
2558
  """
2336
2559
  Execute a pipeline on a file
@@ -2346,6 +2569,7 @@ class AsyncDatalabClient:
2346
2569
  version: Pipeline version to execute (0=draft, omit=active)
2347
2570
  max_polls: Maximum polling attempts after submission (default: 1)
2348
2571
  poll_interval: Seconds between polls
2572
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2349
2573
  checkpoint_id: Checkpoint from the convert step of an earlier run.
2350
2574
  The API skips re-parsing and runs only the later steps. You
2351
2575
  must still send the file.
@@ -2371,6 +2595,10 @@ class AsyncDatalabClient:
2371
2595
  f"/api/v1/pipelines/{pipeline_id}/run", data=form_data
2372
2596
  )
2373
2597
  execution = self._build_pipeline_execution(response)
2598
+ progress = _ProgressReporter(on_progress)
2599
+ await progress.report(
2600
+ execution.progress_percent, complete=execution.status == "completed"
2601
+ )
2374
2602
 
2375
2603
  # Poll if requested
2376
2604
  if max_polls > 1 and execution.status not in (
@@ -2378,10 +2606,15 @@ class AsyncDatalabClient:
2378
2606
  "completed_with_errors",
2379
2607
  "failed",
2380
2608
  ):
2609
+
2610
+ async def forward_progress(percent: int) -> None:
2611
+ await progress.report(percent, complete=percent == 100)
2612
+
2381
2613
  return await self.get_pipeline_execution(
2382
2614
  execution.execution_id,
2383
2615
  max_polls=max_polls - 1,
2384
2616
  poll_interval=poll_interval,
2617
+ on_progress=forward_progress,
2385
2618
  )
2386
2619
  return execution
2387
2620
 
@@ -2390,6 +2623,7 @@ class AsyncDatalabClient:
2390
2623
  execution_id: str,
2391
2624
  max_polls: int = 1,
2392
2625
  poll_interval: int = 1,
2626
+ on_progress: Optional[ProgressCallback] = None,
2393
2627
  ) -> PipelineExecution:
2394
2628
  """
2395
2629
  Get the status of a pipeline execution, optionally polling until completion
@@ -2398,12 +2632,17 @@ class AsyncDatalabClient:
2398
2632
  execution_id: Execution ID (pex_XXXXX)
2399
2633
  max_polls: Maximum polling attempts (default: 1 for single check)
2400
2634
  poll_interval: Seconds between polls
2635
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2401
2636
  """
2637
+ progress = _ProgressReporter(on_progress)
2402
2638
  for i in range(max_polls):
2403
2639
  response = await self._make_request(
2404
2640
  "GET", f"/api/v1/pipelines/executions/{execution_id}"
2405
2641
  )
2406
2642
  execution = self._build_pipeline_execution(response)
2643
+ await progress.report(
2644
+ execution.progress_percent, complete=execution.status == "completed"
2645
+ )
2407
2646
 
2408
2647
  if execution.status in ("completed", "completed_with_errors", "failed"):
2409
2648
  return execution
@@ -2480,6 +2719,7 @@ class AsyncDatalabClient:
2480
2719
  checkpoint_id=s.get("checkpoint_id"),
2481
2720
  source_step_type=s.get("source_step_type"),
2482
2721
  checkpoint_reused=s.get("checkpoint_reused"),
2722
+ progress_percent=s.get("progress_percent"),
2483
2723
  )
2484
2724
  for s in data.get("steps", [])
2485
2725
  ]
@@ -2495,6 +2735,7 @@ class AsyncDatalabClient:
2495
2735
  config_snapshot=data.get("config_snapshot"),
2496
2736
  input_config=data.get("input_config"),
2497
2737
  rate_breakdown=data.get("rate_breakdown"),
2738
+ progress_percent=data.get("progress_percent"),
2498
2739
  )
2499
2740
 
2500
2741
  # --- Custom Processor Management methods ---
@@ -2620,10 +2861,19 @@ class DatalabClient:
2620
2861
  """Run async coroutine in sync context"""
2621
2862
  try:
2622
2863
  loop = asyncio.get_event_loop()
2623
- return loop.run_until_complete(self._async_wrapper(coro))
2624
2864
  except RuntimeError:
2625
- # No event loop exists, create and clean up
2865
+ # Only a missing loop should select asyncio.run. RuntimeError from
2866
+ # the operation itself must propagate without rerunning it.
2626
2867
  return asyncio.run(self._async_wrapper(coro))
2868
+ if loop.is_running():
2869
+ coro.close()
2870
+ raise RuntimeError(
2871
+ "DatalabClient cannot run inside an active event loop; "
2872
+ "use AsyncDatalabClient instead."
2873
+ )
2874
+ if loop.is_closed():
2875
+ return asyncio.run(self._async_wrapper(coro))
2876
+ return loop.run_until_complete(self._async_wrapper(coro))
2627
2877
 
2628
2878
  async def _async_wrapper(self, coro):
2629
2879
  """Wrapper to ensure session management"""
@@ -2639,6 +2889,7 @@ class DatalabClient:
2639
2889
  stream_response_to: Optional[Union[str, Path]] = None,
2640
2890
  max_polls: int = 300,
2641
2891
  poll_interval: int = 1,
2892
+ on_progress: Optional[ProgressCallback] = None,
2642
2893
  ) -> Union[ConversionResult, FileResult]:
2643
2894
  """
2644
2895
  Convert a document to markdown, HTML, JSON, or chunks (sync version)
@@ -2651,6 +2902,7 @@ class DatalabClient:
2651
2902
  stream_response_to: Optional path to stream raw JSON response to disk
2652
2903
  max_polls: Maximum number of polling attempts
2653
2904
  poll_interval: Seconds between polling attempts
2905
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2654
2906
  """
2655
2907
  return self._run_async(
2656
2908
  self._async_client.convert(
@@ -2661,6 +2913,7 @@ class DatalabClient:
2661
2913
  stream_response_to=stream_response_to,
2662
2914
  max_polls=max_polls,
2663
2915
  poll_interval=poll_interval,
2916
+ on_progress=on_progress,
2664
2917
  )
2665
2918
  )
2666
2919
 
@@ -2673,6 +2926,7 @@ class DatalabClient:
2673
2926
  stream_response_to: Optional[Union[str, Path]] = None,
2674
2927
  max_polls: int = 300,
2675
2928
  poll_interval: int = 1,
2929
+ on_progress: Optional[ProgressCallback] = None,
2676
2930
  ) -> Union[ConversionResult, FileResult]:
2677
2931
  """
2678
2932
  Extract structured data using a JSON schema or saved extraction schema (sync version)
@@ -2685,6 +2939,7 @@ class DatalabClient:
2685
2939
  stream_response_to: Optional path to stream raw JSON response to disk
2686
2940
  max_polls: Maximum number of polling attempts
2687
2941
  poll_interval: Seconds between polling attempts
2942
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2688
2943
  """
2689
2944
  return self._run_async(
2690
2945
  self._async_client.extract(
@@ -2695,6 +2950,7 @@ class DatalabClient:
2695
2950
  stream_response_to=stream_response_to,
2696
2951
  max_polls=max_polls,
2697
2952
  poll_interval=poll_interval,
2953
+ on_progress=on_progress,
2698
2954
  )
2699
2955
  )
2700
2956
 
@@ -2707,6 +2963,7 @@ class DatalabClient:
2707
2963
  stream_response_to: Optional[Union[str, Path]] = None,
2708
2964
  max_polls: int = 300,
2709
2965
  poll_interval: int = 1,
2966
+ on_progress: Optional[ProgressCallback] = None,
2710
2967
  ) -> Union[ConversionResult, FileResult]:
2711
2968
  """
2712
2969
  Segment a document into sections using a schema (sync version)
@@ -2719,6 +2976,7 @@ class DatalabClient:
2719
2976
  stream_response_to: Optional path to stream raw JSON response to disk
2720
2977
  max_polls: Maximum number of polling attempts
2721
2978
  poll_interval: Seconds between polling attempts
2979
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2722
2980
  """
2723
2981
  return self._run_async(
2724
2982
  self._async_client.segment(
@@ -2729,6 +2987,7 @@ class DatalabClient:
2729
2987
  stream_response_to=stream_response_to,
2730
2988
  max_polls=max_polls,
2731
2989
  poll_interval=poll_interval,
2990
+ on_progress=on_progress,
2732
2991
  )
2733
2992
  )
2734
2993
 
@@ -2741,6 +3000,7 @@ class DatalabClient:
2741
3000
  stream_response_to: Optional[Union[str, Path]] = None,
2742
3001
  max_polls: int = 300,
2743
3002
  poll_interval: int = 1,
3003
+ on_progress: Optional[ProgressCallback] = None,
2744
3004
  ) -> Union[ConversionResult, FileResult]:
2745
3005
  """
2746
3006
  Execute a custom processor on a document (sync version)
@@ -2756,6 +3016,7 @@ class DatalabClient:
2756
3016
  stream_response_to: Optional path to stream raw JSON response to disk
2757
3017
  max_polls: Maximum number of polling attempts
2758
3018
  poll_interval: Seconds between polling attempts
3019
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2759
3020
  """
2760
3021
  warnings.warn(
2761
3022
  "run_custom_processor() uses the deprecated /custom-processor endpoint. "
@@ -2772,6 +3033,7 @@ class DatalabClient:
2772
3033
  stream_response_to=stream_response_to,
2773
3034
  max_polls=max_polls,
2774
3035
  poll_interval=poll_interval,
3036
+ on_progress=on_progress,
2775
3037
  )
2776
3038
  )
2777
3039
 
@@ -2784,6 +3046,7 @@ class DatalabClient:
2784
3046
  stream_response_to: Optional[Union[str, Path]] = None,
2785
3047
  max_polls: int = 300,
2786
3048
  poll_interval: int = 1,
3049
+ on_progress: Optional[ProgressCallback] = None,
2787
3050
  ) -> Union[ConversionResult, FileResult]:
2788
3051
  """Execute a custom processor on a document (sync version)
2789
3052
 
@@ -2805,6 +3068,7 @@ class DatalabClient:
2805
3068
  stream_response_to=stream_response_to,
2806
3069
  max_polls=max_polls,
2807
3070
  poll_interval=poll_interval,
3071
+ on_progress=on_progress,
2808
3072
  )
2809
3073
  )
2810
3074
 
@@ -2817,6 +3081,7 @@ class DatalabClient:
2817
3081
  stream_response_to: Optional[Union[str, Path]] = None,
2818
3082
  max_polls: int = 300,
2819
3083
  poll_interval: int = 1,
3084
+ on_progress: Optional[ProgressCallback] = None,
2820
3085
  ) -> Union[ConversionResult, FileResult]:
2821
3086
  """
2822
3087
  Extract and display tracked changes from DOCX documents (sync version)
@@ -2829,6 +3094,7 @@ class DatalabClient:
2829
3094
  stream_response_to: Optional path to stream raw JSON response to disk
2830
3095
  max_polls: Maximum number of polling attempts
2831
3096
  poll_interval: Seconds between polling attempts
3097
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2832
3098
  """
2833
3099
  return self._run_async(
2834
3100
  self._async_client.track_changes(
@@ -2839,6 +3105,7 @@ class DatalabClient:
2839
3105
  stream_response_to=stream_response_to,
2840
3106
  max_polls=max_polls,
2841
3107
  poll_interval=poll_interval,
3108
+ on_progress=on_progress,
2842
3109
  )
2843
3110
  )
2844
3111
 
@@ -2852,6 +3119,7 @@ class DatalabClient:
2852
3119
  max_polls: int = 300,
2853
3120
  poll_interval: int = 1,
2854
3121
  processing_location: Optional[str] = None,
3122
+ on_progress: Optional[ProgressCallback] = None,
2855
3123
  ) -> Union[CreateDocumentResult, FileResult]:
2856
3124
  """
2857
3125
  Create a DOCX document from markdown (sync version)
@@ -2864,6 +3132,7 @@ class DatalabClient:
2864
3132
  stream_response_to: Optional path to stream raw JSON response to disk
2865
3133
  max_polls: Maximum number of polling attempts
2866
3134
  poll_interval: Seconds between polling attempts
3135
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2867
3136
  """
2868
3137
  return self._run_async(
2869
3138
  self._async_client.create_document(
@@ -2874,6 +3143,7 @@ class DatalabClient:
2874
3143
  stream_response_to=stream_response_to,
2875
3144
  max_polls=max_polls,
2876
3145
  poll_interval=poll_interval,
3146
+ on_progress=on_progress,
2877
3147
  processing_location=processing_location,
2878
3148
  )
2879
3149
  )
@@ -2886,6 +3156,7 @@ class DatalabClient:
2886
3156
  stream_response_to: Optional[Union[str, Path]] = None,
2887
3157
  max_polls: int = 300,
2888
3158
  poll_interval: int = 1,
3159
+ on_progress: Optional[ProgressCallback] = None,
2889
3160
  ) -> Union[OCRResult, FileResult]:
2890
3161
  """Perform OCR on a document (sync version)
2891
3162
 
@@ -2900,9 +3171,41 @@ class DatalabClient:
2900
3171
  stream_response_to=stream_response_to,
2901
3172
  max_polls=max_polls,
2902
3173
  poll_interval=poll_interval,
3174
+ on_progress=on_progress,
2903
3175
  )
2904
3176
  )
2905
3177
 
3178
+ def redact(
3179
+ self,
3180
+ file_path: Optional[Union[str, Path]] = None,
3181
+ file_url: Optional[str] = None,
3182
+ options: Optional[RedactOptions] = None,
3183
+ save_output: Optional[Union[str, Path]] = None,
3184
+ max_polls: int = 300,
3185
+ poll_interval: int = 1,
3186
+ on_progress: Optional[ProgressCallback] = None,
3187
+ ) -> RedactResult:
3188
+ """Redact a PDF or image. Inspect verdict/failing_checks before use.
3189
+
3190
+ A failed verification can still return a PDF and incur a charge.
3191
+ save_output saves any available PDF, including failed verification.
3192
+ """
3193
+ return self._run_async(
3194
+ self._async_client.redact(
3195
+ file_path=file_path,
3196
+ file_url=file_url,
3197
+ options=options,
3198
+ save_output=save_output,
3199
+ max_polls=max_polls,
3200
+ poll_interval=poll_interval,
3201
+ on_progress=on_progress,
3202
+ )
3203
+ )
3204
+
3205
+ def get_redaction_presets(self) -> Dict[str, Any]:
3206
+ """Get built-in redaction preset IDs, labels, and specifications."""
3207
+ return self._run_async(self._async_client.get_redaction_presets())
3208
+
2906
3209
  def fill(
2907
3210
  self,
2908
3211
  file_path: Optional[Union[str, Path]] = None,
@@ -2912,6 +3215,7 @@ class DatalabClient:
2912
3215
  stream_response_to: Optional[Union[str, Path]] = None,
2913
3216
  max_polls: int = 300,
2914
3217
  poll_interval: int = 1,
3218
+ on_progress: Optional[ProgressCallback] = None,
2915
3219
  ) -> Union[FormFillingResult, FileResult]:
2916
3220
  """
2917
3221
  Fill PDF or image forms with provided field data (sync version)
@@ -2924,6 +3228,7 @@ class DatalabClient:
2924
3228
  stream_response_to: Optional path to stream raw JSON response to disk
2925
3229
  max_polls: Maximum number of polling attempts
2926
3230
  poll_interval: Seconds between polling attempts
3231
+ on_progress: Optional callback for increasing estimated percentages (0-100).
2927
3232
  """
2928
3233
  return self._run_async(
2929
3234
  self._async_client.fill(
@@ -2934,6 +3239,7 @@ class DatalabClient:
2934
3239
  stream_response_to=stream_response_to,
2935
3240
  max_polls=max_polls,
2936
3241
  poll_interval=poll_interval,
3242
+ on_progress=on_progress,
2937
3243
  )
2938
3244
  )
2939
3245
 
@@ -2946,6 +3252,7 @@ class DatalabClient:
2946
3252
  stream_response_to: Optional[Union[str, Path]] = None,
2947
3253
  max_polls: int = 300,
2948
3254
  poll_interval: int = 1,
3255
+ on_progress: Optional[ProgressCallback] = None,
2949
3256
  ) -> Union[AgentResult, FileResult]:
2950
3257
  """Run a published agent processor on a document (sync version)"""
2951
3258
  return self._run_async(
@@ -2957,6 +3264,7 @@ class DatalabClient:
2957
3264
  stream_response_to=stream_response_to,
2958
3265
  max_polls=max_polls,
2959
3266
  poll_interval=poll_interval,
3267
+ on_progress=on_progress,
2960
3268
  )
2961
3269
  )
2962
3270
 
@@ -2969,6 +3277,7 @@ class DatalabClient:
2969
3277
  stream_response_to: Optional[Union[str, Path]] = None,
2970
3278
  max_polls: int = 300,
2971
3279
  poll_interval: int = 1,
3280
+ on_progress: Optional[ProgressCallback] = None,
2972
3281
  ) -> Union[FormFieldsResult, FileResult]:
2973
3282
  """Find the fillable fields in a PDF or image (sync version)"""
2974
3283
  return self._run_async(
@@ -2980,6 +3289,7 @@ class DatalabClient:
2980
3289
  stream_response_to=stream_response_to,
2981
3290
  max_polls=max_polls,
2982
3291
  poll_interval=poll_interval,
3292
+ on_progress=on_progress,
2983
3293
  )
2984
3294
  )
2985
3295
 
@@ -3069,6 +3379,8 @@ class DatalabClient:
3069
3379
  self,
3070
3380
  file_paths: Union[str, Path, list[Union[str, Path]]],
3071
3381
  processing_location: Optional[str] = None,
3382
+ *,
3383
+ max_concurrency: int = 5,
3072
3384
  ) -> Union[UploadedFileMetadata, list[UploadedFileMetadata]]:
3073
3385
  """
3074
3386
  Upload one or more files to Datalab storage (sync version)
@@ -3078,10 +3390,12 @@ class DatalabClient:
3078
3390
  2. Upload the file to the presigned URL
3079
3391
  3. Confirm the upload with the API
3080
3392
 
3081
- Multiple files are uploaded concurrently for better performance.
3393
+ Files stream from disk, with at most max_concurrency uploads in flight.
3394
+ Results preserve the input order.
3082
3395
 
3083
3396
  Args:
3084
3397
  file_paths: Single file path or list of file paths to upload
3398
+ max_concurrency: Maximum concurrent uploads (default: 5, minimum: 1)
3085
3399
  processing_location: Optional residency region, e.g. "eu"
3086
3400
 
3087
3401
  Returns:
@@ -3097,7 +3411,9 @@ class DatalabClient:
3097
3411
  """
3098
3412
  return self._run_async(
3099
3413
  self._async_client.upload_files(
3100
- file_paths=file_paths, processing_location=processing_location
3414
+ file_paths=file_paths,
3415
+ processing_location=processing_location,
3416
+ max_concurrency=max_concurrency,
3101
3417
  )
3102
3418
  )
3103
3419
 
@@ -3376,6 +3692,7 @@ class DatalabClient:
3376
3692
  poll_interval: int = 1,
3377
3693
  checkpoint_id: Optional[str] = None,
3378
3694
  processing_location: Optional[str] = None,
3695
+ on_progress: Optional[ProgressCallback] = None,
3379
3696
  ) -> PipelineExecution:
3380
3697
  """Execute a pipeline on a file (sync version)"""
3381
3698
  return self._run_async(
@@ -3390,6 +3707,7 @@ class DatalabClient:
3390
3707
  version=version,
3391
3708
  max_polls=max_polls,
3392
3709
  poll_interval=poll_interval,
3710
+ on_progress=on_progress,
3393
3711
  checkpoint_id=checkpoint_id,
3394
3712
  processing_location=processing_location,
3395
3713
  )
@@ -3400,6 +3718,7 @@ class DatalabClient:
3400
3718
  execution_id: str,
3401
3719
  max_polls: int = 1,
3402
3720
  poll_interval: int = 1,
3721
+ on_progress: Optional[ProgressCallback] = None,
3403
3722
  ) -> PipelineExecution:
3404
3723
  """Get pipeline execution status (sync version)"""
3405
3724
  return self._run_async(
@@ -3407,6 +3726,7 @@ class DatalabClient:
3407
3726
  execution_id=execution_id,
3408
3727
  max_polls=max_polls,
3409
3728
  poll_interval=poll_interval,
3729
+ on_progress=on_progress,
3410
3730
  )
3411
3731
  )
3412
3732
 
datalab_sdk/models.py CHANGED
@@ -231,6 +231,24 @@ class OCROptions(ProcessingOptions):
231
231
  processing_location: Optional[str] = None # residency region, e.g. "eu"
232
232
 
233
233
 
234
+ @dataclass
235
+ class RedactOptions:
236
+ """Options for whole-document redaction via /redact.
237
+
238
+ A custom spec replaces matching fields of the preset. Provide goal, rules,
239
+ and keep to override all three fields. Redaction does not support
240
+ page_range/max_pages.
241
+ """
242
+
243
+ preset: Optional[str] = "personal_information"
244
+ redaction_spec: Optional[Union[Dict[str, Any], str]] = None
245
+ skip_cache: bool = False
246
+ processing_location: Optional[str] = None
247
+
248
+ def to_form_data(self) -> Dict[str, Any]:
249
+ return ProcessingOptions.to_form_data(self)
250
+
251
+
234
252
  @dataclass
235
253
  class FormFillingOptions(ProcessingOptions):
236
254
  """Options for form filling via the /fill endpoint.
@@ -339,6 +357,7 @@ class ConversionResult:
339
357
  segmentation_schema: Optional[str] = None
340
358
  # True when the run reused a checkpoint of the same file.
341
359
  checkpoint_reused: Optional[bool] = None
360
+ progress_percent: Optional[int] = None
342
361
 
343
362
  def save_output(
344
363
  self, output_path: Union[str, Path], save_images: bool = True
@@ -538,6 +557,7 @@ class OCRResult:
538
557
  versions: Optional[Union[Dict[str, Any], str]] = None
539
558
  cost_breakdown: Optional[Dict[str, Any]] = None
540
559
  request_id: Optional[str] = None
560
+ progress_percent: Optional[int] = None
541
561
 
542
562
  def get_text(self, page_num: Optional[int] = None) -> str:
543
563
  """Extract text from OCR results"""
@@ -580,6 +600,44 @@ class OCRResult:
580
600
  )
581
601
 
582
602
 
603
+ @dataclass
604
+ class RedactResult:
605
+ """Redacted PDF and verification report.
606
+
607
+ A completed request can return success=False and an available PDF.
608
+ Inspect verdict and failing_checks before using or sharing the PDF.
609
+ """
610
+
611
+ status: str
612
+ success: Optional[bool] = None
613
+ error: Optional[str] = None
614
+ verdict: Optional[str] = None
615
+ withheld: Optional[bool] = None
616
+ output_base64: Optional[str] = None
617
+ targets_removed_count: Optional[int] = None
618
+ targets_not_found_count: Optional[int] = None
619
+ failing_checks: Optional[List[Dict[str, Any]]] = None
620
+ boxes_applied: Optional[int] = None
621
+ pages_rewritten: Optional[List[int]] = None
622
+ text_layer_skipped: Optional[List[int]] = None
623
+ runtime: Optional[float] = None
624
+ page_count: Optional[int] = None
625
+ cost_breakdown: Optional[Dict[str, Any]] = None
626
+ versions: Optional[Union[Dict[str, Any], str]] = None
627
+ request_id: Optional[str] = None
628
+ result_url: Optional[str] = None
629
+ expires_in: Optional[int] = None
630
+ progress_percent: Optional[int] = None
631
+
632
+ def save_output(self, output_path: Union[str, Path]) -> None:
633
+ """Save the available PDF, including one that failed verification."""
634
+ if not self.output_base64:
635
+ raise ValueError("No output data available to save")
636
+ Path(output_path).with_suffix(".pdf").write_bytes(
637
+ base64.b64decode(self.output_base64)
638
+ )
639
+
640
+
583
641
  @dataclass
584
642
  class FormFillingResult:
585
643
  """Result from form filling"""
@@ -603,6 +661,7 @@ class FormFillingResult:
603
661
  request_id: Optional[str] = None
604
662
  result_url: Optional[str] = None
605
663
  expires_in: Optional[int] = None
664
+ progress_percent: Optional[int] = None
606
665
 
607
666
  def save_output(self, output_path: Union[str, Path]) -> None:
608
667
  """Save the filled form to a file"""
@@ -660,6 +719,7 @@ class CreateDocumentResult:
660
719
  request_id: Optional[str] = None
661
720
  result_url: Optional[str] = None
662
721
  expires_in: Optional[int] = None
722
+ progress_percent: Optional[int] = None
663
723
 
664
724
  def save_output(self, output_path: Union[str, Path]) -> None:
665
725
  """Save the created document to a file"""
@@ -704,6 +764,7 @@ class AgentResult:
704
764
  request_id: Optional[str] = None
705
765
  result_url: Optional[str] = None
706
766
  expires_in: Optional[int] = None
767
+ progress_percent: Optional[int] = None
707
768
 
708
769
  def save_output(
709
770
  self, output_path: Union[str, Path], save_images: bool = True
@@ -761,6 +822,7 @@ class FormFieldsResult:
761
822
  request_id: Optional[str] = None
762
823
  result_url: Optional[str] = None
763
824
  expires_in: Optional[int] = None
825
+ progress_percent: Optional[int] = None
764
826
 
765
827
  def save_output(self, output_path: Union[str, Path]) -> None:
766
828
  """Save the detected fields to a JSON file"""
@@ -806,6 +868,7 @@ class FileResult:
806
868
  status: str
807
869
  output_path: Path
808
870
  error: Optional[str] = None
871
+ progress_percent: Optional[int] = None
809
872
 
810
873
 
811
874
  # --- Extraction Schema models ---
@@ -894,6 +957,7 @@ class PipelineExecutionStepResult:
894
957
  checkpoint_id: Optional[str] = None
895
958
  source_step_type: Optional[str] = None # for eval steps: the step it scores
896
959
  checkpoint_reused: Optional[bool] = None
960
+ progress_percent: Optional[int] = None
897
961
 
898
962
 
899
963
  @dataclass
@@ -911,6 +975,7 @@ class PipelineExecution:
911
975
  config_snapshot: Optional[Dict[str, Any]] = None
912
976
  input_config: Optional[Dict[str, Any]] = None
913
977
  rate_breakdown: Optional[Dict[str, Any]] = None
978
+ progress_percent: Optional[int] = None
914
979
 
915
980
 
916
981
  # --- Custom Processor models ---
@@ -1,13 +0,0 @@
1
- datalab_sdk/__init__.py,sha256=BLAqVuqjxhdjKabkDUePLSmGeVMo0BnWfVbLDt8haP4,2397
2
- datalab_sdk/auth.py,sha256=X2eccKzpdxogFEDoS4geOHIOeECQ8u3kANxKoqF0PVk,4388
3
- datalab_sdk/cli.py,sha256=icUy91brz0J8hzvC1G-pBtZPszc5oRd4H3sEpYhKr7Y,54186
4
- datalab_sdk/client.py,sha256=aNPW4_gUdyW7UbLHI3YRzPA_Ae2dQmlQwCV38qsw0hA,125702
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=OpiIAdOVcL2tdfBkzRNHZ8MjGjRiBSjaKtFVf_U1l8w,32494
8
- datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
9
- datalab_python_sdk-0.7.1.dist-info/METADATA,sha256=KKadqmtZLF5X_jHCATFjk2Fm1BWm8qj68S48EQ4SeTo,6963
10
- datalab_python_sdk-0.7.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
- datalab_python_sdk-0.7.1.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
12
- datalab_python_sdk-0.7.1.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
13
- datalab_python_sdk-0.7.1.dist-info/RECORD,,