mechbase 0.2.0__tar.gz → 0.2.2__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 (25) hide show
  1. {mechbase-0.2.0 → mechbase-0.2.2}/PKG-INFO +1 -1
  2. {mechbase-0.2.0 → mechbase-0.2.2}/pyproject.toml +1 -1
  3. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/_http.py +3 -1
  4. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/resources/measurements.py +5 -1
  5. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/resources/routes.py +6 -1
  6. mechbase-0.2.2/tests/test_idempotency.py +51 -0
  7. {mechbase-0.2.0 → mechbase-0.2.2}/.gitignore +0 -0
  8. {mechbase-0.2.0 → mechbase-0.2.2}/README.md +0 -0
  9. {mechbase-0.2.0 → mechbase-0.2.2}/examples/list_assets.py +0 -0
  10. {mechbase-0.2.0 → mechbase-0.2.2}/examples/push_measurement.py +0 -0
  11. {mechbase-0.2.0 → mechbase-0.2.2}/examples/run_survey.py +0 -0
  12. {mechbase-0.2.0 → mechbase-0.2.2}/examples/sync_registry.py +0 -0
  13. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/__init__.py +0 -0
  14. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/client.py +0 -0
  15. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/errors.py +0 -0
  16. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/maintnode.py +0 -0
  17. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/models.py +0 -0
  18. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/resources/__init__.py +0 -0
  19. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/resources/_base.py +0 -0
  20. {mechbase-0.2.0 → mechbase-0.2.2}/src/mechbase/resources/registry.py +0 -0
  21. {mechbase-0.2.0 → mechbase-0.2.2}/tests/test_client.py +0 -0
  22. {mechbase-0.2.0 → mechbase-0.2.2}/tests/test_maintnode.py +0 -0
  23. {mechbase-0.2.0 → mechbase-0.2.2}/tests/test_null_safety.py +0 -0
  24. {mechbase-0.2.0 → mechbase-0.2.2}/tests/test_registry.py +0 -0
  25. {mechbase-0.2.0 → mechbase-0.2.2}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mechbase
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Official Python client for the Mechbase condition-monitoring API
5
5
  Project-URL: Homepage, https://app.mechbase.io
6
6
  Project-URL: Source, https://github.com/arpedon/mechbase-sdk
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "mechbase"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Official Python client for the Mechbase condition-monitoring API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -45,7 +45,8 @@ class HttpClient:
45
45
  params: dict | None = None,
46
46
  json: Any = None,
47
47
  data: dict | None = None,
48
- files: dict | None = None,
48
+ files: dict | list | None = None,
49
+ headers: dict | None = None,
49
50
  ) -> Any:
50
51
  response = self._client.request(
51
52
  method,
@@ -54,6 +55,7 @@ class HttpClient:
54
55
  json=json,
55
56
  data=data,
56
57
  files=files,
58
+ headers=headers,
57
59
  )
58
60
  return self._handle(response)
59
61
 
@@ -19,6 +19,7 @@ class Measurements(InstallationScoped):
19
19
  session_id: str | None = None,
20
20
  timestamp: str | None = None,
21
21
  file: str | Path | BinaryIO | None = None,
22
+ idempotency_key: str | None = None,
22
23
  ) -> Measurement:
23
24
  payload: dict[str, Any] = {
24
25
  "measurement_point_id": point_id,
@@ -30,9 +31,11 @@ class Measurements(InstallationScoped):
30
31
  if timestamp:
31
32
  payload["timestamp"] = timestamp
32
33
 
34
+ headers = {"X-Idempotency-Key": idempotency_key} if idempotency_key else None
35
+
33
36
  if file is None:
34
37
  body = self._http.request(
35
- "POST", self._path("/measurements/"), json=payload
38
+ "POST", self._path("/measurements/"), json=payload, headers=headers
36
39
  )
37
40
  return Measurement.from_dict(body)
38
41
 
@@ -47,6 +50,7 @@ class Measurements(InstallationScoped):
47
50
  self._path("/measurements/upload/"),
48
51
  data={"payload": json.dumps(payload)},
49
52
  files={"file": (Path(getattr(fh, "name", "attachment")).name, fh)},
53
+ headers=headers,
50
54
  )
