wherobots-python-sdk 0.7.1__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {wherobots_python_sdk-0.7.1/wherobots_python_sdk.egg-info → wherobots_python_sdk-0.9.0}/PKG-INFO +80 -68
  2. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/README.md +79 -67
  3. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/pyproject.toml +14 -4
  4. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_api.py +72 -42
  5. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_base_client.py +154 -153
  6. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_client.py +241 -75
  7. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_config.py +2 -2
  8. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_enums.py +3 -2
  9. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_files_api.py +46 -54
  10. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_files_drive.py +62 -59
  11. wherobots_python_sdk-0.9.0/tests/test_live_contract.py +64 -0
  12. wherobots_python_sdk-0.9.0/tests/test_models.py +271 -0
  13. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_regressions.py +12 -75
  14. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_security.py +49 -129
  15. wherobots_python_sdk-0.9.0/tests/test_spec_contract.py +84 -0
  16. wherobots_python_sdk-0.9.0/tests/test_task_run_wait.py +470 -0
  17. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_tasks.py +31 -24
  18. wherobots_python_sdk-0.9.0/tests/test_wire.py +149 -0
  19. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/__init__.py +4 -0
  20. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/__version__.py +1 -1
  21. wherobots_python_sdk-0.9.0/wherobots/_wire.py +212 -0
  22. wherobots_python_sdk-0.9.0/wherobots/api/_operations.py +317 -0
  23. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/base.py +74 -84
  24. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/drive.py +59 -53
  25. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/files.py +17 -37
  26. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/runs.py +55 -93
  27. wherobots_python_sdk-0.9.0/wherobots/api/tasks.py +503 -0
  28. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/client.py +151 -162
  29. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/config.py +3 -3
  30. wherobots_python_sdk-0.9.0/wherobots/enums/__init__.py +43 -0
  31. wherobots_python_sdk-0.9.0/wherobots/enums/_generated.py +154 -0
  32. wherobots_python_sdk-0.9.0/wherobots/enums/_handwritten.py +115 -0
  33. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/exceptions.py +40 -1
  34. wherobots_python_sdk-0.9.0/wherobots/models/__init__.py +106 -0
  35. wherobots_python_sdk-0.9.0/wherobots/models/_generated.py +791 -0
  36. wherobots_python_sdk-0.9.0/wherobots/models/_handwritten.py +394 -0
  37. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0/wherobots_python_sdk.egg-info}/PKG-INFO +80 -68
  38. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots_python_sdk.egg-info/SOURCES.txt +12 -2
  39. wherobots_python_sdk-0.7.1/tests/test_models.py +0 -1043
  40. wherobots_python_sdk-0.7.1/wherobots/api/tasks.py +0 -265
  41. wherobots_python_sdk-0.7.1/wherobots/enums.py +0 -183
  42. wherobots_python_sdk-0.7.1/wherobots/models.py +0 -1820
  43. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/LICENSE +0 -0
  44. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/setup.cfg +0 -0
  45. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_client_header.py +0 -0
  46. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_exceptions.py +0 -0
  47. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_init_exports.py +0 -0
  48. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_integration.py +0 -0
  49. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_logger.py +0 -0
  50. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_utils.py +0 -0
  51. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/tests/test_workload_auth.py +0 -0
  52. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/__init__.py +0 -0
  53. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/api/workload_auth.py +0 -0
  54. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/py.typed +0 -0
  55. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/sdk.py +0 -0
  56. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/utils/__init__.py +0 -0
  57. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/utils/client_header.py +0 -0
  58. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/utils/logger.py +0 -0
  59. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots/utils/validation.py +0 -0
  60. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots_python_sdk.egg-info/dependency_links.txt +0 -0
  61. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots_python_sdk.egg-info/requires.txt +0 -0
  62. {wherobots_python_sdk-0.7.1 → wherobots_python_sdk-0.9.0}/wherobots_python_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wherobots-python-sdk
3
- Version: 0.7.1
3
+ Version: 0.9.0
4
4
  Summary: Python SDK for Wherobots (currently covers the Jobs REST API)
5
5
  Author-email: Wherobots <support@wherobots.com>
6
6
  License-Expression: Apache-2.0
@@ -134,7 +134,7 @@ job = WherobotsJob(script="s3://bucket/script.py", name="my-job-001")
134
134
  | `WHEROBOTS_API_KEY` | API key | *(required outside Wherobots)* |
135
135
  | `WHEROBOTS_REGION` | Region override (else org default) | *(none — org default)* |
136
136
  | `WHEROBOTS_API_BASE_URL` | API base URL | `https://api.cloud.wherobots.com` |
137
- | `WHEROBOTS_VERSION` | Wherobots version | `latest` |
137
+ | `WHEROBOTS_VERSION` | Runtime version | *(none, the org preset decides)* |
138
138
  | `WHEROBOTS_REQUEST_TIMEOUT_SECONDS`| HTTP request timeout (seconds) | `30` |
139
139
  | `WHEROBOTS_CLIENT_CHAIN` | Upstream client-attribution chain (see below) | *(none)* |
140
140
  | `WHEROBOTS_ID_TOKEN_PATH` | Workload identity token, set by Wherobots notebooks and jobs | *(none)* |
