sapiopycommons 2025.7.21a630__py3-none-any.whl → 2025.7.22a637__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,7 +1,9 @@
1
+ import base64
1
2
  import json
2
3
  from typing import Mapping, Any
3
4
 
4
5
  import grpc
6
+ from sapiopylib.rest.User import SapioUser
5
7
 
6
8
  from sapiopycommons.ai.api.fielddefinitions.proto.fields_pb2 import FieldValuePbo
7
9
  from sapiopycommons.ai.api.plan.tool.proto.entry_pb2 import DataTypePbo, StepBinaryContainerPbo, StepCsvRowPbo, \
@@ -77,35 +79,41 @@ class TestClient:
77
79
  A client for testing a ToolService. This client can be used to send requests to a tool and receive
78
80
  responses.
79
81
  """
80
- server_url: str
82
+ grpc_server_url: str
81
83
  connection: SapioConnectionInfoPbo
82
84
  _request_inputs: list[Any]
83
85
  _config_fields: dict[str, Any]
84
86
 
85
- def __init__(self, server_url: str):
87
+ def __init__(self, grpc_server_url: str, user: SapioUser | None = None):
86
88
  """
87
- :param server_url: The URL of the gRPC server to connect to.
89
+ :param grpc_server_url: The URL of the gRPC server to connect to.
90
+ :param user: Optional SapioUser object to use for the connection. If not provided, a default connection
91
+ will be created with test credentials.
88
92
  """
89
- self.create_user()
90
- self.server_url = server_url
93
+ self.grpc_server_url = grpc_server_url
94
+ self._create_connection(user)
91
95
  self._request_inputs = []
92
96
  self._config_fields = {}
93
97
 
94
- def create_user(self):
98
+ def _create_connection(self, user: SapioUser | None = None):
95
99
  """
96
100
  Create a SapioConnectionInfoPbo object with test credentials. This method can be overridden to
97
101
  create a user with specific credentials for testing.
98
102
  """
99
103
  self.connection = SapioConnectionInfoPbo()
100
- self.connection.username = "Testing"
101
- self.connection.webservice_url = "https://localhost:8080/webservice/api"
102
- self.connection.app_guid = "1234567890"
103
- self.connection.secret_type = SapioUserSecretTypePbo.PASSWORD
104
+ self.connection.username = user.username if user else "Testing"
105
+ self.connection.webservice_url = user.url if user else "https://localhost:8080/webservice/api"
106
+ self.connection.app_guid = user.guid if user else "1234567890"
104
107
  self.connection.rmi_host.append("Testing")
105
108
  self.connection.rmi_port = 9001
106
- self.connection.secret = "password"
107
-
108
- def add_input_input(self, input_data: list[bytes]) -> None:
109
+ if user and user.password:
110
+ self.connection.secret_type = SapioUserSecretTypePbo.PASSWORD
111
+ self.connection.secret = "Basic " + base64.b64encode(f'{user.username}:{user.password}'.encode()).decode()
112
+ else:
113
+ self.connection.secret_type = SapioUserSecretTypePbo.API_TOKEN
114
+ self.connection.secret = user.api_token if user and user.api_token else "test_api_token"
115
+
116
+ def add_binary_input(self, input_data: list[bytes]) -> None:
109
117
  """
110
118
  Add a binary input to the the next request.
111
119
  """
@@ -203,7 +211,7 @@ class TestClient:
203
211
 
204
212
  :return: A ToolDetailsResponsePbo object containing the details of the tool service.
205
213
  """
206
- with grpc.insecure_channel(self.server_url) as channel:
214
+ with grpc.insecure_channel(self.grpc_server_url) as channel:
207
215
  stub = ToolServiceStub(channel)
208
216
  return stub.GetToolDetails(ToolDetailsRequestPbo(sapio_conn_info=self.connection))
209
217
 
@@ -215,7 +223,7 @@ class TestClient:
215
223
  :param tool_name: The name of the tool to call on the server.
216
224
  :return: A ToolOutput object containing the results of the tool service call.
217
225
  """
218
- with grpc.insecure_channel(self.server_url) as channel:
226
+ with grpc.insecure_channel(self.grpc_server_url) as channel:
219
227
  stub = ToolServiceStub(channel)
220
228
 
221
229
  response: ProcessStepResponsePbo = stub.ProcessData(
@@ -278,9 +278,6 @@ class ToolServiceBase(ToolServiceServicer, ABC):
278
278
  """
279
279
  return: Get instances of the tools registered with this service.
