clarity-api-sdk-python 0.3.27__tar.gz → 0.3.29__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. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/PKG-INFO +5 -5
  2. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/README.md +4 -4
  3. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/pyproject.toml +1 -1
  4. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/clarity_api_sdk_python.egg-info/PKG-INFO +5 -5
  5. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/api/__init__.py +1 -1
  6. clarity_api_sdk_python-0.3.29/src/cti/api/session.py +122 -0
  7. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/api/sonar_wiz_api.py +6 -7
  8. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/api/sonar_wiz_async_api.py +6 -7
  9. clarity_api_sdk_python-0.3.27/src/cti/api/session.py +0 -76
  10. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/setup.cfg +0 -0
  11. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/clarity_api_sdk_python.egg-info/SOURCES.txt +0 -0
  12. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/clarity_api_sdk_python.egg-info/dependency_links.txt +0 -0
  13. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/clarity_api_sdk_python.egg-info/requires.txt +0 -0
  14. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/clarity_api_sdk_python.egg-info/top_level.txt +0 -0
  15. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/__init__.py +0 -0
  16. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/api/async_client.py +0 -0
  17. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/api/client.py +0 -0
  18. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/logger/__init__.py +0 -0
  19. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/logger/logger.py +0 -0
  20. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/main.py +0 -0
  21. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/main_api.py +0 -0
  22. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/__init__.py +0 -0
  23. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/altitude_source.py +0 -0
  24. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/attitude_source.py +0 -0
  25. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/deferred_object_deletion.py +0 -0
  26. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/depth_source.py +0 -0
  27. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/device.py +0 -0
  28. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/device_type.py +0 -0
  29. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/final_product.py +0 -0
  30. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/hierarchy.py +0 -0
  31. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/layback_algorithm.py +0 -0
  32. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/layback_source.py +0 -0
  33. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/layback_type.py +0 -0
  34. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/organization.py +0 -0
  35. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/platform.py +0 -0
  36. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/platform_type.py +0 -0
  37. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/position_source.py +0 -0
  38. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_altitude.py +0 -0
  39. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_attitude.py +0 -0
  40. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_depth.py +0 -0
  41. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_layback.py +0 -0
  42. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_position.py +0 -0
  43. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processed_sidescan_ping.py +0 -0
  44. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/processing_log.py +0 -0
  45. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/project.py +0 -0
  46. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/projection_option.py +0 -0
  47. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_altitude.py +0 -0
  48. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_attitude.py +0 -0
  49. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_depth.py +0 -0
  50. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_file.py +0 -0
  51. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_file_configuration.py +0 -0
  52. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_file_device_mapping.py +0 -0
  53. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_file_state.py +0 -0
  54. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_layback.py +0 -0
  55. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_position.py +0 -0
  56. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/raw_sidescan_ping.py +0 -0
  57. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/s3.py +0 -0
  58. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/sidescan_ping_source.py +0 -0
  59. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/source.py +0 -0
  60. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/survey.py +0 -0
  61. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/target.py +0 -0
  62. {clarity_api_sdk_python-0.3.27 → clarity_api_sdk_python-0.3.29}/src/cti/model/tow_system.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarity-api-sdk-python
3
- Version: 0.3.27
3
+ Version: 0.3.29
4
4
  Summary: A Python SDK to connect to the CTI Clarity API server.
5
5
  Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
6
  Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
@@ -114,10 +114,10 @@ if __name__ == "__main__":
114
114
  asyncio.run(main())
115
115
 
116
116
  # In other modules
117
- from cti.api.session import async_client
117
+ from cti.api.session import get_async_client
118
118
 
119
119
  async def fetch_data():
