sherlock-api 0.1.0__tar.gz → 0.2.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 (24) hide show
  1. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/.gitignore +7 -0
  2. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/CHANGELOG.md +11 -0
  3. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/PKG-INFO +20 -1
  4. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/README.md +19 -0
  5. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/pyproject.toml +1 -1
  6. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/__init__.py +9 -0
  7. sherlock_api-0.2.0/src/sherlock_api/annotations.py +81 -0
  8. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/client.py +32 -0
  9. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/tests/test_client.py +36 -0
  10. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/tests/test_models.py +45 -0
  11. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/LICENSE +0 -0
  12. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/examples/smoke_check.py +0 -0
  13. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/batches.py +0 -0
  14. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/cases.py +0 -0
  15. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/exceptions.py +0 -0
  16. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/files.py +0 -0
  17. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/images.py +0 -0
  18. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/logs.py +0 -0
  19. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/measurements.py +0 -0
  20. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/process.py +0 -0
  21. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/py.typed +0 -0
  22. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/src/sherlock_api/validation.py +0 -0
  23. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/tests/__init__.py +0 -0
  24. {sherlock_api-0.1.0 → sherlock_api-0.2.0}/tests/conftest.py +0 -0
@@ -12,9 +12,16 @@ build/
12
12
  dist/
13
13
  *.egg-info/
14
14
 
15
+ # Local notes (not checked in)
16
+ *.local.md
17
+
15
18
  # Tooling caches
16
19
  .pytest_cache/
17
20
  .mypy_cache/
18
21
  .ruff_cache/
19
22
  .coverage
20
23
  htmlcov/
24
+
25
+ # IDEs and editors
26
+ .vscode/
27
+ .idea/
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project are documented here. This project adheres
4
4
  to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [0.2.0] - 2026-12-06
7
+
8
+ ### Added
9
+
10
+ - Image annotations: `post_annotation_distance(image_id, annotation)` draws a
11
+ distance annotation and returns it; `delete_annotation(image_id, annotation_id)`
12
+ removes one and raises `SherlockNotFoundError` if it does not exist.
13
+ - `sherlock_api.annotations` with the `CreateDistanceAnnotationRequest` model,
14
+ the `CreateAnnotationRequest` alias and `DEFAULT_ANNOTATION_COLOR`. Styling
15
+ fields default to an opaque yellow line, 2 px thick, with 10 px end markers.
16
+
6
17
  ## [0.1.0] - 2026-09-19
7
18
 
8
19
  First packaged release. The code previously lived as loose top-level modules
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sherlock-api
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Python client for the Sherlock REST API
5
5
  Project-URL: Homepage, https://github.com/sherlockrobotics/sherlock-python-api
6
6
  Project-URL: Repository, https://github.com/sherlockrobotics/sherlock-python-api
@@ -106,6 +106,24 @@ Keyword-only options: `request_timeout` (seconds, default `30.0`), `max_retries`
106
106
  (default `3`, applied to connection errors and 502/503/504 on GET and DELETE),
107
107
  and `session` to supply your own `requests.Session`.
108
108
 
109
+ ## Annotations
110
+
111
+ Annotations are shapes drawn on top of an uploaded image. A distance annotation
112
+ is a line between two points, in image pixel coordinates. Only the name and the
113
+ coordinates are required; colours (`"#RRGGBBAA"`) and sizes default to an opaque
114
+ yellow line, 2 px thick, with 10 px end markers.
115
+
116
+ ```python
117
+ from sherlock_api import CreateDistanceAnnotationRequest
118
+
119
+ annotation = client.post_annotation_distance(
120
+ image["id"],
121
+ CreateDistanceAnnotationRequest("gap", 20, 20, 40, 40, line_color="#FF0000FF"),
122
+ )
123
+
124
+ client.delete_annotation(image["id"], annotation["id"])
125
+ ```
126
+
109
127
  ## Modal dialogs
110
128
 
111
129
  `post_modal` returns a modal id; `get_modal` long-polls for the operator's
@@ -157,6 +175,7 @@ on the `sherlock_api.client` logger rather than raised — it is fire-and-forget
157
175
  | Images | `get_image`, `get_images_for_batch`, `post_image`, `upload_image`, `upload_image_with_measurement`, `upload_image_with_measurements` |
158
176
  | Logs | `get_log`, `post_log`, `log_{case,batch,image}_{error,warning,info}` |
159
177
  | Measurements | `get_measurement`, `post_measurement`, `delete_measurement` |
