clarity-api-sdk-python 0.1.6__tar.gz → 0.1.9__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.1.9/PKG-INFO +79 -0
  2. clarity_api_sdk_python-0.1.9/README.md +57 -0
  3. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/pyproject.toml +2 -2
  4. clarity_api_sdk_python-0.1.9/src/clarity_api_sdk_python.egg-info/PKG-INFO +79 -0
  5. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/clarity_api_sdk_python.egg-info/SOURCES.txt +2 -0
  6. clarity_api_sdk_python-0.1.9/src/cti/__init__.py +0 -0
  7. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/cti/logger/logger.py +33 -15
  8. clarity_api_sdk_python-0.1.9/src/cti/main.py +33 -0
  9. clarity_api_sdk_python-0.1.6/PKG-INFO +0 -31
  10. clarity_api_sdk_python-0.1.6/README.md +0 -9
  11. clarity_api_sdk_python-0.1.6/src/clarity_api_sdk_python.egg-info/PKG-INFO +0 -31
  12. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/setup.cfg +0 -0
  13. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/clarity_api_sdk_python.egg-info/dependency_links.txt +0 -0
  14. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/clarity_api_sdk_python.egg-info/requires.txt +0 -0
  15. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/clarity_api_sdk_python.egg-info/top_level.txt +0 -0
  16. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/cti/api/__init__.py +0 -0
  17. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/cti/api/client.py +0 -0
  18. {clarity_api_sdk_python-0.1.6 → clarity_api_sdk_python-0.1.9}/src/cti/logger/__init__.py +0 -0
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: clarity-api-sdk-python
3
+ Version: 0.1.9
4
+ Summary: A Python SDK to connect to the CTI Clarity API server.
5
+ Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
+ Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: httpx>=0.28.1
13
+ Requires-Dist: brotli
14
+ Requires-Dist: h2
15
+ Requires-Dist: httpx_auth>=0.23.1
16
+ Requires-Dist: httpx-retries>=0.4.5
17
+ Requires-Dist: structlog
18
+ Provides-Extra: brotli
19
+ Requires-Dist: httpx[brotli]>=0.28.1; extra == "brotli"
20
+ Provides-Extra: http2
21
+ Requires-Dist: httpx[http2]>=0.28.1; extra == "http2"
22
+
23
+ # Clarity API SDK for Python
24
+
25
+ [![PyPI - Downloads](https://badge.fury.io/py/clarity-api-sdk-python.svg)](https://pypi.org/project/clarity-api-sdk-python/)
26
+ [![Downloads](https://pepy.tech/badge/clarity-api-sdk-python)](ttps://test.pypi.org/project/clarity-api-sdk-python/)
27
+ ![python](https://img.shields.io/badge/python-3.11%2B-blue)
28
+
29
+ A Python SDK for connecting to the CTI API server, with structured logging included.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install clarity-api-sdk-python
35
+ ```
36
+
37
+ ## Logging
38
+
39
+ Logging support is built with [structlog](https://pypi.org/project/structlog/).
40
+
41
+ Set the root logger by setting the environment variable `LOG_LEVEL`. Otherwise, the default root logging is set to `INFO`.
42
+
43
+ ```python
44
+ """Example"""
45
+
46
+ import logging
47
+
48
+ from cti.logger import initialize_logger, get_logger, ExternalLoggerConfig
49
+
50
+ initialize_logger(
51
+ external_logger_configurations=[
52
+ ExternalLoggerConfig(name="urllib3"),
53
+ ExternalLoggerConfig(name="httpcore"),
54
+ ExternalLoggerConfig(name="httpx"),
55
+ ExternalLoggerConfig(name="httpx_auth"),
56
+ ExternalLoggerConfig(name="httpx_retries"),
57
+ ],
58
+ handlers=[logging.FileHandler("app.log")]
59
+ )
60
+
61
+ logger_a = get_logger("logger_a")
62
+ logger_b = get_logger("logger_b", "WARNING")
63
+
64
+ # root_logger = logging.getLogger()
65
+ # root_logger.setLevel("DEBUG")
66
+
67
+ logger_a.info("This is info message from logger_a")
68
+ logger_a.critical("This is critical message from logger_a")
69
+
70
+ # Dynamically change the log level of logger_a to WARNING
71
+ print("\nChanging logger_a level to WARNING...\n")
72
+ logging.getLogger("logger_a").setLevel(logging.WARNING)
73
+
74
+ logger_a.info("This info message from logger_a should NOT be visible.")
75
+ logger_a.warning("This is a new warning message from logger_a.")
76
+
77
+ logger_b.info("This info message from logger_b should NOT be visible.")
78
+ logger_b.warning("This is warning message from logger_b")
79
+ ```
@@ -0,0 +1,57 @@
1
+ # Clarity API SDK for Python
2
+
3
+ [![PyPI - Downloads](https://badge.fury.io/py/clarity-api-sdk-python.svg)](https://pypi.org/project/clarity-api-sdk-python/)
4
+ [![Downloads](https://pepy.tech/badge/clarity-api-sdk-python)](ttps://test.pypi.org/project/clarity-api-sdk-python/)
5
+ ![python](https://img.shields.io/badge/python-3.11%2B-blue)
6
+
7
+ A Python SDK for connecting to the CTI API server, with structured logging included.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install clarity-api-sdk-python
13
+ ```
14
+
15
+ ## Logging
16
+
17
+ Logging support is built with [structlog](https://pypi.org/project/structlog/).
18
+
19
+ Set the root logger by setting the environment variable `LOG_LEVEL`. Otherwise, the default root logging is set to `INFO`.
20
+
21
+ ```python
22
+ """Example"""
23
+
24
+ import logging
25
+
26
+ from cti.logger import initialize_logger, get_logger, ExternalLoggerConfig
27
+
28
+ initialize_logger(
29
+ external_logger_configurations=[
30
+ ExternalLoggerConfig(name="urllib3"),
31
+ ExternalLoggerConfig(name="httpcore"),
32
+ ExternalLoggerConfig(name="httpx"),
33
+ ExternalLoggerConfig(name="httpx_auth"),
34
+ ExternalLoggerConfig(name="httpx_retries"),
35
+ ],
36
+ handlers=[logging.FileHandler("app.log")]
37
+ )
38
+
39
+ logger_a = get_logger("logger_a")
40
+ logger_b = get_logger("logger_b", "WARNING")
41
+
42
+ # root_logger = logging.getLogger()
43
+ # root_logger.setLevel("DEBUG")
44
+
45
+ logger_a.info("This is info message from logger_a")
46
+ logger_a.critical("This is critical message from logger_a")
47
+
48
+ # Dynamically change the log level of logger_a to WARNING
49
+ print("\nChanging logger_a level to WARNING...\n")
50
+ logging.getLogger("logger_a").setLevel(logging.WARNING)
51
+
52
+ logger_a.info("This info message from logger_a should NOT be visible.")
53
+ logger_a.warning("This is a new warning message from logger_a.")
54
+
55
+ logger_b.info("This info message from logger_b should NOT be visible.")
56
+ logger_b.warning("This is warning message from logger_b")
57
+ ```
@@ -5,13 +5,13 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "clarity-api-sdk-python"
8
- version = "0.1.6"
8
+ version = "0.1.9"
9
9
  authors = [
10
10
  { name="Chesapeake Technology Inc.", email="support@chesapeaketech.com" },
11
11
  ]
12
12
  description = "A Python SDK to connect to the CTI Clarity API server."
13
13
  readme = "README.md"
14
- requires-python = ">=3.12"
14
+ requires-python = ">=3.11"
15
15
  classifiers = [
16
16
  "Programming Language :: Python :: 3",
17
17
  "License :: OSI Approved :: MIT License",
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: clarity-api-sdk-python
3
+ Version: 0.1.9
4
+ Summary: A Python SDK to connect to the CTI Clarity API server.
5
+ Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
+ Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: httpx>=0.28.1
13
+ Requires-Dist: brotli
14
+ Requires-Dist: h2
15
+ Requires-Dist: httpx_auth>=0.23.1
16
+ Requires-Dist: httpx-retries>=0.4.5
17
+ Requires-Dist: structlog
18
+ Provides-Extra: brotli
19
+ Requires-Dist: httpx[brotli]>=0.28.1; extra == "brotli"
20
+ Provides-Extra: http2
21
+ Requires-Dist: httpx[http2]>=0.28.1; extra == "http2"
22
+
23
+ # Clarity API SDK for Python
24
+
25
+ [![PyPI - Downloads](https://badge.fury.io/py/clarity-api-sdk-python.svg)](https://pypi.org/project/clarity-api-sdk-python/)
26
+ [![Downloads](https://pepy.tech/badge/clarity-api-sdk-python)](ttps://test.pypi.org/project/clarity-api-sdk-python/)
27
+ ![python](https://img.shields.io/badge/python-3.11%2B-blue)
28
+
29
+ A Python SDK for connecting to the CTI API server, with structured logging included.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install clarity-api-sdk-python
35
+ ```
36
+
37
+ ## Logging
38
+
39
+ Logging support is built with [structlog](https://pypi.org/project/structlog/).
40
+
41
+ Set the root logger by setting the environment variable `LOG_LEVEL`. Otherwise, the default root logging is set to `INFO`.
42
+
43
+ ```python
44
+ """Example"""
45
+
46
+ import logging
47
+
48
+ from cti.logger import initialize_logger, get_logger, ExternalLoggerConfig
49
+
50
+ initialize_logger(
51
+ external_logger_configurations=[
52
+ ExternalLoggerConfig(name="urllib3"),
53
+ ExternalLoggerConfig(name="httpcore"),
54
+ ExternalLoggerConfig(name="httpx"),
55
+ ExternalLoggerConfig(name="httpx_auth"),
56
+ ExternalLoggerConfig(name="httpx_retries"),
57
+ ],
58
+ handlers=[logging.FileHandler("app.log")]
59
+ )
60
+
61
+ logger_a = get_logger("logger_a")
62
+ logger_b = get_logger("logger_b", "WARNING")
63
+
64
+ # root_logger = logging.getLogger()
65
+ # root_logger.setLevel("DEBUG")
66
+
67
+ logger_a.info("This is info message from logger_a")
68
+ logger_a.critical("This is critical message from logger_a")
69
+
70
+ # Dynamically change the log level of logger_a to WARNING
71
+ print("\nChanging logger_a level to WARNING...\n")
72
+ logging.getLogger("logger_a").setLevel(logging.WARNING)
73
+
74
+ logger_a.info("This info message from logger_a should NOT be visible.")
75
+ logger_a.warning("This is a new warning message from logger_a.")
76
+
77
+ logger_b.info("This info message from logger_b should NOT be visible.")
78
+ logger_b.warning("This is warning message from logger_b")
79
+ ```
@@ -5,6 +5,8 @@ src/clarity_api_sdk_python.egg-info/SOURCES.txt
5
5
  src/clarity_api_sdk_python.egg-info/dependency_links.txt
6
6
  src/clarity_api_sdk_python.egg-info/requires.txt
7
7
  src/clarity_api_sdk_python.egg-info/top_level.txt
8
+ src/cti/__init__.py
9
+ src/cti/main.py
8
10
  src/cti/api/__init__.py
9
11
  src/cti/api/client.py
10
12
  src/cti/logger/__init__.py
File without changes
@@ -3,6 +3,7 @@
3
3
  from collections import OrderedDict
4
4
  from dataclasses import dataclass
5
5
  import logging
6
+ import os
6
7
  import socket
7
8
  import sys
8
9
  import urllib.error
@@ -32,16 +33,25 @@ class ExternalLoggerConfig:
32
33
  self.propagate = propagate
33
34
 
34
35
 
35
- def get_logger(name: str) -> logging.Logger:
36
+ def get_logger(
37
+ name: str, level: int | str | None = None
38
+ ) -> structlog.stdlib.BoundLogger:
36
39
  """Creates a structlog logger with the specified name.
37
40
 
38
41
  Args:
39
42
  name (str): The logger name.
43
+ level (int | str | None, optional): The logging level for this logger.
44
+ If None, the root logger's level is used. Defaults to None.
40
45
 
41
46
  Returns:
42
- logging.Logger: The structlog logger.
47
+ structlog.stdlib.BoundLogger: The structlog logger.
43
48
  """
44
- return structlog.get_logger(name)
49
+ logger = structlog.get_logger(name)
50
+ if level:
51
+ # To set the level, we need to get the actual standard library logger instance.
52
+ stdlib_logger = logging.getLogger(name)
53
+ stdlib_logger.setLevel(level)
54
+ return logger
45
55
 
46
56
 
47
57
  def _flatten_extra_processor(_, __, event_dict):
@@ -168,6 +178,7 @@ def _secret_redaction_processor(_, __, event_dict):
168
178
  def initialize_logger(
169
179
  initial_context: dict | None = None,
170
180
  external_logger_configurations: list[ExternalLoggerConfig] | None = None,
181
+ handlers: list[logging.Handler] | None = None,
171
182
  ) -> None:
172
183
  """Configures logging for the application using structlog.
173
184
 
@@ -194,15 +205,24 @@ def initialize_logger(
194
205
  bind to the context at the start of the application. These values
195
206
  will be included in every log message. Defaults to None.
196
207
  external_logger_configurations (list[ExternalLoggerConfig], optional): A list of configuration
208
+ handlers (list[logging.Handler], optional): A list of handlers to send log records to.
197
209
  """
198
210
  # Configure standard logging to be the sink for structlog.
199
211
  # The format="%(message)s" is important because structlog will format the log record
200
212
  # into a JSON string and pass it as the 'message'.
201
- logging.basicConfig(
202
- level=_level(),
203
- format="%(message)s",
204
- stream=sys.stdout,
205
- )
213
+ formatter = logging.Formatter("%(message)s")
214
+
215
+ # Create a handler for stdout
216
+ stdout_handler = logging.StreamHandler(sys.stdout)
217
+ stdout_handler.setFormatter(formatter)
218
+
219
+ # Get the root logger and add handlers
220
+ root_logger = logging.getLogger()
221
+ root_logger.addHandler(stdout_handler)
222
+ for handler in handlers or []:
223
+ handler.setFormatter(formatter)
224
+ root_logger.addHandler(handler)
225
+ root_logger.setLevel(_level())
206
226
 
207
227
  # configure external loggers
208
228
  if external_logger_configurations:
@@ -260,15 +280,13 @@ def initialize_logger(
260
280
  structlog.contextvars.bind_contextvars(**static_context)
261
281
 
262
282
 
263
- def _level():
283
+ def _level() -> str:
264
284
  """Get the log level for the logger.
265
285
 
266
- Set optional environment variable.
267
-
268
- - MANUAL only logs ERROR
269
- - PRODUCTION - turns off debug
286
+ The log level is determined by the `LOG_LEVEL` environment variable.
287
+ If the environment variable is not set, it defaults to "ERROR".
270
288
 
271
289
  Returns:
272
- str: log level
290
+ str: The log level as a string (e.g., "DEBUG", "INFO", "ERROR").
273
291
  """
274
- return "DEBUG"
292
+ return os.getenv("LOG_LEVEL", "INFO").upper()
@@ -0,0 +1,33 @@
1
+ """Example"""
2
+
3
+ import logging
4
+
5
+ from cti.logger import initialize_logger, get_logger, ExternalLoggerConfig
6
+
7
+ initialize_logger(
8
+ external_logger_configurations=[
9
+ ExternalLoggerConfig(name="urllib3"),
10
+ ExternalLoggerConfig(name="httpcore"),
11
+ ExternalLoggerConfig(name="httpx"),
12
+ ExternalLoggerConfig(name="httpx_auth"),
13
+ ExternalLoggerConfig(name="httpx_retries"),
14
+ ]
15
+ )
16
+
17
+ logger_a = get_logger("logger_a")
18
+ logger_b = get_logger("logger_b", "WARNING")
19
+
20
+ # root_logger = logging.getLogger()
21
+ # root_logger.setLevel("DEBUG")
22
+
23
+ logger_a.info("This is info message from logger_a")
24
+ logger_a.critical("This is critical message from logger_a")
25
+
26
+ # Dynamically change the log level of logger_a to WARNING
27
+ print("\nChanging logger_a level to WARNING...\n")
28
+ logging.getLogger("logger_a").setLevel(logging.WARNING)
29
+
30
+ logger_a.info("This info message from logger_a should NOT be visible.")
31
+ logger_a.warning("This is a new warning message from logger_a.")
32
+
33
+ logger_b.warning("This is warning message from logger_b")
@@ -1,31 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: clarity-api-sdk-python
3
- Version: 0.1.6
4
- Summary: A Python SDK to connect to the CTI Clarity API server.
5
- Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
- Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: >=3.12
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: httpx>=0.28.1
13
- Requires-Dist: brotli
14
- Requires-Dist: h2
15
- Requires-Dist: httpx_auth>=0.23.1
16
- Requires-Dist: httpx-retries>=0.4.5
17
- Requires-Dist: structlog
18
- Provides-Extra: brotli
19
- Requires-Dist: httpx[brotli]>=0.28.1; extra == "brotli"
20
- Provides-Extra: http2
21
- Requires-Dist: httpx[http2]>=0.28.1; extra == "http2"
22
-
23
- # Clarity API SDK for Python
24
-
25
- A Python SDK for connecting to the CTI API server, with structured logging included.
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install clarity-api-sdk-python
31
- ```
@@ -1,9 +0,0 @@
1
- # Clarity API SDK for Python
2
-
3
- A Python SDK for connecting to the CTI API server, with structured logging included.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- pip install clarity-api-sdk-python
9
- ```
@@ -1,31 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: clarity-api-sdk-python
3
- Version: 0.1.6
4
- Summary: A Python SDK to connect to the CTI Clarity API server.
5
- Author-email: "Chesapeake Technology Inc." <support@chesapeaketech.com>
6
- Project-URL: Homepage, https://github.com/chesapeake-tech/clarity-api-sdk-python
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Classifier: Operating System :: OS Independent
10
- Requires-Python: >=3.12
11
- Description-Content-Type: text/markdown
12
- Requires-Dist: httpx>=0.28.1
13
- Requires-Dist: brotli
14
- Requires-Dist: h2
15
- Requires-Dist: httpx_auth>=0.23.1
16
- Requires-Dist: httpx-retries>=0.4.5
17
- Requires-Dist: structlog
18
- Provides-Extra: brotli
19
- Requires-Dist: httpx[brotli]>=0.28.1; extra == "brotli"
20
- Provides-Extra: http2
21
- Requires-Dist: httpx[http2]>=0.28.1; extra == "http2"
22
-
23
- # Clarity API SDK for Python
24
-
25
- A Python SDK for connecting to the CTI API server, with structured logging included.
26
-
27
- ## Installation
28
-
29
- ```bash
30
- pip install clarity-api-sdk-python
31
- ```