wherobots-python-sdk 0.8.0__tar.gz → 0.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/PKG-INFO +22 -12
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/README.md +21 -11
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/pyproject.toml +12 -9
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_base_client.py +70 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_security.py +1 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_spec_contract.py +7 -3
- wherobots_python_sdk-0.9.1/tests/test_task_run_wait.py +470 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_tasks.py +11 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/__init__.py +4 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/__version__.py +1 -1
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/base.py +26 -6
- wherobots_python_sdk-0.9.1/wherobots/api/tasks.py +503 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/enums/_handwritten.py +13 -1
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/exceptions.py +40 -1
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/models/_generated.py +3 -2
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/models/_handwritten.py +40 -1
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots_python_sdk.egg-info/PKG-INFO +22 -12
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots_python_sdk.egg-info/SOURCES.txt +1 -0
- wherobots_python_sdk-0.8.0/wherobots/api/tasks.py +0 -244
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/LICENSE +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/setup.cfg +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_api.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_client.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_client_header.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_config.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_enums.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_exceptions.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_files_api.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_files_drive.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_init_exports.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_integration.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_live_contract.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_logger.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_models.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_regressions.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_utils.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_wire.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/tests/test_workload_auth.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/_wire.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/__init__.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/_operations.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/drive.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/files.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/runs.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/api/workload_auth.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/client.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/config.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/enums/__init__.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/enums/_generated.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/models/__init__.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/py.typed +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/sdk.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/utils/__init__.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/utils/client_header.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/utils/logger.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots/utils/validation.py +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots_python_sdk.egg-info/dependency_links.txt +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/wherobots_python_sdk.egg-info/requires.txt +0 -0
- {wherobots_python_sdk-0.8.0 → wherobots_python_sdk-0.9.1}/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.
|
|
3
|
+
Version: 0.9.1
|
|
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
|
|
@@ -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
|
-
|
|
492
|
-
run = wb.
|
|
493
|
-
|
|
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
|
|
506
|
-
|
|
507
|
-
|
|
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.
|
|
@@ -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
|
-
|
|
466
|
-
run = wb.
|
|
467
|
-
|
|
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
|
|
480
|
-
|
|
481
|
-
|
|
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.
|
|
@@ -37,18 +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
|
-
"jsonschema
|
|
41
|
-
"pytest==9.
|
|
40
|
+
"jsonschema==4.26.0",
|
|
41
|
+
"pytest==9.2.0",
|
|
42
42
|
"pytest-cov==7.1.0",
|
|
43
43
|
"pytest-mock==3.17.0",
|
|
44
|
-
"ruff==0.17.
|
|
45
|
-
"pyrefly==1.4.
|
|
46
|
-
"import-linter==2.
|
|
44
|
+
"ruff==0.17.5",
|
|
45
|
+
"pyrefly==1.4.1",
|
|
46
|
+
"import-linter==2.16",
|
|
47
47
|
"pre-commit==4.7.0",
|
|
48
|
-
"hypothesis==6.170.
|
|
49
|
-
"cosmic-ray==8.
|
|
50
|
-
"ast-grep-cli==0.51.
|
|
51
|
-
"types-requests==2.33.0.
|
|
48
|
+
"hypothesis==6.170.15",
|
|
49
|
+
"cosmic-ray==8.9.0",
|
|
50
|
+
"ast-grep-cli==0.51.3",
|
|
51
|
+
"types-requests==2.33.0.20261030",
|
|
52
52
|
]
|
|
53
53
|
|
|
54
54
|
[tool.setuptools.packages.find]
|
|
@@ -123,3 +123,6 @@ markers = [
|
|
|
123
123
|
"integration: live API tests requiring WHEROBOTS_API_KEY (deselected by default)",
|
|
124
124
|
"off_contract: feeds a response the spec forbids, so skip the spec_contract fixture",
|
|
125
125
|
]
|
|
126
|
+
|
|
127
|
+
[tool.uv]
|
|
128
|
+
exclude-newer = "14 days"
|
|
@@ -270,6 +270,76 @@ class TestRequestErrorWrapping:
|
|
|
270
270
|
assert err.response == body
|
|
271
271
|
assert str(err).startswith("API request failed (status 404): Run not found")
|
|
272
272
|
|
|
273
|
+
@patch("wherobots.api.base.requests.Session")
|
|
274
|
+
def test_error_message_shows_every_field_the_api_sets(self, MockSession, config):
|
|
275
|
+
session = _mock_session(MockSession)
|
|
276
|
+
info = payload(
|
|
277
|
+
"ErrorInfo",
|
|
278
|
+
code="BAD_REQUEST_ERROR",
|
|
279
|
+
message="Bad Request",
|
|
280
|
+
details="Inputs for task t are invalid: aoi is required",
|
|
281
|
+
field="aoi",
|
|
282
|
+
path="/tasks/t/runs",
|
|
283
|
+
suggestion="Update your request and try again.",
|
|
284
|
+
documentation_url="https://docs.wherobots.com/tasks",
|
|
285
|
+
data={"limit": 3},
|
|
286
|
+
)
|
|
287
|
+
body = payload("ErrorBody", errors=[info], requestId="req-1")
|
|
288
|
+
session.request.return_value = _error_response(400, body)
|
|
289
|
+
|
|
290
|
+
err = _api_error(session, config)
|
|
291
|
+
|
|
292
|
+
assert str(err) == (
|
|
293
|
+
"API request failed (status 400): Bad Request\n"
|
|
294
|
+
" details: Inputs for task t are invalid: aoi is required\n"
|
|
295
|
+
" field: aoi\n"
|
|
296
|
+
" code: BAD_REQUEST_ERROR\n"
|
|
297
|
+
" path: /tasks/t/runs\n"
|
|
298
|
+
" suggestion: Update your request and try again.\n"
|
|
299
|
+
" documentation_url: https://docs.wherobots.com/tasks\n"
|
|
300
|
+
" data: {'limit': 3} [request_id=req-1]"
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
@patch("wherobots.api.base.requests.Session")
|
|
304
|
+
def test_error_message_skips_fields_the_api_leaves_empty(self, MockSession, config):
|
|
305
|
+
session = _mock_session(MockSession)
|
|
306
|
+
info = payload(
|
|
307
|
+
"ErrorInfo",
|
|
308
|
+
code="not_found_error",
|
|
309
|
+
message="Run not found",
|
|
310
|
+
details="No run r",
|
|
311
|
+
path="/runs/r",
|
|
312
|
+
suggestion="",
|
|
313
|
+
field=None,
|
|
314
|
+
documentation_url=None,
|
|
315
|
+
data=None,
|
|
316
|
+
)
|
|
317
|
+
body = payload("ErrorBody", errors=[info], requestId="req-2")
|
|
318
|
+
session.request.return_value = _error_response(404, body)
|
|
319
|
+
|
|
320
|
+
err = _api_error(session, config)
|
|
321
|
+
|
|
322
|
+
assert str(err) == (
|
|
323
|
+
"API request failed (status 404): Run not found\n"
|
|
324
|
+
" details: No run r\n"
|
|
325
|
+
" code: not_found_error\n"
|
|
326
|
+
" path: /runs/r [request_id=req-2]"
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
@patch("wherobots.api.base.requests.Session")
|
|
330
|
+
def test_error_message_lists_each_error(self, MockSession, config):
|
|
331
|
+
session = _mock_session(MockSession)
|
|
332
|
+
first = payload("ErrorInfo", code="a", message="First", details="d1", path="/p")
|
|
333
|
+
second = payload("ErrorInfo", code="b", message="Second", details="d2", path="/p")
|
|
334
|
+
body = payload("ErrorBody", errors=[first, second], requestId="req-3")
|
|
335
|
+
session.request.return_value = _error_response(400, body)
|
|
336
|
+
|
|
337
|
+
lines = str(_api_error(session, config)).splitlines()
|
|
338
|
+
|
|
339
|
+
assert lines[0] == "API request failed (status 400): First"
|
|
340
|
+
assert "Second" in lines
|
|
341
|
+
assert lines.index(" details: d2") > lines.index("Second") > lines.index(" details: d1")
|
|
342
|
+
|
|
273
343
|
@pytest.mark.off_contract
|
|
274
344
|
@patch("wherobots.api.base.requests.Session")
|
|
275
345
|
def test_gateway_body_falls_back_to_detail(self, MockSession, config):
|
|
@@ -424,6 +424,7 @@ class TestPostRetryRemoved:
|
|
|
424
424
|
retry = adapter.max_retries
|
|
425
425
|
assert retry.allowed_methods == ["GET"]
|
|
426
426
|
assert "POST" not in retry.allowed_methods
|
|
427
|
+
assert set(retry.status_forcelist) == {429, 500, 502, 503, 504}
|
|
427
428
|
|
|
428
429
|
|
|
429
430
|
# =========================================================================== #
|
|
@@ -25,9 +25,13 @@ def test_every_job_status_is_classified():
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def test_every_task_run_state_is_classified():
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
groups = (
|
|
29
|
+
_handwritten._ACTIVE_TASK_RUN_STATES,
|
|
30
|
+
_handwritten._FINISHED_TASK_RUN_STATES,
|
|
31
|
+
_handwritten._UNSETTLED_TASK_RUN_STATES,
|
|
32
|
+
)
|
|
33
|
+
assert frozenset().union(*groups) == _values("TaskRunState")
|
|
34
|
+
assert sum(len(group) for group in groups) == len(_values("TaskRunState"))
|
|
31
35
|
|
|
32
36
|
|
|
33
37
|
@pytest.mark.parametrize("status", list(JobStatus))
|