@@ -165,7 +165,7 @@ config = WherobotsConfig(
165
165
  | `api_key` | `str \| None` | `None` (read from env) |
166
166
  | `region` | `str \| None` | `None` |
167
167
  | `base_url` | `str` | `"https://api.cloud.wherobots.com"` |
168
- | `version` | `str` | `"latest"` |
168
+ | `version` | `str \| None` | `None` (org preset) |
169
169
  | `request_timeout_seconds` | `int` | `30` |
170
170
  | `client_chain` | `str \| None` | `None` |
171
171
 
@@ -212,11 +212,11 @@ WherobotsJob(
212
212
  runtime: str | Runtime | None = None, # Compute size (None -> org default)
213
213
  region: str | Region | None = None, # Region; str passed as-is (None -> org default)
214
214
  api_key: str | None = None, # API key (or env var)
215
- version: str | None = None, # "latest" | "preview"
215
+ version: str | None = None, # "latest" | "preview" (None -> org preset)
216
216
  timeout_seconds: int = 3600, # Job timeout
217
217
  args: list[str] | None = None, # Script arguments
218
218
  spark_configs: dict[str, str] | None = None, # Spark config overrides
219
- dependencies: list[dict] | None = None, # PyPI or file dependencies
219
+ dependencies: list[PyPiDependency | FileDependency] | None = None,
220
220
  spark_driver_disk_gb: int | None = None, # Driver disk size (GB)
221
221
  spark_executor_disk_gb: int | None = None, # Executor disk size (GB)
222
222
  jar_main_class: str | None = None, # Main class (required for JARs)
@@ -234,14 +234,14 @@ WherobotsJob(
234
234
  |--------|---------|-------------|
235
235
  | `submit()` | `str` | Submit the job. Returns the run ID. Idempotent (returns existing ID if already submitted). |
236
236
  | `get_status()` | `RunView` | Get current job status and full details. |
237
- | `get_logs(cursor=0, size=100)` | `LogsResponse` | Fetch a page of log entries. |
237
+ | `get_logs(cursor=None, size=100)` | `LogsResponse` | Fetch a page of log entries. The cursor is an opaque string from `next_page`. |
238
238
  | `get_metrics()` | `RunMetricsResponse` | Fetch CPU/memory metrics for the run. |
239
239
  | `get_cpu_utilization()` | `UtilizationStats` | Aggregated CPU utilization (`latest`, `max`, `avg`, `series`). |
240
240
  | `get_mem_utilization()` | `UtilizationStats` | Aggregated memory utilization (`latest`, `max`, `avg`, `series`). |
241
241
  | `get_cost()` | `float \| None` | Total run cost in USD, or `None` if not yet billed. |
242
242
  | `get_consumed_spatial_units()` | `float \| None` | Spatial Units (SUs) consumed by the run. |
243
243
  | `refresh()` | `RunView` | Re-fetch from the API and update `status`/`name`/`runtime`/`region`/`version` in place. |
244
- | `iter_logs(cursor=0, size=100)` | `Iterator[dict]` | Iterate over all log entries, handling pagination automatically. |
244
+ | `iter_logs(cursor=None, size=100)` | `Iterator[dict]` | Iterate over all log entries, handling pagination automatically. |
245
245
  | `poll_for_logs(follow=True, interval=2.0, log_handler=None, max_errors=10)` | `None` | Poll and print logs. If `follow=True`, continues until job completes. `max_errors` sets the max consecutive transient errors before giving up. |
246
246
  | `cancel()` | `bool` | Request cancellation. Returns `True` on success. |
247
247
  | `wait_for_completion(poll_interval=5.0, stream_logs=True, log_interval=2.0, max_wait_seconds=None)` | `JobStatus` | Block until the job reaches a terminal state. Set `max_wait_seconds` to limit wait time (raises `WherobotsTimeoutError`). |
@@ -268,8 +268,8 @@ with WherobotsJob(script="s3://bucket/script.py", name="my-job") as job:
268
268
  |--------|---------|-------------|
269
269
  | `from_run_id(run_id, api_key=None, ...)` | `WherobotsJob` | Attach to an existing run for read-only log/metric access. No script required. `submit()` is disabled on the returned instance. |
270
270
  | `list_runs(...)` | `RunListPage` | List runs with optional filters. No instance required. |
271
- | `add_pypi_dependency(name, version)` | `dict` | Create a PyPI dependency dict for the `dependencies` parameter. |
272
- | `add_file_dependency(file_path)` | `dict` | Create a file dependency dict (`.jar`, `.whl`, `.zip`, `.json`). Accepts an `s3://` URI or a local path — local paths are auto-uploaded to **managed storage** at `submit()` time. For non-managed destinations, upload via `FilesAPI` first and pass the resulting `s3://` URI. |
271
+ | `add_pypi_dependency(library_name, library_version=None)` | `PyPiDependency` | Create a PyPI dependency for the `dependencies` parameter. |
272
+ | `add_file_dependency(file_path)` | `FileDependency` | Create a file dependency (`.jar`, `.whl`, `.zip`, `.json`). Accepts an `s3://` URI or a local path — local paths are auto-uploaded to **managed storage** at `submit()` time. For non-managed destinations, upload via `FilesAPI` first and pass the resulting `s3://` URI. |
273
273
 
274
274
  #### Attaching to an Existing Run
275
275
 
@@ -477,8 +477,6 @@ A task is a named unit of work, such as RasterFlow inference, that your organiza
477
477
  your organization.
478
478
 
479
479
  ```python
480
- import time
481
-
482
480
  import wherobots
483
481
 
484
482
  with wherobots.Wherobots() as wb:
@@ -488,23 +486,35 @@ with wherobots.Wherobots() as wb:
488
486
  task = wb.tasks.get("my-task")
489
487
  print(task.input_schema) # JSON Schema the inputs must satisfy
490
488
 
491
- started = wb.tasks.run("my-task", {"aoi": "s3://bucket/aoi.geojson"}, name="nightly")
492
- run = wb.task_runs.get(started.task_run_id)
493
- while run.is_active:
494
- time.sleep(10)
495
- run = wb.task_runs.get(run.task_run_id)
489
+ # Start a run and wait for it; raises WherobotsTaskRunError if it does not succeed
490
+ run = wb.tasks.run_and_wait("my-task", {"aoi": "s3://bucket/aoi.geojson"}, name="nightly")
491
+ print(run.output) # the one result of a single-output task; run.results has them all
496
492
 
497
- print(run.state, run.results, run.error_message)
498
493
  print(wb.task_runs.logs(run.task_run_id).entries)
499
494
  print(wb.task_runs.cost(run.task_run_id).total_cost_usd)
495
+
496
+ # Or start a run now and wait for it later
497
+ started = wb.tasks.run("my-task", {"aoi": "s3://bucket/aoi.geojson"})
498
+ run = wb.task_runs.wait_for_completion(started.task_run_id, max_wait_seconds=3600)
500
499
  ```
501
500
 
502
501
  - `tasks.run` uses `region=` if passed, then the configured region, then your organization's
503
502
  default region.
504
503
  - Listings return an `OffsetPage`; pass `page.next_offset` as `offset=` for the next one.
505
- - `TaskRunState.is_active` is `True` for `PENDING`, `SUBMITTED`, `RUNNING` and `CANCELLING`. A
506
- state the SDK does not know yet is kept as its raw string and counts as not active, so a
507
- polling loop stops on it.
504
+ - `TaskRunState.is_active` is `True` for `PENDING`, `SUBMITTED`, `RUNNING` and `CANCELLING`, and
505
+ `is_finished` is `True` for every other state the SDK knows except `UNKNOWN`, which the server
506
+ also reports while a run starts. `wait_for_completion` polls through `UNKNOWN`, and treats it as
507
+ final after 10 minutes in a row. A state the SDK does not know yet is kept as its raw string and
508
+ is neither; `wait_for_completion` logs a warning once and keeps polling through it.
509
+ - `task_runs.wait_for_completion` polls 5 seconds apart at first, backing off to 30 seconds, and
510
+ logs each state change at INFO on the `wherobots` logger. A timeout (`max_wait_seconds`) raises
511
+ `WherobotsTaskRunTimeoutError` (a `WherobotsTimeoutError`) with the run in `.run`, and never
512
+ cancels it: call `wait_for_completion(err.run.task_run_id)` to resume, or `task_runs.cancel` to
513
+ stop it. Interrupting the wait leaves the run going too; the traceback names it. Pass `raise_on_failure=False` to get an unsuccessful run back
514
+ instead of an error.
515
+ - When a platform task succeeds before its results are readable, `wait_for_completion` fetches it
516
+ up to three more times, at the current poll interval. If `results` is still empty, `run.output` raises; fetch the run again
517
+ with `task_runs.get` rather than running the task again. Script tasks never return results.
508
518
  - A run's state can lag the run by up to 2 minutes.
509
519
  - `task_runs.logs` pages forward: pass the previous page's `next_since` as `since=`. It is `None`
510
520
  once the run has finished and every line has been returned.
@@ -597,77 +607,79 @@ job = WherobotsJob(
597
607
 
598
608
  ## Models
599
609
 
600
- All models are Python dataclasses with `from_dict()` and `to_dict()` methods
601
- for JSON round-tripping.
610
+ Models are generated from the Wherobots OpenAPI spec. They are frozen dataclasses built with
611
+ keyword arguments, with `from_dict()` and `to_dict()` for the API's JSON. A missing required field
612
+ or a wrong type raises `WherobotsAPIError`. Unknown fields are ignored, and an enum value newer than
613
+ the SDK still decodes, so `status.value` works for it.
602
614
 
603
615
  ### RunView
604
616
 
605
617
  Returned by `get_status()` and `list_runs()`. Represents a single job run.
606
618
 
607
- | Field | Type | Description |
608
- |--------------------|---------------------------|--------------------------------|
609
- | `id` | `str` | Run ID |
610
- | `name` | `str` | Job name |
611
- | `status` | `JobStatus \| None` | Current status |
612
- | `runtime` | `str \| None` | Compute runtime size |
613
- | `region` | `str \| None` | AWS region |
614
- | `version` | `str \| None` | Wherobots version |
615
- | `timeout_seconds` | `int \| None` | Job timeout |
616
- | `create_time` | `str \| None` | ISO-8601 creation timestamp |
617
- | `update_time` | `str \| None` | ISO-8601 last update timestamp |
618
- | `start_time` | `str \| None` | ISO-8601 start timestamp |
619
- | `complete_time` | `str \| None` | ISO-8601 completion timestamp |
620
- | `run_python` | `RunPythonPayload \| None`| Python script payload |
621
- | `run_jar` | `RunJarPayload \| None` | JAR payload |
622
- | `environment` | `RunEnvironment \| None` | Spark config & dependencies |
623
- | `triggered_by` | `dict \| None` | User who triggered the run |
624
- | `kube_app` | `RunKubeApp \| None` | Kubernetes app details |
625
- | `app_meta` | `RunAppMeta \| None` | Spark/Sedona UI URLs |
626
- | `organization` | `OrganizationCustomer \| None` | Org info |
627
- | `extra` | `dict` | Any additional API fields |
619
+ | Field | Type | Description |
620
+ |-------------------|----------------------------|--------------------------------------------|
621
+ | `id` | `str` | Run ID |
622
+ | `name` | `str` | Job name |
623
+ | `status` | `JobStatus` | Current status |
624
+ | `is_terminal` | `bool` | The run has finished |
625
+ | `create_time` | `datetime` | Creation time |
626
+ | `update_time` | `datetime` | Last update time |
627
+ | `start_time` | `datetime \| None` | Start time |
628
+ | `complete_time` | `datetime \| None` | Completion time |
629
+ | `triggered_by` | `OrganizationCustomer` | User who triggered the run |
630
+ | `kube_app` | `RunKubeApp \| None` | Kubernetes app details |
631
+ | `payload` | `RunPayload` | What the run was created with |
632
+ | `runtime` | `str \| None` | From `payload` |
633
+ | `version` | `str \| None` | From `payload` |
634
+ | `timeout_seconds` | `int` | From `payload` |
635
+ | `run_python` | `RunPythonPayload \| None` | From `payload` |
636
+ | `run_jar` | `RunJarPayload \| None` | From `payload` |
637
+ | `environment` | `ResolvedRunEnvironment \| None` | From `payload` |
638
+ | `region` | `str \| None` | From `kube_app` |
639
+ | `app_meta` | `RunAppMeta \| None` | Spark and Sedona UI URLs, from `kube_app` |
640
+ | `raw` | `dict` | The response body as the server sent it |
628
641
 
629
642
  ### LogsResponse
630
643
 
631
644
  Returned by `get_logs()`.
632
645
 
633
- | Field | Type | Description |
634
- |----------------|------------------------|------------------------------|
635
- | `items` | `list[LogItem]` | Log entries |
636
- | `next_page` | `int \| str \| None` | Next page cursor |
637
- | `current_page` | `int \| str \| None` | Current page cursor |
646
+ | Field | Type | Description |
647
+ |----------------|-----------------|-----------------------------------------------|
648
+ | `items` | `list[LogItem]` | Log entries |
649
+ | `next_page` | `str \| None` | Next page cursor. `None` on a tail page |
650
+ | `current_page` | `str` | Current page cursor |
651
+ | `raw` | `dict` | The response body as the server sent it |
638
652
 
639
653
  ### LogItem
640
654
 
641
- | Field | Type | Description |
642
- |-------------|------------------------|---------------------------------|
643
- | `raw` | `str` | Raw log line text |
644
- | `timestamp` | `int \| str \| None` | Epoch int or ISO-8601 string |
645
- | `level` | `str \| None` | Log level (INFO, ERROR, etc.) |
646
- | `message` | `str \| None` | Parsed message |
647
- | `extra` | `dict` | Additional fields |
655
+ | Field | Type | Description |
656
+ |-------------|-------|-----------------------------------|
657
+ | `raw` | `str` | Raw log line text |
658
+ | `timestamp` | `str` | Epoch nanoseconds, as a string |
648
659
 
649
660
  ### RunListPage
650
661
 
651
662
  Returned by `list_runs()`.
652
663
 
653
- | Field | Type | Description |
654
- |--------------------------|-------------------|--------------------------------|
655
- | `items` | `list[RunView]` | Runs on this page |
656
- | `total` | `int` | Total matching runs |
657
- | `next_page` | `str \| None` | Next page cursor |
658
- | `previous_page` | `str \| None` | Previous page cursor |
659
- | `current_page` | `str \| None` | Current page cursor |
660
- | `current_page_backwards` | `str \| None` | Backward pagination cursor |
664
+ | Field | Type | Description |
665
+ |--------------------------|-----------------|-----------------------------------------|
666
+ | `items` | `list[RunView]` | Runs on this page |
667
+ | `total` | `int` | Total matching runs |
668
+ | `next_page` | `str \| None` | Next page cursor |
669
+ | `previous_page` | `str \| None` | Previous page cursor |
670
+ | `current_page` | `str \| None` | Current page cursor |
671
+ | `current_page_backwards` | `str \| None` | Backward pagination cursor |
672
+ | `raw` | `dict` | The response body as the server sent it |
661
673
 
662
674
  ### RunMetricsResponse
663
675
 
664
676
  Returned by `get_metrics()`.
665
677
 
666
- | Field | Type | Description |
667
- |-------------------|--------|--------------------------|
668
- | `series_metrics` | `dict` | Time-series metrics |
669
- | `instant_metrics` | `dict` | Point-in-time metrics |
670
- | `extra` | `dict` | Additional fields |
678
+ | Field | Type | Description |
679
+ |-------------------|----------------------------------|-----------------------------------------|
680
+ | `series_metrics` | `dict[str, SeriesMetricDetails]` | Time-series metrics |
681
+ | `instant_metrics` | `dict[str, InstantMetricDetails]` | Point-in-time metrics |
682
+ | `raw` | `dict` | The response body as the server sent it |
671
683
 
672
684
  ## Exceptions
673
685
 
@@ -108,7 +108,7 @@ job = WherobotsJob(script="s3://bucket/script.py", name="my-job-001")
108
108
  | `WHEROBOTS_API_KEY` | API key | *(required outside Wherobots)* |
109
109
  | `WHEROBOTS_REGION` | Region override (else org default) | *(none — org default)* |
110
110
  | `WHEROBOTS_API_BASE_URL` | API base URL | `https://api.cloud.wherobots.com` |
111
- | `WHEROBOTS_VERSION` | Wherobots version | `latest` |
111
+ | `WHEROBOTS_VERSION` | Runtime version | *(none, the org preset decides)* |
112
112
  | `WHEROBOTS_REQUEST_TIMEOUT_SECONDS`| HTTP request timeout (seconds) | `30` |
113
113
  | `WHEROBOTS_CLIENT_CHAIN` | Upstream client-attribution chain (see below) | *(none)* |
114
114
  | `WHEROBOTS_ID_TOKEN_PATH` | Workload identity token, set by Wherobots notebooks and jobs | *(none)* |
@@ -139,7 +139,7 @@ config = WherobotsConfig(
139
139
  | `api_key` | `str \| None` | `None` (read from env) |
140
140
  | `region` | `str \| None` | `None` |
141
141
  | `base_url` | `str` | `"https://api.cloud.wherobots.com"` |
142
- | `version` | `str` | `"latest"` |
142
+ | `version` | `str \| None` | `None` (org preset) |
143
143
  | `request_timeout_seconds` | `int` | `30` |
144
144
  | `client_chain` | `str \| None` | `None` |
145
145
 
@@ -186,11 +186,11 @@ WherobotsJob(
186
186
  runtime: str | Runtime | None = None, # Compute size (None -> org default)
187
187
  region: str | Region | None = None, # Region; str passed as-is (None -> org default)
188
188
  api_key: str | None = None, # API key (or env var)
189
- version: str | None = None, # "latest" | "preview"
189
+ version: str | None = None, # "latest" | "preview" (None -> org preset)
190
190
  timeout_seconds: int = 3600, # Job timeout
191
191
  args: list[str] | None = None, # Script arguments
192
192
  spark_configs: dict[str, str] | None = None, # Spark config overrides
193
- dependencies: list[dict] | None = None, # PyPI or file dependencies
193
+ dependencies: list[PyPiDependency | FileDependency] | None = None,
194
194
  spark_driver_disk_gb: int | None = None, # Driver disk size (GB)
195
195
  spark_executor_disk_gb: int | None = None, # Executor disk size (GB)
196
196
  jar_main_class: str | None = None, # Main class (required for JARs)
@@ -208,14 +208,14 @@ WherobotsJob(
208
208
  |--------|---------|-------------|
209
209
  | `submit()` | `str` | Submit the job. Returns the run ID. Idempotent (returns existing ID if already submitted). |
210
210
  | `get_status()` | `RunView` | Get current job status and full details. |
211
- | `get_logs(cursor=0, size=100)` | `LogsResponse` | Fetch a page of log entries. |
211
+ | `get_logs(cursor=None, size=100)` | `LogsResponse` | Fetch a page of log entries. The cursor is an opaque string from `next_page`. |
212
212
  | `get_metrics()` | `RunMetricsResponse` | Fetch CPU/memory metrics for the run. |
213
213
  | `get_cpu_utilization()` | `UtilizationStats` | Aggregated CPU utilization (`latest`, `max`, `avg`, `series`). |
214
214
  | `get_mem_utilization()` | `UtilizationStats` | Aggregated memory utilization (`latest`, `max`, `avg`, `series`). |
215
215
  | `get_cost()` | `float \| None` | Total run cost in USD, or `None` if not yet billed. |
216
216
  | `get_consumed_spatial_units()` | `float \| None` | Spatial Units (SUs) consumed by the run. |
217
217
  | `refresh()` | `RunView` | Re-fetch from the API and update `status`/`name`/`runtime`/`region`/`version` in place. |
218
- | `iter_logs(cursor=0, size=100)` | `Iterator[dict]` | Iterate over all log entries, handling pagination automatically. |
218
+ | `iter_logs(cursor=None, size=100)` | `Iterator[dict]` | Iterate over all log entries, handling pagination automatically. |
219
219
  | `poll_for_logs(follow=True, interval=2.0, log_handler=None, max_errors=10)` | `None` | Poll and print logs. If `follow=True`, continues until job completes. `max_errors` sets the max consecutive transient errors before giving up. |
220
220
  | `cancel()` | `bool` | Request cancellation. Returns `True` on success. |
221
221
  | `wait_for_completion(poll_interval=5.0, stream_logs=True, log_interval=2.0, max_wait_seconds=None)` | `JobStatus` | Block until the job reaches a terminal state. Set `max_wait_seconds` to limit wait time (raises `WherobotsTimeoutError`). |
@@ -242,8 +242,8 @@ with WherobotsJob(script="s3://bucket/script.py", name="my-job") as job:
242
242
  |--------|---------|-------------|
243
243
  | `from_run_id(run_id, api_key=None, ...)` | `WherobotsJob` | Attach to an existing run for read-only log/metric access. No script required. `submit()` is disabled on the returned instance. |
244
244
  | `list_runs(...)` | `RunListPage` | List runs with optional filters. No instance required. |
245
- | `add_pypi_dependency(name, version)` | `dict` | Create a PyPI dependency dict for the `dependencies` parameter. |
246
- | `add_file_dependency(file_path)` | `dict` | Create a file dependency dict (`.jar`, `.whl`, `.zip`, `.json`). Accepts an `s3://` URI or a local path — local paths are auto-uploaded to **managed storage** at `submit()` time. For non-managed destinations, upload via `FilesAPI` first and pass the resulting `s3://` URI. |
245
+ | `add_pypi_dependency(library_name, library_version=None)` | `PyPiDependency` | Create a PyPI dependency for the `dependencies` parameter. |
246
+ | `add_file_dependency(file_path)` | `FileDependency` | Create a file dependency (`.jar`, `.whl`, `.zip`, `.json`). Accepts an `s3://` URI or a local path — local paths are auto-uploaded to **managed storage** at `submit()` time. For non-managed destinations, upload via `FilesAPI` first and pass the resulting `s3://` URI. |
247
247
 
248
248
  #### Attaching to an Existing Run
249
249
 
@@ -451,8 +451,6 @@ A task is a named unit of work, such as RasterFlow inference, that your organiza
451
451
  your organization.
452
452
 
453
453
  ```python
454
- import time
455
-
456
454
  import wherobots
457
455
 
458
456
  with wherobots.Wherobots() as wb:
@@ -462,23 +460,35 @@ with wherobots.Wherobots() as wb:
462
460
  task = wb.tasks.get("my-task")
463
461
  print(task.input_schema) # JSON Schema the inputs must satisfy
464
462
 
465
- started = wb.tasks.run("my-task", {"aoi": "s3://bucket/aoi.geojson"}, name="nightly")
466
- run = wb.task_runs.get(started.task_run_id)
467
- while run.is_active:
468
- time.sleep(10)
469
- run = wb.task_runs.get(run.task_run_id)
463
+ # Start a run and wait for it; raises WherobotsTaskRunError if it does not succeed
464
+ run = wb.tasks.run_and_wait("my-task", {"aoi": "s3://bucket/aoi.geojson"}, name="nightly")
465
+ print(run.output) # the one result of a single-output task; run.results has them all
470
466
 
471
- print(run.state, run.results, run.error_message)
472
467
  print(wb.task_runs.logs(run.task_run_id).entries)
473
468
  print(wb.task_runs.cost(run.task_run_id).total_cost_usd)
469
+
470
+ # Or start a run now and wait for it later
471
+ started = wb.tasks.run("my-task", {"aoi": "s3://bucket/aoi.geojson"})
472
+ run = wb.task_runs.wait_for_completion(started.task_run_id, max_wait_seconds=3600)
474
473
  ```
475
474
 
476
475
  - `tasks.run` uses `region=` if passed, then the configured region, then your organization's
477
476
  default region.
478
477
  - Listings return an `OffsetPage`; pass `page.next_offset` as `offset=` for the next one.
479
- - `TaskRunState.is_active` is `True` for `PENDING`, `SUBMITTED`, `RUNNING` and `CANCELLING`. A
480
- state the SDK does not know yet is kept as its raw string and counts as not active, so a
481
- polling loop stops on it.
478
+ - `TaskRunState.is_active` is `True` for `PENDING`, `SUBMITTED`, `RUNNING` and `CANCELLING`, and
479
+ `is_finished` is `True` for every other state the SDK knows except `UNKNOWN`, which the server
480
+ also reports while a run starts. `wait_for_completion` polls through `UNKNOWN`, and treats it as
481
+ final after 10 minutes in a row. A state the SDK does not know yet is kept as its raw string and
482
+ is neither; `wait_for_completion` logs a warning once and keeps polling through it.
483
+ - `task_runs.wait_for_completion` polls 5 seconds apart at first, backing off to 30 seconds, and
484
+ logs each state change at INFO on the `wherobots` logger. A timeout (`max_wait_seconds`) raises
485
+ `WherobotsTaskRunTimeoutError` (a `WherobotsTimeoutError`) with the run in `.run`, and never
486
+ cancels it: call `wait_for_completion(err.run.task_run_id)` to resume, or `task_runs.cancel` to
487
+ stop it. Interrupting the wait leaves the run going too; the traceback names it. Pass `raise_on_failure=False` to get an unsuccessful run back
488
+ instead of an error.
489
+ - When a platform task succeeds before its results are readable, `wait_for_completion` fetches it
490
+ up to three more times, at the current poll interval. If `results` is still empty, `run.output` raises; fetch the run again
491
+ with `task_runs.get` rather than running the task again. Script tasks never return results.
482
492
  - A run's state can lag the run by up to 2 minutes.
483
493
  - `task_runs.logs` pages forward: pass the previous page's `next_since` as `since=`. It is `None`
484
494
  once the run has finished and every line has been returned.
@@ -571,77 +581,79 @@ job = WherobotsJob(
571
581
 
572
582
  ## Models
573
583
 
574
- All models are Python dataclasses with `from_dict()` and `to_dict()` methods
575
- for JSON round-tripping.
584
+ Models are generated from the Wherobots OpenAPI spec. They are frozen dataclasses built with
585
+ keyword arguments, with `from_dict()` and `to_dict()` for the API's JSON. A missing required field
586
+ or a wrong type raises `WherobotsAPIError`. Unknown fields are ignored, and an enum value newer than
587
+ the SDK still decodes, so `status.value` works for it.
576
588
 
577
589
  ### RunView
578
590
 
579
591
  Returned by `get_status()` and `list_runs()`. Represents a single job run.
580
592
 
581
- | Field | Type | Description |
582
- |--------------------|---------------------------|--------------------------------|
583
- | `id` | `str` | Run ID |
584
- | `name` | `str` | Job name |
585
- | `status` | `JobStatus \| None` | Current status |
586
- | `runtime` | `str \| None` | Compute runtime size |
587
- | `region` | `str \| None` | AWS region |
588
- | `version` | `str \| None` | Wherobots version |
589
- | `timeout_seconds` | `int \| None` | Job timeout |
590
- | `create_time` | `str \| None` | ISO-8601 creation timestamp |
591
- | `update_time` | `str \| None` | ISO-8601 last update timestamp |
592
- | `start_time` | `str \| None` | ISO-8601 start timestamp |
593
- | `complete_time` | `str \| None` | ISO-8601 completion timestamp |
594
- | `run_python` | `RunPythonPayload \| None`| Python script payload |
595
- | `run_jar` | `RunJarPayload \| None` | JAR payload |
596
- | `environment` | `RunEnvironment \| None` | Spark config & dependencies |
597
- | `triggered_by` | `dict \| None` | User who triggered the run |
598
- | `kube_app` | `RunKubeApp \| None` | Kubernetes app details |
599
- | `app_meta` | `RunAppMeta \| None` | Spark/Sedona UI URLs |
600
- | `organization` | `OrganizationCustomer \| None` | Org info |
601
- | `extra` | `dict` | Any additional API fields |
593
+ | Field | Type | Description |
594
+ |-------------------|----------------------------|--------------------------------------------|
595
+ | `id` | `str` | Run ID |
596
+ | `name` | `str` | Job name |
597
+ | `status` | `JobStatus` | Current status |
598
+ | `is_terminal` | `bool` | The run has finished |
599
+ | `create_time` | `datetime` | Creation time |
600
+ | `update_time` | `datetime` | Last update time |
601
+ | `start_time` | `datetime \| None` | Start time |
602
+ | `complete_time` | `datetime \| None` | Completion time |
603
+ | `triggered_by` | `OrganizationCustomer` | User who triggered the run |
604
+ | `kube_app` | `RunKubeApp \| None` | Kubernetes app details |
605
+ | `payload` | `RunPayload` | What the run was created with |
606
+ | `runtime` | `str \| None` | From `payload` |
607
+ | `version` | `str \| None` | From `payload` |
608
+ | `timeout_seconds` | `int` | From `payload` |
609
+ | `run_python` | `RunPythonPayload \| None` | From `payload` |
610
+ | `run_jar` | `RunJarPayload \| None` | From `payload` |
611
+ | `environment` | `ResolvedRunEnvironment \| None` | From `payload` |
612
+ | `region` | `str \| None` | From `kube_app` |
613
+ | `app_meta` | `RunAppMeta \| None` | Spark and Sedona UI URLs, from `kube_app` |
614
+ | `raw` | `dict` | The response body as the server sent it |
602
615
 
603
616
  ### LogsResponse
604
617
 
605
618
  Returned by `get_logs()`.
606
619
 
607
- | Field | Type | Description |
608
- |----------------|------------------------|------------------------------|
609
- | `items` | `list[LogItem]` | Log entries |
610
- | `next_page` | `int \| str \| None` | Next page cursor |
611
- | `current_page` | `int \| str \| None` | Current page cursor |
620
+ | Field | Type | Description |
621
+ |----------------|-----------------|-----------------------------------------------|
622
+ | `items` | `list[LogItem]` | Log entries |
623
+ | `next_page` | `str \| None` | Next page cursor. `None` on a tail page |
624
+ | `current_page` | `str` | Current page cursor |
625
+ | `raw` | `dict` | The response body as the server sent it |
612
626
 
613
627
  ### LogItem
614
628
 
615
- | Field | Type | Description |
616
- |-------------|------------------------|---------------------------------|
617
- | `raw` | `str` | Raw log line text |
618
- | `timestamp` | `int \| str \| None` | Epoch int or ISO-8601 string |
619
- | `level` | `str \| None` | Log level (INFO, ERROR, etc.) |
620
- | `message` | `str \| None` | Parsed message |
621
- | `extra` | `dict` | Additional fields |
629
+ | Field | Type | Description |
630
+ |-------------|-------|-----------------------------------|
631
+ | `raw` | `str` | Raw log line text |
632
+ | `timestamp` | `str` | Epoch nanoseconds, as a string |
622
633
 
623
634
  ### RunListPage
624
635
 
625
636
  Returned by `list_runs()`.
626
637
 
627
- | Field | Type | Description |
628
- |--------------------------|-------------------|--------------------------------|
629
- | `items` | `list[RunView]` | Runs on this page |
630
- | `total` | `int` | Total matching runs |
631
- | `next_page` | `str \| None` | Next page cursor |
632
- | `previous_page` | `str \| None` | Previous page cursor |
633
- | `current_page` | `str \| None` | Current page cursor |
634
- | `current_page_backwards` | `str \| None` | Backward pagination cursor |
638
+ | Field | Type | Description |
639
+ |--------------------------|-----------------|-----------------------------------------|
640
+ | `items` | `list[RunView]` | Runs on this page |
641
+ | `total` | `int` | Total matching runs |
642
+ | `next_page` | `str \| None` | Next page cursor |
643
+ | `previous_page` | `str \| None` | Previous page cursor |
644
+ | `current_page` | `str \| None` | Current page cursor |
645
+ | `current_page_backwards` | `str \| None` | Backward pagination cursor |
646
+ | `raw` | `dict` | The response body as the server sent it |
635
647
 
636
648
  ### RunMetricsResponse
637
649
 
638
650
  Returned by `get_metrics()`.
639
651
 
640
- | Field | Type | Description |
641
- |-------------------|--------|--------------------------|
642
- | `series_metrics` | `dict` | Time-series metrics |
643
- | `instant_metrics` | `dict` | Point-in-time metrics |
644
- | `extra` | `dict` | Additional fields |
652
+ | Field | Type | Description |
653
+ |-------------------|----------------------------------|-----------------------------------------|
654
+ | `series_metrics` | `dict[str, SeriesMetricDetails]` | Time-series metrics |
655
+ | `instant_metrics` | `dict[str, InstantMetricDetails]` | Point-in-time metrics |
656
+ | `raw` | `dict` | The response body as the server sent it |
645
657
 
646
658
  ## Exceptions
647
659
 
@@ -37,17 +37,18 @@ Documentation = "https://docs.wherobots.com"
37
37
  # PEP 735 dev dependencies — installed with `uv sync --group dev`.
38
38
  [dependency-groups]
39
39
  dev = [
40
- "pytest==9.1.1",
40
+ "jsonschema==4.26.0",
41
+ "pytest==9.2.0",
41
42
  "pytest-cov==7.1.0",
42
43
  "pytest-mock==3.17.0",
43
44
  "ruff==0.17.3",
44
45
  "pyrefly==1.4.0",
45
46
  "import-linter==2.15",
46
47
  "pre-commit==4.7.0",
47
- "hypothesis==6.170.12",
48
+ "hypothesis==6.170.14",
48
49
  "cosmic-ray==8.7.0",
49
- "ast-grep-cli==0.51.0",
50
- "types-requests==2.33.0.20261006",
50
+ "ast-grep-cli==0.51.1",
51
+ "types-requests==2.33.0.20261030",
51
52
  ]
52
53
 
53
54
  [tool.setuptools.packages.find]
@@ -97,6 +98,14 @@ extend-ignore = ["SIM117", "EM101", "EM102", "TRY003", "PLR0917"]
97
98
  # Package __init__ groups exports by category with comment headers;
98
99
  # don't let ruff re-sort them alphabetically.
99
100
  "wherobots/__init__.py" = ["RUF022"]
101
+ # Generated from the spec: names and docstrings are the API's, and the annotations
102
+ # are evaluated at runtime by the wire decoder.
103
+ "wherobots/models/_generated.py" = ["A", "D", "E501", "FBT", "TC"]
104
+ "wherobots/enums/_generated.py" = ["D", "E501"]
105
+ "wherobots/api/_operations.py" = ["A", "D", "E501", "FBT", "PLR0913", "TC"]
106
+ "wherobots/{enums,models}/__init__.py" = ["D", "RUF022"]
107
+ # Dev tools rather than package code.
108
+ "scripts/*.py" = ["D", "INP001", "PLR0911", "S310", "S603", "S607", "T201"]
100
109
 
101
110
  [tool.pyrefly]
102
111
  project-includes = ["wherobots"]
@@ -112,4 +121,5 @@ python_functions = ["test_*"]
112
121
  addopts = ["--cov=wherobots", "--cov-report=html", "--cov-report=term-missing", "-m", "not integration"]
113
122
  markers = [
114
123
  "integration: live API tests requiring WHEROBOTS_API_KEY (deselected by default)",
124
+ "off_contract: feeds a response the spec forbids, so skip the spec_contract fixture",
115
125
  ]