datalab-python-sdk 0.10.0__py3-none-any.whl → 0.12.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.10.0
3
+ Version: 0.12.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
@@ -182,8 +182,8 @@ Published-agent execution is in open beta; the API may change. Processor design
182
182
  ## Inputs, polling and errors
183
183
 
184
184
  - 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`.
185
- - 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.
186
- - 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.
185
+ - 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. It returns a `FileResult` with the status, `output_path` and, when the poll response sends them, `request_id`, `page_count`, `parse_quality_score`, `versions`, `runtime` and `cost_breakdown`.
186
+ - The SDK retries a submission that gets HTTP 429 or 503, and polls or result downloads that get 408, 429, 5xx or a connection error, including one that happens while a result streams. It waits for the `Retry-After` header when the API sends one.
187
187
  - 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`.
188
188
 
189
189
  With SDK 0.9.0, `upload_files(paths, max_concurrency=5)` streams
@@ -0,0 +1,13 @@
1
+ datalab_sdk/__init__.py,sha256=bgRAkvlqFmwVdUpZjPf4LfPDzkDM7GLq3FszGKAUn68,3321
2
+ datalab_sdk/auth.py,sha256=X2eccKzpdxogFEDoS4geOHIOeECQ8u3kANxKoqF0PVk,4388
3
+ datalab_sdk/cli.py,sha256=g_qR_xMJS19PYVOf19HRD3nl3GnzHf1bIohh7WY5AO0,63928
4
+ datalab_sdk/client.py,sha256=201rfE-nC-zlpSS0Chx1JBJgueNzk1fBjBR04wkv0ZY,161558
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=j6UruxDaGp1gfcc7YHMNr7ZUg6ez0Jx-8gzJ18efNkQ,43374
8
+ datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
9
+ datalab_python_sdk-0.12.0.dist-info/METADATA,sha256=wuvbL-9NIxLo8wNQfKyedBIldXogEzP5t-a4iZywyvI,10297
10
+ datalab_python_sdk-0.12.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ datalab_python_sdk-0.12.0.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
12
+ datalab_python_sdk-0.12.0.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
13
+ datalab_python_sdk-0.12.0.dist-info/RECORD,,
datalab_sdk/__init__.py CHANGED
@@ -52,6 +52,16 @@ from .models import (
52
52
  PipelineExecutionStepResult,
53
53
  CustomProcessor,
54
54
  CustomProcessorVersion,
55
+ Comparison,
56
+ ComparisonDifference,
57
+ ComparisonDifferences,
58
+ ComparisonField,
59
+ ComparisonDocumentResult,
60
+ ComparisonFile,
61
+ ComparisonList,
62
+ ComparisonVariant,
63
+ ComparisonVariantResult,
64
+ # Deprecated aliases of the Comparison models (SDK 0.10.0 names).
55
65
  Eval,
56
66
  EvalDifference,
57
67
  EvalDifferences,
@@ -111,6 +121,15 @@ __all__ = [
111
121
  "PipelineExecutionStepResult",
112
122
  "CustomProcessor",
113
123
  "CustomProcessorVersion",
124
+ "Comparison",
125
+ "ComparisonDifference",
126
+ "ComparisonDifferences",
127
+ "ComparisonField",
128
+ "ComparisonDocumentResult",
129
+ "ComparisonFile",
130
+ "ComparisonList",
131
+ "ComparisonVariant",
132
+ "ComparisonVariantResult",
114
133
  "Eval",
115
134
  "EvalDifference",
116
135
  "EvalDifferences",
datalab_sdk/cli.py CHANGED
@@ -26,7 +26,7 @@ from datalab_sdk.models import (
26
26
  ProcessingOptions,
27
27
  WorkflowStep,
28
28
  InputConfig,
29
- EvalVariant,
29
+ ComparisonVariant,
30
30
  )
31
31
  from datalab_sdk.exceptions import DatalabError
32
32
  from datalab_sdk.settings import settings
@@ -1153,10 +1153,13 @@ def create_document(
1153
1153
  sys.exit(1)
1154
1154
 
1155
1155
 
1156
- # Eval commands (open beta; the API may change)
1156
+ # Compare commands (open beta; the API may change). `datalab eval` is the
1157
+ # deprecated 0.10.0 name of the same commands.
1157
1158
 
1159
+ _LEGACY_EVAL_META = "datalab_legacy_eval"
1158
1160
 
1159
- def _eval_client(api_key: Optional[str], base_url: str) -> DatalabClient:
1161
+
1162
+ def _compare_client(api_key: Optional[str], base_url: str) -> DatalabClient:
1160
1163
  if api_key is None:
1161
1164
  api_key = settings.DATALAB_API_KEY
1162
1165
  if api_key is None:
@@ -1167,12 +1170,31 @@ def _eval_client(api_key: Optional[str], base_url: str) -> DatalabClient:
1167
1170
  return DatalabClient(api_key=api_key, base_url=base_url)
1168
1171
 
1169
1172
 
1170
- def _print_eval_summary(evaluation) -> None:
1173
+ def _legacy_eval() -> bool:
1174
+ """True when the command runs as the deprecated `datalab eval`."""
1175
+ return bool(click.get_current_context().meta.get(_LEGACY_EVAL_META))
1176
+
1177
+
1178
+ def _echo_json(result) -> None:
1179
+ """Print a result as JSON. Under `datalab eval`, use the 0.10.0 keys."""
1180
+ data = dataclasses.asdict(result)
1181
+ if _legacy_eval():
1182
+ if "comparison_id" in data:
1183
+ data = {"eval_id": data.pop("comparison_id"), **data}
1184
+ if "comparisons" in data:
1185
+ data["evals"] = [
1186
+ {"eval_id": c.pop("comparison_id"), **c}
1187
+ for c in data.pop("comparisons")
1188
+ ]
1189
+ click.echo(json.dumps(data, indent=2))
1190
+
1191
+
1192
+ def _print_comparison_summary(comparison) -> None:
1171
1193
  click.echo(
1172
- f"Eval {evaluation.eval_id}: {evaluation.status} "
1173
- f"(pipeline {evaluation.pipeline_id}, compares {evaluation.compared_step})"
1194
+ f"Comparison {comparison.comparison_id}: {comparison.status} "
1195
+ f"(pipeline {comparison.pipeline_id}, compares {comparison.compared_step})"
1174
1196
  )
1175
- for variant in evaluation.variants:
1197
+ for variant in comparison.variants:
1176
1198
  share = f"{variant.share * 100:.0f}%" if variant.share is not None else "n/a"
1177
1199
  rate = (
1178
1200
  f"${variant.rate_per_1000_pages_cents / 100:.2f}/1000 pages"
@@ -1190,33 +1212,46 @@ def _print_eval_summary(evaluation) -> None:
1190
1212
  )
1191
1213
 
1192
1214
 
1193
- eval_option_api_key = click.option("--api_key", required=False, help="Datalab API key")
1194
- eval_option_base_url = click.option(
1215
+ compare_option_api_key = click.option(
1216
+ "--api_key", required=False, help="Datalab API key"
1217
+ )
1218
+ compare_option_base_url = click.option(
1195
1219
  "--base_url", default=settings.DATALAB_HOST, help="API base URL"
1196
1220
  )
1197
- eval_option_json = click.option(
1221
+ compare_option_json = click.option(
1198
1222
  "--json", "json_output", is_flag=True, help="Print the raw result as JSON"
1199
1223
  )
1200
1224
 
1201
1225
 
1202
- @click.group("eval")
1203
- def eval_group():
1226
+ @click.group("compare")
1227
+ def compare_group():
1204
1228
  """[Open beta] Compare pipeline variants, head to head."""
1205
1229
  pass
1206
1230
 
1207
1231
 
1208
- @eval_group.command("run")
1232
+ @click.group("eval", hidden=True)
1233
+ @click.pass_context
1234
+ def eval_group(ctx):
1235
+ """Deprecated: use `datalab compare`."""
1236
+ ctx.meta[_LEGACY_EVAL_META] = True
1237
+ click.echo(
1238
+ "Note: `datalab eval` is deprecated. Use `datalab compare` instead.",
1239
+ err=True,
1240
+ )
1241
+
1242
+
1243
+ @click.command("run")
1209
1244
  @click.argument("paths", nargs=-1, type=click.Path(exists=True))
1210
1245
  @click.option(
1211
1246
  "--pipeline",
1212
1247
  "pipeline_id",
1213
1248
  required=True,
1214
- help="Pipeline ID to evaluate (pl_XXXXX)",
1249
+ help="Pipeline ID to compare (pl_XXXXX)",
1215
1250
  )
1216
1251
  @click.option(
1217
1252
  "--collection_id",
1218
1253
  type=int,
1219
- help="Collection ID to evaluate, instead of FILE paths",
1254
+ help="Collection ID to compare, instead of FILE paths",
1220
1255
  )
1221
1256
  @click.option(
1222
1257
  "--variant-json",
@@ -1229,7 +1264,9 @@ def eval_group():
1229
1264
  "--version", type=int, help="Pipeline version to run (0=draft, omit=active)"
1230
1265
  )
1231
1266
  @click.option(
1232
- "--wait", is_flag=True, help="Poll until the Eval finishes and print a summary"
1267
+ "--wait",
1268
+ is_flag=True,
1269
+ help="Poll until the comparison finishes and print a summary",
1233
1270
  )
1234
1271
  @click.option(
1235
1272
  "--poll_interval", default=10, type=int, help="Seconds between polls with --wait"
@@ -1237,10 +1274,10 @@ def eval_group():
1237
1274
  @click.option(
1238
1275
  "--timeout", default=7200, type=int, help="Maximum seconds to wait with --wait"
1239
1276
  )
1240
- @eval_option_json
1241
- @eval_option_api_key
1242
- @eval_option_base_url
1243
- def eval_run(
1277
+ @compare_option_json
1278
+ @compare_option_api_key
1279
+ @compare_option_base_url
1280
+ def compare_run(
1244
1281
  paths,
1245
1282
  pipeline_id: str,
1246
1283
  collection_id: Optional[int],
@@ -1253,7 +1290,7 @@ def eval_run(
1253
1290
  api_key: Optional[str],
1254
1291
  base_url: str,
1255
1292
  ):
1256
- """[Open beta] Run an Eval: compare pipeline variants on FILE paths or a collection."""
1293
+ """[Open beta] Compare pipeline variants on FILE paths or a collection."""
1257
1294
  try:
1258
1295
  if bool(paths) == bool(collection_id):
1259
1296
  raise click.UsageError(
@@ -1263,10 +1300,11 @@ def eval_run(
1263
1300
  if variants_json is not None:
1264
1301
  data = _load_json_option(variants_json, "--variant-json")
1265
1302
  variants = [
1266
- EvalVariant(name=v["name"], steps=v.get("steps", {})) for v in data
1303
+ ComparisonVariant(name=v["name"], steps=v.get("steps", {}))
1304
+ for v in data
1267
1305
  ]
1268
1306
 
1269
- client = _eval_client(api_key, base_url)
1307
+ client = _compare_client(api_key, base_url)
1270
1308
  file_ids = None
1271
1309
  if paths:
1272
1310
  uploaded = client.upload_files(list(paths))
@@ -1274,7 +1312,7 @@ def eval_run(
1274
1312
  uploaded = [uploaded]
1275
1313
  file_ids = [u.file_id for u in uploaded]
1276
1314
 
1277
- evaluation = client.create_eval(
1315
+ comparison = client.create_comparison(
1278
1316
  pipeline_id,
1279
1317
  file_ids=file_ids,
1280
1318
  collection_id=collection_id,
@@ -1282,51 +1320,55 @@ def eval_run(
1282
1320
  version=version,
1283
1321
  )
1284
1322
  if wait:
1285
- evaluation = client.wait_for_eval(
1286
- evaluation.eval_id, poll_interval=poll_interval, timeout=timeout
1323
+ comparison = client.wait_for_comparison(
1324
+ comparison.comparison_id, poll_interval=poll_interval, timeout=timeout
1287
1325
  )
1288
1326
  if json_output:
1289
- click.echo(json.dumps(dataclasses.asdict(evaluation), indent=2))
1327
+ _echo_json(comparison)
1290
1328
  else:
1291
- _print_eval_summary(evaluation)
1329
+ _print_comparison_summary(comparison)
1292
1330
  elif json_output:
1293
- click.echo(json.dumps(dataclasses.asdict(evaluation), indent=2))
1331
+ _echo_json(comparison)
1294
1332
  else:
1295
- click.echo(f"Eval {evaluation.eval_id} started ({evaluation.status}).")
1296
- click.echo(f"Check it with: datalab eval get {evaluation.eval_id}")
1333
+ click.echo(
1334
+ f"Comparison {comparison.comparison_id} started ({comparison.status})."
1335
+ )
1336
+ click.echo(f"Check it with: datalab compare get {comparison.comparison_id}")
1297
1337
  except DatalabError as e:
1298
1338
  click.echo(f"Error: {e}", err=True)
1299
1339
  sys.exit(1)
1300
1340
 
1301
1341
 
1302
- @eval_group.command("get")
1303
- @click.argument("eval_id", type=int)
1304
- @eval_option_json
1305
- @eval_option_api_key
1306
- @eval_option_base_url
1307
- def eval_get(eval_id: int, json_output: bool, api_key: Optional[str], base_url: str):
1308
- """[Open beta] Get an Eval's status and each variant's result."""
1342
+ @click.command("get")
1343
+ @click.argument("comparison_id", type=int)
1344
+ @compare_option_json
1345
+ @compare_option_api_key
1346
+ @compare_option_base_url
1347
+ def compare_get(
1348
+ comparison_id: int, json_output: bool, api_key: Optional[str], base_url: str
1349
+ ):
1350
+ """[Open beta] Get a comparison's status and each variant's result."""
1309
1351
  try:
1310
- client = _eval_client(api_key, base_url)
1311
- evaluation = client.get_eval(eval_id)
1352
+ client = _compare_client(api_key, base_url)
1353
+ comparison = client.get_comparison(comparison_id)
1312
1354
  if json_output:
1313
- click.echo(json.dumps(dataclasses.asdict(evaluation), indent=2))
1355
+ _echo_json(comparison)
1314
1356
  else:
1315
- _print_eval_summary(evaluation)
1357
+ _print_comparison_summary(comparison)
1316
1358
  except DatalabError as e:
1317
1359
  click.echo(f"Error: {e}", err=True)
1318
1360
  sys.exit(1)
1319
1361
 
1320
1362
 
1321
- @eval_group.command("list")
1322
- @click.option("--pipeline_id", help="Only Evals of this pipeline")
1323
- @click.option("--collection_id", type=int, help="Only Evals of this collection")
1363
+ @click.command("list")
1364
+ @click.option("--pipeline_id", help="Only comparisons of this pipeline")
1365
+ @click.option("--collection_id", type=int, help="Only comparisons of this collection")
1324
1366
  @click.option("--limit", default=20, type=int, help="Maximum number to return")
1325
1367
  @click.option("--offset", default=0, type=int, help="Offset for pagination")
1326
- @eval_option_json
1327
- @eval_option_api_key
1328
- @eval_option_base_url
1329
- def eval_list(
1368
+ @compare_option_json
1369
+ @compare_option_api_key
1370
+ @compare_option_base_url
1371
+ def compare_list(
1330
1372
  pipeline_id: Optional[str],
1331
1373
  collection_id: Optional[int],
1332
1374
  limit: int,
@@ -1335,43 +1377,47 @@ def eval_list(
1335
1377
  api_key: Optional[str],
1336
1378
  base_url: str,
1337
1379
  ):
1338
- """[Open beta] List the team's Evals, newest first."""
1380
+ """[Open beta] List the team's comparisons, newest first."""
1339
1381
  try:
1340
- client = _eval_client(api_key, base_url)
1341
- result = client.list_evals(
1382
+ client = _compare_client(api_key, base_url)
1383
+ result = client.list_comparisons(
1342
1384
  pipeline_id=pipeline_id,
1343
1385
  collection_id=collection_id,
1344
1386
  limit=limit,
1345
1387
  offset=offset,
1346
1388
  )
1347
1389
  if json_output:
1348
- click.echo(json.dumps(dataclasses.asdict(result), indent=2))
1390
+ _echo_json(result)
1349
1391
  else:
1350
- click.echo(f"{result.total} Eval(s):")
1351
- for evaluation in result.evals:
1392
+ click.echo(f"{result.total} comparison(s):")
1393
+ for comparison in result.comparisons:
1352
1394
  click.echo(
1353
- f" {evaluation.eval_id}: {evaluation.status} (pipeline {evaluation.pipeline_id})"
1395
+ f" {comparison.comparison_id}: {comparison.status} (pipeline {comparison.pipeline_id})"
1354
1396
  )
1355
1397
  except DatalabError as e:
1356
1398
  click.echo(f"Error: {e}", err=True)
1357
1399
  sys.exit(1)
1358
1400
 
1359
1401
 
1360
- @eval_group.command("differences")
1361
- @click.argument("eval_id", type=int)
1402
+ @click.command("differences")
1403
+ @click.argument("comparison_id", type=int)
1362
1404
  @click.argument("file_id", type=int)
1363
- @eval_option_json
1364
- @eval_option_api_key
1365
- @eval_option_base_url
1366
- def eval_differences(
1367
- eval_id: int, file_id: int, json_output: bool, api_key: Optional[str], base_url: str
1405
+ @compare_option_json
1406
+ @compare_option_api_key
1407
+ @compare_option_base_url
1408
+ def compare_differences(
1409
+ comparison_id: int,
1410
+ file_id: int,
1411
+ json_output: bool,
1412
+ api_key: Optional[str],
1413
+ base_url: str,
1368
1414
  ):
1369
- """[Open beta] Show where an Eval's variants read one document differently."""
1415
+ """[Open beta] Show where a comparison's variants read one document differently."""
1370
1416
  try:
1371
- client = _eval_client(api_key, base_url)
1372
- result = client.get_eval_differences(eval_id, file_id)
1417
+ client = _compare_client(api_key, base_url)
1418
+ result = client.get_comparison_differences(comparison_id, file_id)
1373
1419
  if json_output:
1374
- click.echo(json.dumps(dataclasses.asdict(result), indent=2))
1420
+ _echo_json(result)
1375
1421
  else:
1376
1422
  click.echo(
1377
1423
  f"File {result.file_id}: variants {', '.join(result.variant_names)}"
@@ -1386,6 +1432,11 @@ def eval_differences(
1386
1432
  sys.exit(1)
1387
1433
 
1388
1434
 
1435
+ for _command in (compare_run, compare_get, compare_list, compare_differences):
1436
+ compare_group.add_command(_command)
1437
+ eval_group.add_command(_command)
1438
+
1439
+
1389
1440
  # Workflow commands
1390
1441
  def _echo_workflows_removed():
1391
1442
  click.echo(
@@ -1894,6 +1945,7 @@ cli.add_command(fill)
1894
1945
  cli.add_command(form_fields)
1895
1946
  cli.add_command(agent)
1896
1947
  cli.add_command(create_document)
1948
+ cli.add_command(compare_group)
1897
1949
  cli.add_command(eval_group)
1898
1950
  cli.add_command(create_workflow)
1899
1951
  cli.add_command(get_workflow)