178
+ | Annotations | `post_annotation_distance`, `delete_annotation` |
160
179
  | Processes | `get_process_state`, `is_process_running`, `get_env_state`, `get_env_vars`, `post_modal`, `get_modal`, `delete_modal`, `post_notification` |
161
180
 
162
181
  Methods returning JSON return the parsed `dict` or `list` from the server as-is.
@@ -69,6 +69,24 @@ Keyword-only options: `request_timeout` (seconds, default `30.0`), `max_retries`
69
69
  (default `3`, applied to connection errors and 502/503/504 on GET and DELETE),
70
70
  and `session` to supply your own `requests.Session`.
71
71
 
72
+ ## Annotations
73
+
74
+ Annotations are shapes drawn on top of an uploaded image. A distance annotation
75
+ is a line between two points, in image pixel coordinates. Only the name and the
76
+ coordinates are required; colours (`"#RRGGBBAA"`) and sizes default to an opaque
77
+ yellow line, 2 px thick, with 10 px end markers.
78
+
79
+ ```python
80
+ from sherlock_api import CreateDistanceAnnotationRequest
81
+
82
+ annotation = client.post_annotation_distance(
83
+ image["id"],
84
+ CreateDistanceAnnotationRequest("gap", 20, 20, 40, 40, line_color="#FF0000FF"),
85
+ )
86
+
87
+ client.delete_annotation(image["id"], annotation["id"])
88
+ ```
89
+
72
90
  ## Modal dialogs
73
91
 
74
92
  `post_modal` returns a modal id; `get_modal` long-polls for the operator's
@@ -120,6 +138,7 @@ on the `sherlock_api.client` logger rather than raised — it is fire-and-forget
120
138
  | Images | `get_image`, `get_images_for_batch`, `post_image`, `upload_image`, `upload_image_with_measurement`, `upload_image_with_measurements` |
121
139
  | Logs | `get_log`, `post_log`, `log_{case,batch,image}_{error,warning,info}` |
122
140
  | Measurements | `get_measurement`, `post_measurement`, `delete_measurement` |
141
+ | Annotations | `post_annotation_distance`, `delete_annotation` |
123
142
  | Processes | `get_process_state`, `is_process_running`, `get_env_state`, `get_env_vars`, `post_modal`, `get_modal`, `delete_modal`, `post_notification` |
124
143
 
125
144
  Methods returning JSON return the parsed `dict` or `list` from the server as-is.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sherlock-api"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Python client for the Sherlock REST API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -19,6 +19,11 @@ from __future__ import annotations
19
19
  import logging
20
20
  from importlib.metadata import PackageNotFoundError, version
21
21
 
22
+ from .annotations import (
23
+ DEFAULT_ANNOTATION_COLOR,
24
+ CreateAnnotationRequest,
25
+ CreateDistanceAnnotationRequest,
26
+ )
22
27
  from .batches import CreateBatchRequest
23
28
  from .cases import CreateCaseRequest, RobotPlatform
24
29
  from .client import DEFAULT_TIMEOUT, DEFAULT_URL, SherlockAPIClient
