sapiopycommons 2025.5.12a519__py3-none-any.whl → 2025.5.12a521__py3-none-any.whl

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 sapiopycommons might be problematic. Click here for more details.

@@ -1,12 +1,14 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import logging
4
5
  import traceback
5
6
  from abc import abstractmethod, ABC
7
+ from logging import Logger
6
8
  from typing import Any, Iterable, Sequence
7
9
 
8
10
  from grpc import ServicerContext
9
- from sapiopylib.rest.User import SapioUser
11
+ from sapiopylib.rest.User import SapioUser, ensure_logger_initialized
10
12
  from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition
11
13
 
12
14
  from sapiopycommons.ai.api.fielddefinitions.proto.fields_pb2 import FieldValueMapPbo, FieldValuePbo
@@ -305,8 +307,8 @@ class ToolServiceBase(ToolServiceServicer, ABC):
305
307
  tool.setup(user, request, context)
306
308
  results: list[SapioToolResult] = tool.run(user)
307
309
  return True, results, tool.logs
308
- except Exception:
309
- tool.log_message(traceback.format_exc())
310
+ except Exception as e:
311
+ tool.log_exception("Exception occurred during tool execution.", e)
310
312
  return False, [], tool.logs
311
313
 
312
314
 
@@ -321,6 +323,7 @@ class ToolBase(ABC):
321
323
  outputs: list[ToolOutputDetailsPbo]
322
324
  configs: list[VeloxFieldDefPbo]
323
325
  logs: list[str]
326
+ logger: Logger
324
327
 
325
328
  user: SapioUser
326
329
  request: ProcessStepRequestPbo
@@ -341,6 +344,8 @@ class ToolBase(ABC):
341
344
  self.outputs = []
342
345
  self.configs = []
343
346
  self.logs = []
347
+ self.logger = logging.getLogger(f"ToolBase.{self.name}")
348
+ ensure_logger_initialized(self.logger)
344
349
 
345
350
  def setup(self, user: SapioUser, request: ProcessStepRequestPbo, context: ServicerContext) -> None:
346
351
  """
@@ -624,16 +629,50 @@ class ToolBase(ABC):
624
629
  """
625
630
  pass
626
631
 
627
- def log_message(self, message: str, verbose: bool = False) -> None:
632
+ def log_info(self, message: str) -> None:
633
+ """
634
+ Log an info message for this tool. If verbose logging is enabled, this message will be included in the logs
635
+ returned to the caller.
636
+ .
637
+
638
+ :param message: The message to log.
639
+ """
640
+ msg = f"INFO: {self.name}: {message}"
641
+ if self.verbose_logging:
642
+ self.logs.append(msg)
643
+ self.logger.info(msg)
644
+
645
+ def log_warning(self, message: str) -> None:
646
+ """
647
+ Log a warning message for this tool. This message will be included in the logs returned to the caller.
648
+
649
+ :param message: The message to log.
650
+ """
651
+ msg = f"WARNING: {self.name}: {message}"
652
+ self.logs.append(msg)
653
+ self.logger.warning(msg)
654
+
655
+ def log_error(self, message: str) -> None:
656
+ """
657
+ Log an error message for this tool. This message will be included in the logs returned to the caller.
658
+
659
+ :param message: The message to log.
660
+ """
661
+ msg = f"ERROR: {self.name}: {message}"
662
+ self.logs.append(msg)
663
+ self.logger.error(msg)
664
+
665
+ def log_exception(self, message: str, e: Exception) -> None:
628
666
  """
629
- Log a message for this tool. This message will be included in the logs returned to the caller.
667
+ Log an exception for this tool. This message will be included in the logs returned to the caller.
630
668
 
631
669
  :param message: The message to log.
632
- :param verbose: If true, the message will only be logged if verbose logging is enabled. If false, the message
633
- will be logged regardless of the verbose logging setting.
670
+ :param e: The exception to log.
634
671
  """
635
- if not verbose or self.verbose_logging:
636
- self.logs.append(f"{self.name}: {message}")
672
+ msg = f"EXCEPTION: {self.name}: {message} - {e}"
673
+ self.logs.append(msg)
674
+ msg += "\n" + traceback.format_exc()
675
+ self.logger.error(msg)
637
676
 
638
677
  def get_input_binary(self, index: int = 0) -> list[bytes]:
639
678
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.5.12a519
3
+ Version: 2025.5.12a521
4
4
  Summary: Official Sapio Python API Utilities Package
5
5
  Project-URL: Homepage, https://github.com/sapiosciences
6
6
  Author-email: Jonathan Steck <jsteck@sapiosciences.com>, Yechen Qiao <yqiao@sapiosciences.com>
@@ -1,7 +1,7 @@
1
1
  sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  sapiopycommons/ai/protobuf_utils.py,sha256=aKmZtNLrrzUe_LFsdW0zYpG4VI-ZGgukyXVDFtIqfes,22656
4
- sapiopycommons/ai/tool_service_base.py,sha256=lJRR4jX9oRs56f9ysRbIbWe5tFOYrV6DXQlS0dbGa3M,32496
4
+ sapiopycommons/ai/tool_service_base.py,sha256=h9XtvPKaDBCVE9a6oRVU7ZkvqJhUPO9U0VaHX76JhXM,33728
5
5
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py,sha256=YcZjb_YM-XeLErM8hEC_S7vGMVGvcXAMGs2b-u5zvOE,2377
6
6
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi,sha256=FwtXmNAf7iYGEFm4kbqb04v77jNHbZg18ZmEDhle_bU,1444
7
7
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py,sha256=wPImJPdCUZNVEVoUWzsba9kGIXjEKPdUkawP5SnVyiU,932
@@ -85,7 +85,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
85
85
  sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
86
86
  sapiopycommons/webhook/webhook_handlers.py,sha256=L0HetSm43NvA5KyW3xbLpGFh2DbAaeZJVtXIEl2fvV8,39689
87
87
  sapiopycommons/webhook/webservice_handlers.py,sha256=Y5dHx_UFWFuSqaoPL6Re-fsKYRuxvCWZ8bj6KSZ3jfM,14285
88
- sapiopycommons-2025.5.12a519.dist-info/METADATA,sha256=ydyu7WKWgeim8QXQl90mu2FpgluAJUDW1TnmolC5Z9U,3143
89
- sapiopycommons-2025.5.12a519.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
90
- sapiopycommons-2025.5.12a519.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
91
- sapiopycommons-2025.5.12a519.dist-info/RECORD,,
88
+ sapiopycommons-2025.5.12a521.dist-info/METADATA,sha256=NDAG-QmrZ4B1l_8ZVl6iaEHGA296uwg7PL5sHF6uEoA,3143
89
+ sapiopycommons-2025.5.12a521.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
90
+ sapiopycommons-2025.5.12a521.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
91
+ sapiopycommons-2025.5.12a521.dist-info/RECORD,,