python-sdk-remote 0.0.145__tar.gz → 0.0.146__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.

Potentially problematic release.


This version of python-sdk-remote might be problematic. Click here for more details.

Files changed (23) hide show
  1. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/PKG-INFO +1 -1
  2. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/README.md +1 -1
  3. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/constants.py +1 -0
  4. python_sdk_remote-0.0.146/python_sdk_remote/src/constants_src_mini_logger.py +14 -0
  5. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/http_response.py +2 -2
  6. python_sdk_remote-0.0.146/python_sdk_remote/src/mini_logger.py +146 -0
  7. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/utilities.py +25 -14
  8. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote.egg-info/PKG-INFO +1 -1
  9. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote.egg-info/SOURCES.txt +1 -0
  10. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/setup.py +1 -1
  11. python_sdk_remote-0.0.145/python_sdk_remote/src/mini_logger.py +0 -132
  12. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/pyproject.toml +0 -0
  13. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/__init__.py +0 -0
  14. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/is_test_data.py +0 -0
  15. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/item.py +0 -0
  16. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/our_object.py +0 -0
  17. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/unified_json.py +0 -0
  18. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/valid_json_versions.py +0 -0
  19. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote/src/validate_environment.py +0 -0
  20. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote.egg-info/dependency_links.txt +0 -0
  21. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote.egg-info/requires.txt +0 -0
  22. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/python_sdk_remote.egg-info/top_level.txt +0 -0
  23. {python_sdk_remote-0.0.145 → python_sdk_remote-0.0.146}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-sdk-remote
3
- Version: 0.0.145
3
+ Version: 0.0.146
4
4
  Summary: PyPI Package for Circles Python SDK Local Python
5
5
  Home-page: https://github.com/circles-zone/python-sdk-remote-python-package
6
6
  Author: Circles
@@ -8,4 +8,4 @@ logger = Logger.create_logger(object=your_logger_object)
8
8
  @handler_decorator(logger=logger)
9
9
  def my_handler(request_parameters: dict) -> dict:
10
10
  # here you can use both camelCase and snake_case keys from request_parameters
11
- ```
11
+ ```# dummy change
@@ -17,3 +17,4 @@ OBJECT_TO_INSERT_TEST = {
17
17
  'testing_framework': LoggerComponentEnum.testingFramework.pytest.value,
18
18
  'developer_email': 'sahar.g@circ.zone'
19
19
  }
20
+
@@ -0,0 +1,14 @@
1
+ from enum import Enum
2
+
3
+ class LogMessageSeverity(Enum):
4
+ Debug = 100
5
+ Verbose = 200
6
+ Init = 300
7
+ Info = 500
8
+ Warning = 600
9
+ Error = 700
10
+ Critical = 800
11
+ Exception = 900
12
+ class StartEndEnum(Enum):
13
+ Start = 400
14
+ End = 402
@@ -11,7 +11,7 @@ AUTHORIZATION_KEY = 'authorization'
11
11
  AUTHORIZATION_PREFIX = 'Bearer '
12
12
 
13
13
 
14
- # TODO Align those methods with typescript-sdk https://github.com/circles-zone/typescript-sdk-remote-typescript-package/blob/dev/typescript-sdk/src/utils/index.ts
14
+ # TODO Align those methods with typescript-sdk https://github.com/circles-zone/typescript-sdk-remote-typescript-package/blob/dev/typescript-sdk/src/utils/index.ts # noqa: E501
15
15
  # TODO Shall we create also createInternalServerErrorHttpResponse(), createOkHttpResponse() like we have in TypeScript?
16
16
 
17
17
  # TODO: add handler wrapper?
@@ -104,7 +104,7 @@ def get_user_jwt_from_event(event: dict) -> str:
104
104
  def create_return_http_headers() -> dict:
105
105
  logger.start()
106
106
  # Adding "Access-Control-Allow-Origin" : "*" to take care of CORS from localhost
