datalab-python-sdk 0.8.0__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.
- {datalab_python_sdk-0.8.0.dist-info → datalab_python_sdk-0.9.0.dist-info}/METADATA +29 -2
- datalab_python_sdk-0.9.0.dist-info/RECORD +13 -0
- datalab_sdk/__init__.py +4 -0
- datalab_sdk/client.py +211 -20
- datalab_sdk/models.py +56 -0
- datalab_python_sdk-0.8.0.dist-info/RECORD +0 -13
- {datalab_python_sdk-0.8.0.dist-info → datalab_python_sdk-0.9.0.dist-info}/WHEEL +0 -0
- {datalab_python_sdk-0.8.0.dist-info → datalab_python_sdk-0.9.0.dist-info}/entry_points.txt +0 -0
- {datalab_python_sdk-0.8.0.dist-info → datalab_python_sdk-0.9.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datalab-python-sdk
|
|
3
|
-
Version: 0.
|
|
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
|
|
@@ -125,6 +125,30 @@ print(result.extraction_schema_json, result.extraction_score_average)
|
|
|
125
125
|
|
|
126
126
|
When you do not set the parse `mode`, the API picks the parse mode that matches `extraction_mode`.
|
|
127
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
|
+
|
|
128
152
|
## Other endpoints
|
|
129
153
|
|
|
130
154
|
| Method | Endpoint |
|
|
@@ -135,7 +159,6 @@ When you do not set the parse `mode`, the API picks the parse mode that matches
|
|
|
135
159
|
| `form_fields()` | Find the fillable fields in a PDF or image |
|
|
136
160
|
| `track_changes()` | Read tracked changes and comments from DOCX or PDF |
|
|
137
161
|
| `create_document()` | Make a DOCX from markdown with track changes markup |
|
|
138
|
-
| `generate_extraction_schemas()` | Suggest extraction schemas for a saved checkpoint |
|
|
139
162
|
| `delete_result()` | Result deletion, by `result.request_id` |
|
|
140
163
|
| `upload_files()`, `list_files()`, ... | File storage. Pass the returned `datalab://file-...` reference as `file_url` |
|
|
141
164
|
| `create_extraction_schema()`, ... | Saved extraction schemas |
|
|
@@ -152,6 +175,10 @@ Published-agent execution is in open beta; the API may change. Processor design
|
|
|
152
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.
|
|
153
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`.
|
|
154
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
|
+
|
|
155
182
|
## Workflows
|
|
156
183
|
|
|
157
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
|
@@ -43,6 +43,8 @@ from datalab_sdk.models import (
|
|
|
43
43
|
CustomProcessorOptions,
|
|
44
44
|
TrackChangesOptions,
|
|
45
45
|
OCROptions,
|
|
46
|
+
RedactOptions,
|
|
47
|
+
RedactResult,
|
|
46
48
|
FormFillingOptions,
|
|
47
49
|
FormFillingResult,
|
|
48
50
|
FormFieldsOptions,
|
|
@@ -318,6 +320,7 @@ class AsyncDatalabClient:
|
|
|
318
320
|
poll_interval: int = 1,
|
|
319
321
|
stream_response_to: Optional[Path] = None,
|
|
320
322
|
on_progress: Optional[ProgressCallback] = None,
|
|
323
|
+
result_transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
|
|
321
324
|
) -> Union[Dict[str, Any], FileResult]:
|
|
322
325
|
"""Poll for result completion"""
|
|
323
326
|
full_url = (
|
|
@@ -342,6 +345,10 @@ class AsyncDatalabClient:
|
|
|
342
345
|
if status == "complete":
|
|
343
346
|
if not stream_response_to:
|
|
344
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")
|
|
345
352
|
await progress.report(percent, complete=bool(success))
|
|
346
353
|
return result
|
|
347
354
|
|
|
@@ -645,6 +652,7 @@ class AsyncDatalabClient:
|
|
|
645
652
|
stream_response_to: Optional[Path] = None,
|
|
646
653
|
json: Optional[Dict[str, Any]] = None,
|
|
647
654
|
on_progress: Optional[ProgressCallback] = None,
|
|
655
|
+
result_transform: Optional[Callable[[Dict[str, Any]], Dict[str, Any]]] = None,
|
|
648
656
|
) -> Union[Dict[str, Any], FileResult]:
|
|
649
657
|
"""Submit a request and poll for the result.
|
|
650
658
|
|
|
@@ -664,6 +672,11 @@ class AsyncDatalabClient:
|
|
|
664
672
|
poll_interval=poll_interval,
|
|
665
673
|
on_progress=on_progress,
|
|
666
674
|
stream_response_to=stream_response_to,
|
|
675
|
+
**(
|
|
676
|
+
{"result_transform": result_transform}
|
|
677
|
+
if result_transform is not None
|
|
678
|
+
else {}
|
|
679
|
+
),
|
|
667
680
|
)
|
|
668
681
|
if isinstance(result, dict):
|
|
669
682
|
result = dict(result)
|
|
@@ -1265,6 +1278,104 @@ class AsyncDatalabClient:
|
|
|
1265
1278
|
self._save_if_requested(result, save_output)
|
|
1266
1279
|
return result
|
|
1267
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
|
+
|
|
1268
1379
|
async def fill(
|
|
1269
1380
|
self,
|
|
1270
1381
|
file_path: Optional[Union[str, Path]] = None,
|
|
@@ -1824,6 +1935,7 @@ class AsyncDatalabClient:
|
|
|
1824
1935
|
self,
|
|
1825
1936
|
file_path: Union[str, Path],
|
|
1826
1937
|
processing_location: Optional[str] = None,
|
|
1938
|
+
upload_session: Optional[aiohttp.ClientSession] = None,
|
|
1827
1939
|
) -> UploadedFileMetadata:
|
|
1828
1940
|
"""
|
|
1829
1941
|
Internal method to upload a single file to Datalab storage
|
|
@@ -1871,14 +1983,23 @@ class AsyncDatalabClient:
|
|
|
1871
1983
|
|
|
1872
1984
|
# Step 2: Upload file to presigned URL
|
|
1873
1985
|
try:
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
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()
|
|
1882
2003
|
except Exception as e:
|
|
1883
2004
|
raise DatalabFileError(f"Failed to upload file to storage: {str(e)}")
|
|
1884
2005
|
|
|
@@ -1906,6 +2027,8 @@ class AsyncDatalabClient:
|
|
|
1906
2027
|
self,
|
|
1907
2028
|
file_paths: Union[str, Path, list[Union[str, Path]]],
|
|
1908
2029
|
processing_location: Optional[str] = None,
|
|
2030
|
+
*,
|
|
2031
|
+
max_concurrency: int = 5,
|
|
1909
2032
|
) -> Union[UploadedFileMetadata, list[UploadedFileMetadata]]:
|
|
1910
2033
|
"""
|
|
1911
2034
|
Upload one or more files to Datalab storage
|
|
@@ -1915,10 +2038,12 @@ class AsyncDatalabClient:
|
|
|
1915
2038
|
2. Upload the file to the presigned URL
|
|
1916
2039
|
3. Confirm the upload with the API
|
|
1917
2040
|
|
|
1918
|
-
|
|
2041
|
+
Files stream from disk, with at most max_concurrency uploads in flight.
|
|
2042
|
+
Results preserve the input order.
|
|
1919
2043
|
|
|
1920
2044
|
Args:
|
|
1921
2045
|
file_paths: Single file path or list of file paths to upload
|
|
2046
|
+
max_concurrency: Maximum concurrent uploads (default: 5, minimum: 1)
|
|
1922
2047
|
processing_location: Optional residency region (e.g. "eu") for
|
|
1923
2048
|
the stored file. Use the returned reference as file_url in a
|
|
1924
2049
|
request with the same processing_location.
|
|
@@ -1934,16 +2059,36 @@ class AsyncDatalabClient:
|
|
|
1934
2059
|
# Upload multiple files
|
|
1935
2060
|
metadatas = client.upload_files(["doc1.pdf", "doc2.pdf"])
|
|
1936
2061
|
"""
|
|
1937
|
-
|
|
2062
|
+
if type(max_concurrency) is not int or max_concurrency < 1:
|
|
2063
|
+
raise DatalabValidationError("max_concurrency must be a positive integer")
|
|
2064
|
+
|
|
1938
2065
|
if isinstance(file_paths, (str, Path)):
|
|
1939
2066
|
return await self._upload_single_file(file_paths, processing_location)
|
|
2067
|
+
if not file_paths:
|
|
2068
|
+
return []
|
|
1940
2069
|
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
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
|
|
1947
2092
|
|
|
1948
2093
|
async def list_files(
|
|
1949
2094
|
self,
|
|
@@ -2716,10 +2861,19 @@ class DatalabClient:
|
|
|
2716
2861
|
"""Run async coroutine in sync context"""
|
|
2717
2862
|
try:
|
|
2718
2863
|
loop = asyncio.get_event_loop()
|
|
2719
|
-
return loop.run_until_complete(self._async_wrapper(coro))
|
|
2720
2864
|
except RuntimeError:
|
|
2721
|
-
#
|
|
2865
|
+
# Only a missing loop should select asyncio.run. RuntimeError from
|
|
2866
|
+
# the operation itself must propagate without rerunning it.
|
|
2722
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))
|
|
2723
2877
|
|
|
2724
2878
|
async def _async_wrapper(self, coro):
|
|
2725
2879
|
"""Wrapper to ensure session management"""
|
|
@@ -3021,6 +3175,37 @@ class DatalabClient:
|
|
|
3021
3175
|
)
|
|
3022
3176
|
)
|
|
3023
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
|
+
|
|
3024
3209
|
def fill(
|
|
3025
3210
|
self,
|
|
3026
3211
|
file_path: Optional[Union[str, Path]] = None,
|
|
@@ -3194,6 +3379,8 @@ class DatalabClient:
|
|
|
3194
3379
|
self,
|
|
3195
3380
|
file_paths: Union[str, Path, list[Union[str, Path]]],
|
|
3196
3381
|
processing_location: Optional[str] = None,
|
|
3382
|
+
*,
|
|
3383
|
+
max_concurrency: int = 5,
|
|
3197
3384
|
) -> Union[UploadedFileMetadata, list[UploadedFileMetadata]]:
|
|
3198
3385
|
"""
|
|
3199
3386
|
Upload one or more files to Datalab storage (sync version)
|
|
@@ -3203,10 +3390,12 @@ class DatalabClient:
|
|
|
3203
3390
|
2. Upload the file to the presigned URL
|
|
3204
3391
|
3. Confirm the upload with the API
|
|
3205
3392
|
|
|
3206
|
-
|
|
3393
|
+
Files stream from disk, with at most max_concurrency uploads in flight.
|
|
3394
|
+
Results preserve the input order.
|
|
3207
3395
|
|
|
3208
3396
|
Args:
|
|
3209
3397
|
file_paths: Single file path or list of file paths to upload
|
|
3398
|
+
max_concurrency: Maximum concurrent uploads (default: 5, minimum: 1)
|
|
3210
3399
|
processing_location: Optional residency region, e.g. "eu"
|
|
3211
3400
|
|
|
3212
3401
|
Returns:
|
|
@@ -3222,7 +3411,9 @@ class DatalabClient:
|
|
|
3222
3411
|
"""
|
|
3223
3412
|
return self._run_async(
|
|
3224
3413
|
self._async_client.upload_files(
|
|
3225
|
-
file_paths=file_paths,
|
|
3414
|
+
file_paths=file_paths,
|
|
3415
|
+
processing_location=processing_location,
|
|
3416
|
+
max_concurrency=max_concurrency,
|
|
3226
3417
|
)
|
|
3227
3418
|
)
|
|
3228
3419
|
|
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.
|
|
@@ -582,6 +600,44 @@ class OCRResult:
|
|
|
582
600
|
)
|
|
583
601
|
|
|
584
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
|
+
|
|
585
641
|
@dataclass
|
|
586
642
|
class FormFillingResult:
|
|
587
643
|
"""Result from form filling"""
|
|
@@ -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=ULzCKs1EgHQzi7eg2lxHvjZC20AUtVzuFa0YQDz-JSA,132311
|
|
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=SnXQEHh8xro9pvzcZ0tcT1jlS0-zEopzgXP49x7ycZc,32881
|
|
8
|
-
datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
|
|
9
|
-
datalab_python_sdk-0.8.0.dist-info/METADATA,sha256=59jpki5J8TcCcJ2fO7w7w7VWIahfuippcJboYqhcSXU,8136
|
|
10
|
-
datalab_python_sdk-0.8.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
11
|
-
datalab_python_sdk-0.8.0.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
|
|
12
|
-
datalab_python_sdk-0.8.0.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
|
|
13
|
-
datalab_python_sdk-0.8.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|