280
280
  """
281
- # This is complaining about the name and description not being filled from ToolBase,
282
- # but none of the provided tools should have any init parameters.
283
- # noinspection PyArgumentList
284
281
  tools: list[ToolBase] = [x() for x in self.register_tools()]
285
282
  if not tools:
286
283
  raise Exception("No tools registered with this service.")
@@ -348,16 +345,35 @@ class ToolBase(ABC):
348
345
  request: ProcessStepRequestPbo
349
346
  context: ServicerContext
350
347
 
351
- def __init__(self, name: str, description: str, data_type_name: str | None = None):
348
+ @staticmethod
349
+ @abstractmethod
350
+ def name() -> str:
351
+ """
352
+ :return: The name of the tool. This should be unique across all tools in the service.
353
+ """
354
+ pass
355
+
356
+ @staticmethod
357
+ @abstractmethod
358
+ def description() -> str:
352
359
  """
353
- :param name: The name of the tool.
354
- :param description: A description of the tool.
355
- :param data_type_name: The name of the output data type of this tool, if applicable. When this tool returns
360
+ :return: A description of the tool.
361
+ """
362
+ pass
363
+
364
+ @staticmethod
365
+ @abstractmethod
366
+ def data_type_name() -> str | None:
367
+ """
368
+ :return: The name of the output data type of this tool, if applicable. When this tool returns
356
369
  FieldMapResult objects in its run method, this name will be used to set the data type of the output data.
357
370
  """
358
- self.name = name
359
- self.description = description
360
- self.data_type_name = data_type_name
371
+ return None
372
+
373
+ def __init__(self):
374
+ self.name = self.name()
375
+ self.description = self.description()
376
+ self.data_type_name = self.data_type_name()
361
377
  self.inputs = []
362
378
  self.outputs = []
363
379
  self.configs = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.7.21a630
3
+ Version: 2025.7.22a637
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,8 +1,8 @@
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=8VYGhAdD731Ojy5PTy61PlTcvfEdydkIdX-4rOFPtxM,24911
4
- sapiopycommons/ai/test_client.py,sha256=PCc5s_-Uo8_CVsB1rpwvHtvXfHKa2iuZnC7VK-9cAoE,10457
5
- sapiopycommons/ai/tool_service_base.py,sha256=ezNXOEPN3-4_FFiDDJ80hBLj3ZhC_xsQKPZZHAhp4uQ,41802
4
+ sapiopycommons/ai/test_client.py,sha256=C8yr4Zp4vflRxufD2oUD45PVmQnfra5hi6flKJ230Tg,11169
5
+ sapiopycommons/ai/tool_service_base.py,sha256=r_QJHcN1z1umzet9av7N66Mk5tIVaWPfEHDQzveYzwc,41884
6
6
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.py,sha256=YcZjb_YM-XeLErM8hEC_S7vGMVGvcXAMGs2b-u5zvOE,2377
7
7
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2.pyi,sha256=FwtXmNAf7iYGEFm4kbqb04v77jNHbZg18ZmEDhle_bU,1444
8
8
  sapiopycommons/ai/api/fielddefinitions/proto/fields_pb2_grpc.py,sha256=wPImJPdCUZNVEVoUWzsba9kGIXjEKPdUkawP5SnVyiU,932
@@ -90,7 +90,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
90
90
  sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
91
91
  sapiopycommons/webhook/webhook_handlers.py,sha256=7o_wXOruhT9auNh8OfhJAh4WhhiPKij67FMBSpGPICc,39939
92
92
  sapiopycommons/webhook/webservice_handlers.py,sha256=tyaYGG1-v_JJrJHZ6cy5mGCxX9z1foLw7pM4MDJlFxs,14297
93
- sapiopycommons-2025.7.21a630.dist-info/METADATA,sha256=UXQiQOApr9tU_aSyBOZ1U6dpWeB3jNwvl7WjBWFp2VE,3143
94
- sapiopycommons-2025.7.21a630.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
95
- sapiopycommons-2025.7.21a630.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
96
- sapiopycommons-2025.7.21a630.dist-info/RECORD,,
93
+ sapiopycommons-2025.7.22a637.dist-info/METADATA,sha256=5XWnDlnBTpUOuqdFcZWfLf2Hcsvo3XBqsX0TbWvCAIY,3143
94
+ sapiopycommons-2025.7.22a637.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
95
+ sapiopycommons-2025.7.22a637.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
96
+ sapiopycommons-2025.7.22a637.dist-info/RECORD,,