@@ -90,6 +95,10 @@ __all__ = [
90
95
  "CreateImageLogRequest",
91
96
  # Measurements
92
97
  "CreateMeasurementRequest",
98
+ # Annotations
99
+ "DEFAULT_ANNOTATION_COLOR",
100
+ "CreateDistanceAnnotationRequest",
101
+ "CreateAnnotationRequest",
93
102
  # Processes
94
103
  "ProcessState",
95
104
  "DialogType",
@@ -0,0 +1,81 @@
1
+ """Request models for Sherlock image annotations.
2
+
3
+ An annotation is a shape drawn on top of an image in Sherlock. Each kind of
4
+ annotation has its own request class and endpoint; :data:`CreateAnnotationRequest`
5
+ names any of them.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from dataclasses import dataclass
11
+ from typing import Any, TypeAlias
12
+
13
+ __all__ = [
14
+ "DEFAULT_ANNOTATION_COLOR",
15
+ "CreateDistanceAnnotationRequest",
16
+ "CreateAnnotationRequest",
17
+ ]
18
+
19
+ #: RGBA hex colour used when none is given: opaque yellow.
20
+ DEFAULT_ANNOTATION_COLOR = "#FFFF00FF"
21
+
22
+
23
+ @dataclass
24
+ class CreateDistanceAnnotationRequest:
25
+ """Payload for :meth:`sherlock_api.SherlockAPIClient.post_annotation_distance`.
26
+
27
+ A line from ``(x1, y1)`` to ``(x2, y2)``, in image pixel coordinates, with a
28
+ marker at each end. Colours are ``"#RRGGBBAA"`` hex strings.
29
+
30
+ Args:
31
+ name: Label shown with the annotation.
32
+ x1: X coordinate of the start point.
33
+ y1: Y coordinate of the start point.
34
+ x2: X coordinate of the end point.
35
+ y2: Y coordinate of the end point.
36
+ line_color: Colour of the line.
37
+ line_thickness: Thickness of the line, in pixels.
38
+ head_color: Colour of the marker at the end point.
39
+ head_length: Length of the end-point marker, in pixels.
40
+ head_thickness: Thickness of the end-point marker, in pixels.
41
+ tail_color: Colour of the marker at the start point.
42
+ tail_length: Length of the start-point marker, in pixels.
43
+ tail_thickness: Thickness of the start-point marker, in pixels.
44
+ """
45
+
46
+ name: str
47
+ x1: float
48
+ y1: float
49
+ x2: float
50
+ y2: float
51
+ line_color: str = DEFAULT_ANNOTATION_COLOR
52
+ line_thickness: int = 2
53
+ head_color: str = DEFAULT_ANNOTATION_COLOR
54
+ head_length: int = 10
55
+ head_thickness: int = 2
56
+ tail_color: str = DEFAULT_ANNOTATION_COLOR
57
+ tail_length: int = 10
58
+ tail_thickness: int = 2
59
+
60
+ def to_dict(self) -> dict[str, Any]:
61
+ """Serialize to the JSON body of ``POST /image/{id}/annotation/distance``."""
62
+ return {
63
+ "name": self.name,
64
+ # The server parses coordinates as floats; send 20.0 rather than 20.
65
+ "x1": float(self.x1),
66
+ "y1": float(self.y1),
67
+ "x2": float(self.x2),
68
+ "y2": float(self.y2),
69
+ "line_color": self.line_color,
70
+ "line_thickness": self.line_thickness,
71
+ "head_color": self.head_color,
72
+ "head_length": self.head_length,
73
+ "head_thickness": self.head_thickness,
74
+ "tail_color": self.tail_color,
75
+ "tail_length": self.tail_length,
76
+ "tail_thickness": self.tail_thickness,
77
+ }
78
+
79
+
80
+ #: Any annotation creation payload. Becomes a union as more kinds are supported.
81
+ CreateAnnotationRequest: TypeAlias = CreateDistanceAnnotationRequest
@@ -13,6 +13,7 @@ from PIL import Image
13
13
  from requests.adapters import HTTPAdapter
14
14
  from urllib3.util.retry import Retry
15
15
 
16
+ from .annotations import CreateDistanceAnnotationRequest
16
17
  from .batches import CreateBatchRequest
17
18
  from .cases import CreateCaseRequest
18
19
  from .exceptions import (
@@ -491,6 +492,37 @@ class SherlockAPIClient:
491
492
  """Delete a measurement."""
492
493
  self._request("DELETE", f"/measurement/{measurement_id}", expected=(204,))
493
494
 
495
+ # ------------------------------------------------------------------
496
+ # Annotations
497
+ # ------------------------------------------------------------------
498
+
499
+ def post_annotation_distance(
500
+ self, image_id: str, annotation: CreateDistanceAnnotationRequest
501
+ ) -> JSONDict:
502
+ """Draw a distance annotation on an image.
503
+
504
+ Returns:
505
+ The created annotation object.
506
+ """
507
+ return _as_object(
508
+ self._request(
509
+ "POST",
510
+ f"/image/{image_id}/annotation/distance",
511
+ expected=(201,),
512
+ json=annotation.to_dict(),
513
+ )
514
+ )
515
+
516
+ def delete_annotation(self, image_id: str, annotation_id: str) -> None:
517
+ """Delete an annotation from an image.
518
+
519
+ Raises:
520
+ SherlockNotFoundError: If the image has no such annotation.
521
+ """
522
+ self._request(
523
+ "DELETE", f"/image/{image_id}/annotation/{annotation_id}", expected=(204,)
524
+ )
525
+
494
526
  # ------------------------------------------------------------------
495
527
  # Processes
496
528
  # ------------------------------------------------------------------
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import io
6
+ import json
6
7
  import logging
7
8
 
8
9
  import pytest
@@ -10,6 +11,7 @@ import responses
10
11
  from PIL import Image
11
12
 
12
13
  from sherlock_api import (
14
+ CreateDistanceAnnotationRequest,
13
15
  CreateNotificationRequest,
14
16
  CreateProcessModalDialogRequest,
15
17
  DecisionClass,
@@ -253,6 +255,40 @@ def test_delete_measurement_expects_204(client):
253
255
  assert client.delete_measurement("m1") is None
254
256
 
255
257
 
258
+ # ----------------------------------------------------------------------
259
+ # Annotations
260
+ # ----------------------------------------------------------------------
261
+
262
+
263
+ @responses.activate
264
+ def test_post_annotation_distance_posts_to_the_image(client):
265
+ responses.add(
266
+ responses.POST,
267
+ f"{BASE_URL}/image/img-1/annotation/distance",
268
+ status=201,
269
+ json={"id": "a1", "name": "beep"},
270
+ )
271
+ annotation = CreateDistanceAnnotationRequest("beep", 20, 20, 40, 40)
272
+
273
+ result = client.post_annotation_distance("img-1", annotation)
274
+
275
+ assert result == {"id": "a1", "name": "beep"}
276
+ assert json.loads(responses.calls[0].request.body) == annotation.to_dict()
277
+
278
+
279
+ @responses.activate
280
+ def test_delete_annotation_expects_204(client):
281
+ responses.add(responses.DELETE, f"{BASE_URL}/image/img-1/annotation/a1", status=204)
282
+ assert client.delete_annotation("img-1", "a1") is None
283
+
284
+
285
+ @responses.activate
286
+ def test_delete_annotation_raises_when_not_found(client):
287
+ responses.add(responses.DELETE, f"{BASE_URL}/image/img-1/annotation/a1", status=404)
288
+ with pytest.raises(SherlockNotFoundError):
289
+ client.delete_annotation("img-1", "a1")
290
+
291
+
256
292
  # ----------------------------------------------------------------------
257
293
  # Logs
258
294
  # ----------------------------------------------------------------------
@@ -11,6 +11,7 @@ from sherlock_api import (
11
11
  CreateBatchRequest,
12
12
  CreateCaseLogRequest,
13
13
  CreateCaseRequest,
14
+ CreateDistanceAnnotationRequest,
14
15
  CreateImageLogRequest,
15
16
  CreateImageRequest,
16
17
  CreateMeasurementRequest,
@@ -83,6 +84,50 @@ def test_measurement_stringifies_numbers(value, expected):
83
84
  }
84
85
 
85
86
 
87
+ def test_distance_annotation_defaults_match_the_documented_body():
88
+ req = CreateDistanceAnnotationRequest("beep", 20.0, 20.0, 40.0, 40.0)
89
+ assert req.to_dict() == {
90
+ "name": "beep",
91
+ "x1": 20.0,
92
+ "y1": 20.0,
93
+ "x2": 40.0,
94
+ "y2": 40.0,
95
+ "line_color": "#FFFF00FF",
96
+ "line_thickness": 2,
97
+ "head_color": "#FFFF00FF",
98
+ "head_length": 10,
99
+ "head_thickness": 2,
100
+ "tail_color": "#FFFF00FF",
101
+ "tail_length": 10,
102
+ "tail_thickness": 2,
103
+ }
104
+
105
+
106
+ def test_distance_annotation_sends_integer_coordinates_as_floats():
107
+ payload = CreateDistanceAnnotationRequest("d", 1, 2, 3, 4).to_dict()
108
+ for key in ("x1", "y1", "x2", "y2"):
109
+ assert isinstance(payload[key], float)
110
+
111
+
112
+ def test_distance_annotation_passes_styling_through():
113
+ req = CreateDistanceAnnotationRequest(
114
+ "d",
115
+ 0,
116
+ 0,
117
+ 1,
118
+ 1,
119
+ line_color="#FF0000FF",
120
+ line_thickness=5,
121
+ head_length=0,
122
+ tail_color="#00FF0080",
123
+ )
124
+ payload = req.to_dict()
125
+ assert payload["line_color"] == "#FF0000FF"
126
+ assert payload["line_thickness"] == 5
127
+ assert payload["head_length"] == 0
128
+ assert payload["tail_color"] == "#00FF0080"
129
+
130
+
86
131
  def test_modal_request_keys_message_by_language():
87
132
  req = CreateProcessModalDialogRequest(DialogType.YesNo, Language.German, "Weiter?")
88
133
  assert req.to_dict() == {
File without changes