120
- if async_client:
121
- response = await async_client.get(...)
122
- return response.json()
120
+ client = get_async_client()
121
+ response = await client.get(...)
122
+ return response.json()
123
123
  ```
@@ -80,10 +80,10 @@ if __name__ == "__main__":
80
80
  asyncio.run(main())
81
81
 
82
82
  # In other modules
83
- from cti.api.session import async_client
83
+ from cti.api.session import get_async_client
84
84
 
85
85
  async def fetch_data():
86
- if async_client:
87
- response = await async_client.get(...)
88
- return response.json()
86
+ client = get_async_client()
87
+ response = await client.get(...)
88
+ return response.json()
89
89
  ```
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "clarity-api-sdk-python"
8
- version = "0.3.27"
8
+ version = "0.3.29"
9
9
  authors = [
10
10
  { name="Chesapeake Technology Inc.", email="support@chesapeaketech.com" },
11
11
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarity-api-sdk-python
3
- Version: 0.3.27
3
+ Version: 0.3.29
4
4
  Summary: A Python SDK to connect to the CTI Clarity API server.
5
5
  Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
6
  Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
@@ -114,10 +114,10 @@ if __name__ == "__main__":
114
114
  asyncio.run(main())
115
115
 
116
116
  # In other modules
117
- from cti.api.session import async_client
117
+ from cti.api.session import get_async_client
118
118
 
119
119
  async def fetch_data():
120
- if async_client:
121
- response = await async_client.get(...)
122
- return response.json()
120
+ client = get_async_client()
121
+ response = await client.get(...)
122
+ return response.json()
123
123
  ```
@@ -2,6 +2,6 @@
2
2
 
3
3
  from .async_client import ClarityApiAsyncClient
4
4
  from .client import ClarityApiClient
5
- from .session import async_client, initialize_async_client, close_async_client
5
+ from .session import get_async_client, initialize_async_client, close_async_client
6
6
  from .sonar_wiz_api import SonarWizApi
7
7
  from .sonar_wiz_async_api import SonarWizAsyncApi
@@ -0,0 +1,122 @@
1
+ """Provides event loop-scoped async client instances.
2
+
3
+ This module uses contextvars to ensure each event loop gets its own
4
+ ClarityApiAsyncClient instance, preventing issues when event loops are
5
+ created/destroyed (common in Dask workers).
6
+
7
+ Example:
8
+ # Each asyncio.run() gets its own isolated client
9
+ async def task():
10
+ await initialize_async_client()
11
+ client = get_async_client()
12
+ response = await client.get(...)
13
+ await close_async_client() # Optional, cleans up resources
14
+
15
+ # Task 1 - creates client in loop 1
16
+ asyncio.run(task())
17
+
18
+ # Task 2 - creates new client in loop 2
19
+ asyncio.run(task())
20
+ """
21
+
22
+ # pylint: disable=unnecessary-dunder-call
23
+
24
+ import asyncio
25
+ from contextvars import ContextVar
26
+ from typing import Optional
27
+
28
+ from cti.api.async_client import ClarityApiAsyncClient
29
+
30
+ # Context-local storage (isolated per event loop)
31
+ # Stores tuple of (client, loop) to track which loop the client was created in
32
+ _async_client_var: ContextVar[
33
+ Optional[tuple[ClarityApiAsyncClient, asyncio.AbstractEventLoop]]
34
+ ] = ContextVar("clarity_async_client", default=None)
35
+
36
+
37
+ def _is_client_valid(
38
+ client_tuple: Optional[tuple[ClarityApiAsyncClient, asyncio.AbstractEventLoop]],
39
+ current_loop: asyncio.AbstractEventLoop,
40
+ ) -> bool:
41
+ """Check if client is still valid for the current event loop.
42
+
43
+ Args:
44
+ client_tuple: Tuple of (client, loop) from context storage.
45
+ current_loop: The current event loop to check against.
46
+
47
+ Returns:
48
+ True if client is valid for the current loop, False otherwise.
49
+ """
50
+ if client_tuple is None:
51
+ return False
52
+
53
+ _, stored_loop = client_tuple
54
+
55
+ try:
56
+ # Check if stored loop is the same as current loop and not closed
57
+ return stored_loop is current_loop and not current_loop.is_closed()
58
+ except Exception:
59
+ pass
60
+ return False
61
+
62
+
63
+ async def initialize_async_client() -> None:
64
+ """Initialize async client for the current event loop context.
65
+
66
+ Creates a new client instance if:
67
+ - No client exists in current context, OR
68
+ - Existing client is bound to a different (closed) event loop
69
+
70
+ This function is idempotent within a single event loop.
71
+ """
72
+ current_client_tuple = _async_client_var.get()
73
+ current_loop = asyncio.get_running_loop()
74
+
75
+ # Check if we need a new client
76
+ needs_new_client = not _is_client_valid(current_client_tuple, current_loop)
77
+
78
+ if needs_new_client:
79
+ # Close old client if it exists
80
+ if current_client_tuple is not None:
81
+ old_client, _ = current_client_tuple
82
+ try:
83
+ await old_client.__aexit__(None, None, None)
84
+ except Exception:
85
+ pass # Best effort cleanup
86
+
87
+ # Create new client for this event loop
88
+ new_client = ClarityApiAsyncClient()
89
+ await new_client.__aenter__()
90
+ _async_client_var.set((new_client, current_loop))
91
+
92
+
93
+ def get_async_client() -> ClarityApiAsyncClient:
94
+ """Get the async client for the current context.
95
+
96
+ Returns:
97
+ ClarityApiAsyncClient instance for this event loop.
98
+
99
+ Raises:
100
+ ValueError: If initialize_async_client() hasn't been called in this context.
101
+ """
102
+ client_tuple = _async_client_var.get()
103
+ if client_tuple is None:
104
+ raise ValueError(
105
+ "initialize_async_client() must be called first to initialize client."
106
+ )
107
+ client, _ = client_tuple
108
+ return client
109
+
110
+
111
+ async def close_async_client() -> None:
112
+ """Close the async client for the current context.
113
+
114
+ This function should be awaited to ensure the underlying connection
115
+ pool is closed gracefully. Resources are cleaned up for the current
116
+ event loop context only.
117
+ """
118
+ client_tuple = _async_client_var.get()
119
+ if client_tuple:
120
+ client, _ = client_tuple
121
+ await client.__aexit__(None, None, None)
122
+ _async_client_var.set(None)
@@ -1337,21 +1337,20 @@ class SonarWizApi:
1337
1337
  response.raise_for_status()
1338
1338
  return RawDepth.model_validate(response.json())
1339
1339
 
1340
- def create_raw_sidescan_ping(self, ping: RawSidescanPingCreate) -> None:
1341
- """Create a raw sidescan ping record.
1340
+ def create_raw_sidescan_pings(self, pings: list[RawSidescanPingCreate]) -> None:
1341
+ """Create raw sidescan ping records.
1342
1342
 
1343
1343
  Args:
1344
- ping: Raw sidescan ping creation data.
1344
+ pings: Raw sidescan ping creation data.
1345
1345
  """
1346
1346
  response = self._client.post(
1347
- "/api/v1/raw-sidescan-pings", json=[ping.model_dump(mode="json")]
1347
+ "/api/v1/raw-sidescan-pings", json=[ping.model_dump(mode="json") for ping in pings]
1348
1348
  )
1349
1349
  response.raise_for_status()
1350
1350
  logger.debug(
1351
- "raw_sidescan_ping_created",
1351
+ "raw_sidescan_pings_created",
1352
1352
  extra={
1353
- "sidescan_ping_source_id": str(ping.sidescan_ping_source_id),
1354
- "ping_number_id": str(ping.ping_number_id),
1353
+ "count": len(pings),
1355
1354
  },
1356
1355
  )
1357
1356
 
@@ -1347,21 +1347,20 @@ class SonarWizAsyncApi:
1347
1347
  response.raise_for_status()
1348
1348
  return RawDepth.model_validate(response.json())
1349
1349
 
1350
- async def create_raw_sidescan_ping(self, ping: RawSidescanPingCreate) -> None:
1351
- """Create a raw sidescan ping record.
1350
+ async def create_raw_sidescan_pings(self, pings: list[RawSidescanPingCreate]) -> None:
1351
+ """Create raw sidescan ping records.
1352
1352
 
1353
1353
  Args:
1354
- ping: Raw sidescan ping creation data.
1354
+ pings: Raw sidescan ping creation data.
1355
1355
  """
1356
1356
  response = await self._client.post(
1357
- "/api/v1/raw-sidescan-pings", json=[ping.model_dump(mode="json")]
1357
+ "/api/v1/raw-sidescan-pings", json=[ping.model_dump(mode="json") for ping in pings]
1358
1358
  )
1359
1359
  response.raise_for_status()
1360
1360
  logger.debug(
1361
- "raw_sidescan_ping_created",
1361
+ "raw_sidescan_pings_created",
1362
1362
  extra={
1363
- "sidescan_ping_source_id": str(ping.sidescan_ping_source_id),
1364
- "ping_number_id": str(ping.ping_number_id),
1363
+ "count": len(pings),
1365
1364
  },
1366
1365
  )
1367
1366
 
@@ -1,76 +0,0 @@
1
- """Provides a shared, singleton instance of the ClarityApiAsyncClient.
2
-
3
- This module allows for a single, reusable async client to be initialized
4
- and accessed throughout the application, promoting connection reuse and
5
- efficiency. The client should be initialized at application startup
6
- and closed gracefully on shutdown.
7
-
8
- Example:
9
- # In your main application entry point
10
- import asyncio
11
- from cti.api.session import initialize_async_client, close_async_client
12
-
13
- async def main():
14
- await initialize_async_client()
15
- # ... your application logic ...
16
- await close_async_client()
17
-
18
- if __name__ == "__main__":
19
- asyncio.run(main())
20
-
21
- # In other modules
22
- from cti.api.session import get_async_client
23
-
24
- async def fetch_data():
25
- response = await get_async_client().get(...)
26
- return response.json()
27
- """
28
-
29
- # pylint: disable=global-statement, unnecessary-dunder-call
30
-
31
- from cti.api.async_client import ClarityApiAsyncClient
32
-
33
- # The singleton instance, initially None.
34
- async_client: ClarityApiAsyncClient | None = None
35
-
36
-
37
- async def initialize_async_client() -> None:
38
- """Initializes the shared ClarityApiAsyncClient instance.
39
-
40
- If the client is already initialized, this function does nothing.
41
- This function should be awaited at application startup.
42
- """
43
- global async_client
44
- if async_client is None:
45
- async_client = ClarityApiAsyncClient()
46
- await async_client.__aenter__()
47
-
48
-
49
- def get_async_client() -> ClarityApiAsyncClient:
50
- """Returns the shared ClarityApiAsyncClient instance.
51
-
52
- If the client is not initialized, this function initializes it first.
53
-
54
- Returns:
55
- ClarityApiAsyncClient: The shared ClarityApiAsyncClient instance.
56
-
57
- Raises:
58
- ValueError: If initialize_async_client() has not been called first.
59
- """
60
- if async_client is None:
61
- raise ValueError(
62
- "initialize_async_client() must be called first to initialize client."
63
- )
64
- return async_client
65
-
66
-
67
- async def close_async_client() -> None:
68
- """Closes the shared ClarityApiAsyncClient instance.
69
-
70
- This function should be awaited at application shutdown to ensure
71
- the underlying connection pool is closed gracefully.
72
- """
73
- global async_client
74
- if async_client:
75
- await async_client.__aexit__(None, None, None)
76
- async_client = None