107
- # TODO Do we need to add those? In which cases? try adding crossDomain: true, to the request, 'Access-Control-Allow-Credentials': true to header
107
+ # TODO Do we need to add those? In which cases? try adding crossDomain: true, to the request, 'Access-Control-Allow-Credentials': true to header # noqa: E501
108
108
  return_http_headers = {
109
109
  "Content-Type": "application/json",
110
110
  "Access-Control-Allow-Origin": "*",
@@ -0,0 +1,146 @@
1
+ import logging
2
+ import os
3
+ import sys
4
+ from enum import Enum
5
+ import inspect
6
+ from src.constants_src_mini_logger import LogMessageSeverity, StartEndEnum
7
+
8
+ # TODO LOGGER_MINIMAL_SEVERITY_DEFAULT
9
+ LOGGER_MINIMUM_SEVERITY = os.getenv("LOGGER_MINIMUM_SEVERITY", "INFO").upper()
10
+ # logging expects NOTSET/DEBUG/INFO/WARNING/ERROR/FATAL/CRITICAL
11
+ if LOGGER_MINIMUM_SEVERITY.isdigit():
12
+ # TODO logger_minimal_severity_default_value
13
+ logger_minimum_severity = int(LOGGER_MINIMUM_SEVERITY)
14
+ # TODO Change Magic Numbers and use the values from Logger.MessageSeverity
15
+ if logger_minimum_severity < LogMessageSeverity.Start.value:
16
+ # TODO LOGGER_MINIMAL_SEVERITY_DEFAULT_NAME =
17
+ # TODO Change "DEBUG", "INFO", "WARNING" ... into enum values from Logger.LogMessageSeverity
18
+ LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Debug
19
+ elif logger_minimum_severity < LogMessageSeverity.Warning.value:
20
+ LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Info
21
+ elif logger_minimum_severity < LogMessageSeverity.Error.value:
22
+ LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Warning
23
+ elif logger_minimum_severity < LogMessageSeverity.Critical.value:
24
+ LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Error
25
+ else:
26
+ LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Critical
27
+
28
+ logging.basicConfig(level=LOGGER_MINIMUM_SEVERITY, stream=sys.stdout,
29
+ format="%(asctime)s - %(message)s")
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class MiniLogger:
34
+ # TODO Can we so one generic function call by all
35
+
36
+ @staticmethod
37
+ def _log(level: LogMessageSeverity, start_or_end: StartEndEnum = None, log_message: str = None, **kwargs):
38
+ """
39
+ Private method to unify all log methods
40
+
41
+ Parameters:
42
+ level (MessageSeverity): log level
43
+ log_message (str): The message to be printed.
44
+ """
45
+ object = kwargs.get("object")
46
+ method_name = level.name.lower()
47
+ method = getattr(logger, method_name)
48
+ if not start_or_end:
49
+ action_name = level.name
50
+ else:
51
+ action_name = start_or_end.name
52
+ stk = inspect.stack()[2]
53
+ function = stk.function
54
+ line = stk.lineno
55
+ if object is None:
56
+ method(f"Function: {function}, Line: {line}; {action_name} - {log_message}")
57
+ else:
58
+ method(f"Function: {function}, Line: {line}; {action_name} - {log_message} - {object}")
59
+
60
+
61
+ @staticmethod
62
+ # TODO Add a new file called align_logger_and_minilogger_test.py, which makes sure the signature of all methods of MiniLogger and Logger are the same and we can change from MiniLogger to Logger and vice versa by changing only one line in our code. If we should change the signatures, we should make them backward compatible.
63
+ def start(log_message: str = None, **kwargs):
64
+ """
65
+ Print a log message with the current time.
66
+
67
+ Parameters:
68
+ log_message (str): The message to be printed.
69
+ """
70
+ MiniLogger._log(LogMessageSeverity.Debug, StartEndEnum.Start, log_message, **kwargs)
71
+
72
+ @staticmethod
73
+ def end(log_message: str = None, **kwargs):
74
+ """
75
+ Print a log message with the current time.
76
+
77
+ Parameters:
78
+ log_message (str): The message to be printed.
79
+ """
80
+ MiniLogger._log(LogMessageSeverity.Debug, StartEndEnum.End, log_message, **kwargs)
81
+
82
+ # TODO convert all those methods (debug, info, warning, error) into one unified private method
83
+ # TODO Add to the unified private method print of the name of method, version
84
+ # and line number of the calling function/method to the mini_logger methods
85
+ @staticmethod
86
+ def debug(log_message: str = None, **kwargs):
87
+ """
88
+ Print a log message with the current time.
89
+
90
+ Parameters:
91
+ log_message (str): The message to be printed.
92
+ """
93
+ MiniLogger._log(LogMessageSeverity.Debug, log_message=log_message, **kwargs)
94
+
95
+ @staticmethod
96
+ def info(log_message: str = None, **kwargs):
97
+ """
98
+ Print a log message with the current time.
99
+
100
+ Parameters:
101
+ log_message (str): The message to be printed.
102
+ """
103
+ MiniLogger._log(LogMessageSeverity.Info, log_message=log_message, **kwargs)
104
+
105
+ @staticmethod
106
+ def warning(log_message: str = None, **kwargs):
107
+ """
108
+ Print a log message with the current time.
109
+
110
+ Parameters:
111
+ log_message (str): The message to be printed.
112
+ """
113
+ # TODO Add the source of the message - We should add the object or atleast some parts of it
114
+ MiniLogger._log(LogMessageSeverity.Warning, log_message=log_message, **kwargs)
115
+
116
+
117
+ @staticmethod
118
+ def error(log_message: str = None, **kwargs):
119
+ """
120
+ Print a log error message with the current time.
121
+
122
+ Parameters:
123
+ log_message (str): The message to be printed.
124
+ """
125
+ MiniLogger._log(LogMessageSeverity.Error, log_message=log_message, **kwargs)
126
+
127
+ @staticmethod
128
+ def exception(log_message: str = None, **kwargs):
129
+ """
130
+ Print a log error message with the current time.
131
+
132
+ Parameters:
133
+ log_message (str): The message to be printed.
134
+ """
135
+ object = kwargs.get("object")
136
+ if isinstance(object, Exception):
137
+ exception = object
138
+ elif isinstance(object, dict):
139
+ exception = object.get("exception")
140
+ else:
141
+ exception = None
142
+
143
+ if object is None:
144
+ logger.exception(f"EXCEPTION - {log_message}")
145
+ else:
146
+ logger.exception(f"EXCEPTION- {log_message} - {object}", exc_info=exception)
@@ -279,42 +279,53 @@ def is_datetime_in_datetime_range(check_datetime: datetime, datetime_range: (dat
279
279
  return is_datetime_in_datetime_range_result
280
280
 
281
281
 
282
- def get_brand_name() -> str:
283
- get_brand_name_result = our_get_env("BRAND_NAME")
282
+ def get_brand_name(raise_if_not_found: bool = True,
283
+ raise_if_empty: bool = False) -> str:
284
+ get_brand_name_result = our_get_env("BRAND_NAME",
285
+ raise_if_not_found=raise_if_not_found,
286
+ raise_if_empty=raise_if_empty)
284
287
  return get_brand_name_result
285
288
 
286
289
 
287
- def get_environment_name() -> str:
288
- environment_name = our_get_env("ENVIRONMENT_NAME")
290
+ def get_environment_name(raise_if_not_found: bool = True,
291
+ raise_if_empty: bool = False) -> str:
292
+ environment_name = our_get_env("ENVIRONMENT_NAME",
293
+ raise_if_not_found=raise_if_not_found,
294
+ raise_if_empty=raise_if_empty)
289
295
  EnvironmentName(environment_name) # if invalid, raises ValueError: x is not a valid EnvironmentName
290
296
  return environment_name
291
297
 
292
298
 
293
299
  def our_get_env(key: str, default: str = None, raise_if_not_found: bool = True,
294
300
  raise_if_empty: bool = False) -> str:
295
- logger.start(object={"key": key, "default": default, "raise_if_not_found": raise_if_not_found,
301
+ logger.start(object={"key": key, "default": default,
302
+ "raise_if_not_found": raise_if_not_found,
296
303
  "raise_if_empty": raise_if_empty})
297
304
  env_var = os.getenv(key, default)
305
+ # TODO: "default is None" is always False
298
306
  if ((raise_if_not_found and key not in os.environ and default is None)
299
307
  or (raise_if_empty and not env_var and not default)):
300
- raise Exception(f"Environment variable {key} not found - please check your .env file")
308
+ raise Exception(f"Environment variable {key} not found - please check your .env file") # noqa: E501
301
309
  logger.end(object={"env_var": env_var})
302
310
  return env_var
303
311
 
304
312
 
305
- # TODO As only the database package uses those, let's move those three to the database package
306
- def get_sql_hostname() -> str:
307
- get_sql_hostname_result = our_get_env("RDS_HOSTNAME")
313
+ # TODO As only the database package uses those, let's move those three to the database package # noqa: E501
314
+ def get_sql_hostname(raise_if_not_found: bool = True, raise_if_empty: bool = False) -> str:
315
+ get_sql_hostname_result = our_get_env("RDS_HOSTNAME",
316
+ raise_if_empty=raise_if_empty)
308
317
  return get_sql_hostname_result
309
318
 
310
319
 
311
- def get_sql_username() -> str:
312
- get_sql_username_result = our_get_env("RDS_USERNAME")
320
+ def get_sql_username(raise_if_empty: bool = False) -> str:
321
+ get_sql_username_result = our_get_env("RDS_USERNAME",
322
+ raise_if_empty=raise_if_empty)
313
323
  return get_sql_username_result
314
324
 
315
325
 
316
- def get_sql_password() -> str:
317
- get_sql_password_result = our_get_env("RDS_PASSWORD")
326
+ def get_sql_password(raise_if_empty: bool = False) -> str:
327
+ get_sql_password_result = our_get_env("RDS_PASSWORD",
328
+ raise_if_empty=raise_if_empty)
318
329
  return get_sql_password_result
319
330
 
320
331
 
@@ -405,7 +416,7 @@ def validate_arguments(args: dict) -> None:
405
416
  :return: True if all arguments are not None or '', False otherwise
406
417
  """
407
418
  for arg, value in args.items():
408
- if not arg:
419
+ if not value:
409
420
  raise ValueError(f"Argument {arg} is cannot be empty (got {value})")
410
421
 
411
422
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-sdk-remote
3
- Version: 0.0.145
3
+ Version: 0.0.146
4
4
  Summary: PyPI Package for Circles Python SDK Local Python
5
5
  Home-page: https://github.com/circles-zone/python-sdk-remote-python-package
6
6
  Author: Circles
@@ -8,6 +8,7 @@ python_sdk_remote.egg-info/requires.txt
8
8
  python_sdk_remote.egg-info/top_level.txt
9
9
  python_sdk_remote/src/__init__.py
10
10
  python_sdk_remote/src/constants.py
11
+ python_sdk_remote/src/constants_src_mini_logger.py
11
12
  python_sdk_remote/src/http_response.py
12
13
  python_sdk_remote/src/is_test_data.py
13
14
  python_sdk_remote/src/item.py
@@ -7,7 +7,7 @@ package_dir = PACKAGE_NAME.replace("-", "_")
7
7
  # python -m build needs pyproject.toml or setup.py
8
8
  setuptools.setup(
9
9
  name=PACKAGE_NAME,
10
- version='0.0.145', # https://pypi.org/project/python-sdk-remote/
10
+ version='0.0.146', # https://pypi.org/project/python-sdk-remote/
11
11
  author="Circles",
12
12
  author_email="info@circlez.ai",
13
13
  description="PyPI Package for Circles Python SDK Local Python",
@@ -1,132 +0,0 @@
1
- import logging
2
- import os
3
- import sys
4
-
5
- LOGGER_MINIMUM_SEVERITY = os.getenv("LOGGER_MINIMUM_SEVERITY", "INFO").upper()
6
- # logging expects NOTSET/DEBUG/INFO/WARNING/ERROR/FATAL/CRITICAL
7
- if LOGGER_MINIMUM_SEVERITY.isdigit():
8
- logger_minimum_severity = int(LOGGER_MINIMUM_SEVERITY)
9
- # Values from Logger.MessageSeverity
10
- if logger_minimum_severity < 400:
11
- LOGGER_MINIMUM_SEVERITY = "DEBUG"
12
- elif logger_minimum_severity < 600:
13
- LOGGER_MINIMUM_SEVERITY = "INFO"
14
- elif logger_minimum_severity < 700:
15
- LOGGER_MINIMUM_SEVERITY = "WARNING"
16
- elif logger_minimum_severity < 800:
17
- LOGGER_MINIMUM_SEVERITY = "ERROR"
18
- else:
19
- LOGGER_MINIMUM_SEVERITY = "CRITICAL"
20
-
21
- logging.basicConfig(level=LOGGER_MINIMUM_SEVERITY, stream=sys.stdout,
22
- format="%(asctime)s - %(message)s")
23
- logger = logging.getLogger(__name__)
24
-
25
-
26
- class MiniLogger:
27
- # TODO Can we so one generic function call by all
28
-
29
- @staticmethod
30
- def start(message: str = "", object: dict = None):
31
- """
32
- Print a log message with the current time.
33
-
34
- Parameters:
35
- message (str): The message to be printed.
36
- object (dict): The object to be printed.
37
- """
38
- if object is None:
39
- logger.debug(f"START - {message}")
40
- else:
41
- logger.debug(f"START - {message} - {object}")
42
-
43
- @staticmethod
44
- def end(message: str = "", object: dict = None):
45
- """
46
- Print a log message with the current time.
47
-
48
- Parameters:
49
- message (str): The message to be printed.
50
- """
51
- if object is None:
52
- logger.debug(f"END - {message}")
53
- else:
54
- logger.debug(f"END - {message} - {object}")
55
-
56
- @staticmethod
57
- def debug(message: str = "", object: dict = None):
58
- """
59
- Print a log message with the current time.
60
-
61
- Parameters:
62
- message (str): The message to be printed.
63
- object (dict): The object to be printed.
64
- """
65
- if object is None:
66
- logger.debug(f"DEBUG - {message}")
67
- else:
68
- logger.debug(f"DEBUG {message} - {object}")
69
-
70
- @staticmethod
71
- def info(message: str = "", object: dict = None):
72
- """
73
- Print a log message with the current time.
74
-
75
- Parameters:
76
- message (str): The message to be printed.
77
- object (dict): The object to be printed.
78
- """
79
- if object is None:
80
- logger.info(f"INFO - {message}")
81
- else:
82
- logger.info(f"INFO {message} - {object}")
83
-
84
- @staticmethod
85
- def warning(message: str = "", object: dict = None):
86
- """
87
- Print a log message with the current time.
88
-
89
- Parameters:
90
- message (str): The message to be printed.
91
- object (dict): The object to be printed.
92
- """
93
- # TODO Add the source of the message - We should add the object or atleast some parts of it
94
- if object is None:
95
- logger.warning(f"WARNING - {message}")
96
- else:
97
- logger.warning(f"WARNING {message} - {object}")
98
-
99
- @staticmethod
100
- def error(message: str = "", object: dict = None):
101
- """
102
- Print a log error message with the current time.
103
-
104
- Parameters:
105
- message (str): The message to be printed.
106
- object (dict): The object to be printed.
107
- """
108
- if object is None:
109
- logger.error(f"ERROR - {message}")
110
- else:
111
- logger.error(f"ERROR - {message} - {object}")
112
-
113
- @staticmethod
114
- def exception(message: str = "", object: Exception or dict = None):
115
- """
116
- Print a log error message with the current time.
117
-
118
- Parameters:
119
- message (str): The message to be printed.
120
- object (dict / Exception): The object / Exception to be printed.
121
- """
122
- if isinstance(object, Exception):
123
- exception = object
124
- elif isinstance(object, dict):
125
- exception = object.get("exception")
126
- else:
127
- exception = None
128
-
129
- if object is None:
130
- logger.exception(f"EXCEPTION - {message}")
131
- else:
132
- logger.exception(f"EXCEPTION- {message} - {object}", exc_info=exception)