clarity-api-sdk-python 0.2.11__tar.gz → 0.2.13__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 (18) hide show
  1. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/PKG-INFO +26 -1
  2. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/README.md +25 -0
  3. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/pyproject.toml +1 -1
  4. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/clarity_api_sdk_python.egg-info/PKG-INFO +26 -1
  5. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/clarity_api_sdk_python.egg-info/SOURCES.txt +2 -0
  6. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/api/__init__.py +1 -0
  7. clarity_api_sdk_python-0.2.13/src/cti/api/session.py +73 -0
  8. clarity_api_sdk_python-0.2.13/src/cti/main_api.py +19 -0
  9. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/setup.cfg +0 -0
  10. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/clarity_api_sdk_python.egg-info/dependency_links.txt +0 -0
  11. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/clarity_api_sdk_python.egg-info/requires.txt +0 -0
  12. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/clarity_api_sdk_python.egg-info/top_level.txt +0 -0
  13. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/__init__.py +0 -0
  14. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/api/async_client.py +0 -0
  15. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/api/client.py +0 -0
  16. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/logger/__init__.py +0 -0
  17. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/logger/logger.py +0 -0
  18. {clarity_api_sdk_python-0.2.11 → clarity_api_sdk_python-0.2.13}/src/cti/main.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clarity-api-sdk-python
3
- Version: 0.2.11
3
+ Version: 0.2.13
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
@@ -77,3 +77,28 @@ logger_a.warning("This is a new warning message from logger_a.")
77
77
  logger_b.info("This info message from logger_b should NOT be visible.")
78
78
  logger_b.warning("This is warning message from logger_b")
79
79
  ```
80
+
81
+ ## API
82
+
83
+ ### Singleton async client
84
+
85
+ ```python
86
+ import asyncio
87
+ from cti.api.session import initialize_async_client, close_async_client
88
+
89
+ async def main():
90
+ await initialize_async_client()
91
+ # ... your application logic ...
92
+ await close_async_client()
93
+
94
+ if __name__ == "__main__":
95
+ asyncio.run(main())
96
+
97
+ # In other modules
98
+ from cti.api.session import async_client
99
+
100
+ async def fetch_data():
101
+ if async_client:
102
+ response = await async_client.get(...)
103
+ return response.json()
104
+ ```
@@ -55,3 +55,28 @@ logger_a.warning("This is a new warning message from logger_a.")
55
55
  logger_b.info("This info message from logger_b should NOT be visible.")
56
56
  logger_b.warning("This is warning message from logger_b")
57
57
  ```
58
+
59
+ ## API
60
+
61
+ ### Singleton async client
62
+
63
+ ```python
64
+ import asyncio
65
+ from cti.api.session import initialize_async_client, close_async_client
66
+
67
+ async def main():
68
+ await initialize_async_client()
69
+ # ... your application logic ...
70
+ await close_async_client()
71
+
72
+ if __name__ == "__main__":
73
+ asyncio.run(main())
74
+
75
+ # In other modules
76
+ from cti.api.session import async_client
77
+
78
+ async def fetch_data():
79
+ if async_client:
80
+ response = await async_client.get(...)
81
+ return response.json()
82
+ ```
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "clarity-api-sdk-python"
8
- version = "0.2.11"
8
+ version = "0.2.13"
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.2.11
3
+ Version: 0.2.13
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
@@ -77,3 +77,28 @@ logger_a.warning("This is a new warning message from logger_a.")
77
77
  logger_b.info("This info message from logger_b should NOT be visible.")
78
78
  logger_b.warning("This is warning message from logger_b")
79
79
  ```
80
+
81
+ ## API
82
+
83
+ ### Singleton async client
84
+
85
+ ```python
86
+ import asyncio
87
+ from cti.api.session import initialize_async_client, close_async_client
88
+
89
+ async def main():
90
+ await initialize_async_client()
91
+ # ... your application logic ...
92
+ await close_async_client()
93
+
94
+ if __name__ == "__main__":
95
+ asyncio.run(main())
96
+
97
+ # In other modules
98
+ from cti.api.session import async_client
99
+
100
+ async def fetch_data():
101
+ if async_client:
102
+ response = await async_client.get(...)
103
+ return response.json()
104
+ ```
@@ -7,8 +7,10 @@ src/clarity_api_sdk_python.egg-info/requires.txt
7
7
  src/clarity_api_sdk_python.egg-info/top_level.txt
8
8
  src/cti/__init__.py
9
9
  src/cti/main.py
10
+ src/cti/main_api.py
10
11
  src/cti/api/__init__.py
11
12
  src/cti/api/async_client.py
12
13
  src/cti/api/client.py
14
+ src/cti/api/session.py
13
15
  src/cti/logger/__init__.py
14
16
  src/cti/logger/logger.py
@@ -2,3 +2,4 @@
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
@@ -0,0 +1,73 @@
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
+ def get_async_client() -> ClarityApiAsyncClient:
49
+ """Returns the shared ClarityApiAsyncClient instance.
50
+
51
+ If the client is not initialized, this function initializes it first.
52
+
53
+ Returns:
54
+ ClarityApiAsyncClient: The shared ClarityApiAsyncClient instance.
55
+
56
+ Raises:
57
+ ValueError: If initialize_async_client() has not been called first.
58
+ """
59
+ if async_client is None:
60
+ raise ValueError("initialize_async_client() must be called first to initialize client.")
61
+ return async_client
62
+
63
+
64
+ async def close_async_client() -> None:
65
+ """Closes the shared ClarityApiAsyncClient instance.
66
+
67
+ This function should be awaited at application shutdown to ensure
68
+ the underlying connection pool is closed gracefully.
69
+ """
70
+ global async_client
71
+ if async_client:
72
+ await async_client.__aexit__(None, None, None)
73
+ async_client = None
@@ -0,0 +1,19 @@
1
+ """Example"""
2
+
3
+ import asyncio
4
+
5
+ from cti.api.session import get_async_client, close_async_client, initialize_async_client
6
+
7
+ async def main():
8
+ """Example of using the Clarity API asynchronously
9
+ """
10
+ try:
11
+ await initialize_async_client()
12
+ client = get_async_client()
13
+ response = await client.get(url="/api/v1/status")
14
+ print(response.json())
15
+ finally:
16
+ await close_async_client()
17
+
18
+ if __name__ == "__main__":
19
+ asyncio.run(main())