51
55
  finally:
52
56
  if opened:
@@ -25,14 +25,18 @@ class Executions(InstallationScoped):
25
25
  data: dict,
26
26
  notes: str = "",
27
27
  photos: list[str | Path | BinaryIO] | None = None,
28
+ idempotency_key: str | None = None,
28
29
  ) -> ItemResponse:
29
30
  payload: dict[str, Any] = {
30
31
  "route_item_uuid": route_item_uuid,
31
32
  "data": data,
32
33
  "notes": notes,
33
34
  }
35
+ headers = {"X-Idempotency-Key": idempotency_key} if idempotency_key else None
34
36
  if not photos:
35
- body = self._http.request("POST", self._url("/responses"), json=payload)
37
+ body = self._http.request(
38
+ "POST", self._url("/responses"), json=payload, headers=headers
39
+ )
36
40
  return ItemResponse.from_dict(body)
37
41
 
38
42
  files = []
@@ -50,6 +54,7 @@ class Executions(InstallationScoped):
50
54
  self._url("/responses/upload"),
51
55
  data={"payload": json.dumps(payload)},
52
56
  files=files,
57
+ headers=headers,
53
58
  )
54
59
  finally:
55
60
  for fh in opened:
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ import httpx
4
+ import respx
5
+
6
+ from mechbase import Mechbase
7
+
8
+ BASE = "https://example.test"
9
+
10
+ _MEAS = {
11
+ "uuid": "m1", "measurement_point_id": 5, "point_sequence": 1,
12
+ "data": {"rms": 1.2}, "status": "good", "notes": "",
13
+ "created_at": "2026-01-01T00:00:00Z", "file_url": None,
14
+ }
15
+ _RESP = {
16
+ "uuid": "r1", "route_item_uuid": "item-1", "data": {"passed": True},
17
+ "notes": "", "status": 1, "created_at": "2026-01-01T00:00:01Z",
18
+ }
19
+
20
+
21
+ @respx.mock
22
+ def test_create_sends_idempotency_header():
23
+ route = respx.post(f"{BASE}/api/installations/2012/measurements/").mock(
24
+ return_value=httpx.Response(201, json=_MEAS)
25
+ )
26
+ Mechbase(token="t", base_url=BASE).for_installation(2012).measurements.create(
27
+ point_id=5, data={"rms": 1.2}, idempotency_key="k"
28
+ )
29
+ assert route.calls.last.request.headers.get("X-Idempotency-Key") == "k"
30
+
31
+
32
+ @respx.mock
33
+ def test_create_without_key_sends_no_header():
34
+ route = respx.post(f"{BASE}/api/installations/2012/measurements/").mock(
35
+ return_value=httpx.Response(201, json=_MEAS)
36
+ )
37
+ Mechbase(token="t", base_url=BASE).for_installation(2012).measurements.create(
38
+ point_id=5, data={"rms": 1.2}
39
+ )
40
+ assert route.calls.last.request.headers.get("X-Idempotency-Key") is None
41
+
42
+
43
+ @respx.mock
44
+ def test_respond_sends_idempotency_header():
45
+ route = respx.post(
46
+ f"{BASE}/api/installations/2012/executions/exec-1/responses"
47
+ ).mock(return_value=httpx.Response(201, json=_RESP))
48
+ Mechbase(token="t", base_url=BASE).for_installation(2012).routes.execution(
49
+ "exec-1"
50
+ ).respond(route_item_uuid="item-1", data={"passed": True}, idempotency_key="k")
51
+ assert route.calls.last.request.headers.get("X-Idempotency-Key") == "k"
File without changes
File without changes
File without changes
File without changes