sapiopycommons 2025.10.9a776__py3-none-any.whl → 2025.10.9a777__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.

@@ -17,6 +17,8 @@ from grpc import ServicerContext
17
17
  from sapiopylib.rest.User import SapioUser, ensure_logger_initialized
18
18
  from sapiopylib.rest.pojo.datatype.FieldDefinition import AbstractVeloxFieldDefinition
19
19
 
20
+ from sapiopycommons.ai.external_credentials import ExternalCredentials
21
+ from sapiopycommons.ai.protoapi.externalcredentials.external_credentials_pb2 import ExternalCredentialsPbo
20
22
  from sapiopycommons.ai.protoapi.fielddefinitions.fields_pb2 import FieldValueMapPbo, FieldValuePbo
21
23
  from sapiopycommons.ai.protoapi.fielddefinitions.velox_field_def_pb2 import VeloxFieldDefPbo, FieldTypePbo, \
22
24
  SelectionPropertiesPbo, IntegerPropertiesPbo, DoublePropertiesPbo, BooleanPropertiesPbo, StringPropertiesPbo, \
@@ -876,6 +878,38 @@ class AgentBase(ABC):
876
878
  """
877
879
  pass
878
880
 
881
+ def get_credentials(self, category: str = None, host: str = None) -> ExternalCredentials:
882
+ """
883
+ Get credentials for the given category and host.
884
+
885
+ :param category: The category of the credentials to retrieve.
886
+ :param host: The host for which to retrieve the credentials.
887
+ :return: An ExternalCredentials object containing the credentials for the given category and host.
888
+ """
889
+ # Remove leading/trailing whitespace
890
+ category = category.strip() if category else None
891
+ host = host.strip() if host else None
892
+
893
+ matching_creds: list[ExternalCredentialsPbo] = []
894
+ for cred in self.request.external_credential:
895
+ # Do case insensitive comparison
896
+ if category and cred.category.lower() != category.lower():
897
+ continue
898
+ if host:
899
+ # Parse the URL to get the host and compare
900
+ from urllib.parse import urlparse
901
+ parsed_url = urlparse(cred.url)
902
+ if parsed_url.hostname is None or parsed_url.hostname.lower() != host.lower():
903
+ continue
904
+
905
+ matching_creds.append(cred)
906
+ if len(matching_creds) == 0:
907
+ raise ValueError(f"No credentials found for category '{category}' and host '{host}'.")
908
+ if len(matching_creds) > 1:
909
+ raise ValueError(f"Multiple credentials found for category '{category}' and host '{host}'.")
910
+
911
+ return ExternalCredentials(matching_creds[0])
912
+
879
913
  def call_subprocess(self,
880
914
  args: str | bytes | PathLike[str] | PathLike[bytes] | Sequence[str | bytes | PathLike[str] | PathLike[bytes]],
881
915
  cwd: str | bytes | PathLike[str] | PathLike[bytes] | None = None,
@@ -0,0 +1,37 @@
1
+ from sapiopycommons.ai.protoapi.externalcredentials.external_credentials_pb2 import ExternalCredentialsPbo
2
+
3
+
4
+ class ExternalCredentials:
5
+ """
6
+ A class representing external credentials.
7
+ """
8
+ id: str
9
+ display_name: str
10
+ description: str
11
+ category: str
12
+ url: str
13
+ username: str
14
+ password: str
15
+ token: str
16
+ custom_fields: dict[str, str]
17
+
18
+ def __init__(self, pbo: ExternalCredentialsPbo):
19
+ self.id = pbo.id
20
+ self.display_name = pbo.display_name
21
+ self.description = pbo.description
22
+ self.category = pbo.category
23
+ self.url = pbo.url
24
+ self.username = pbo.username
25
+ self.password = pbo.password
26
+ self.token = pbo.token
27
+ self.custom_fields = dict(pbo.custom_field)
28
+
29
+ def get_custom_field(self, key: str, default: str = None) -> str | None:
30
+ """
31
+ Get a custom field by key.
32
+
33
+ :param key: The key of the custom field to retrieve.
34
+ :param default: The value to return if the key does not exist.
35
+ :return: The value of the custom field, or None if the key does not exist.
36
+ """
37
+ return self.custom_fields.get(key, default)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sapiopycommons
3
- Version: 2025.10.9a776
3
+ Version: 2025.10.9a777
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,8 @@
1
1
  sapiopycommons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sapiopycommons/ai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- sapiopycommons/ai/agent_service_base.py,sha256=52_QRjbMi6XYHC3oakX3mO5TOh6w8hieTbxzfKbFZWw,54600
3
+ sapiopycommons/ai/agent_service_base.py,sha256=3qU3_wy9wPuhZaRrPAzXNUe63pbQAQxqLnFPdhrm-08,56280
4
4
  sapiopycommons/ai/converter_service_base.py,sha256=HiUXmwqv1STgyQeF9_eTFXzjIFXp5-NJ7sEhMpV3aAU,6351
5
+ sapiopycommons/ai/external_credentials.py,sha256=40AI7VtHf6PzvwJLR_mZemUCrfAUvC--tGH-npaDIgo,1163
5
6
  sapiopycommons/ai/protobuf_utils.py,sha256=cBjbxoFAwU02kNUxEce95WnMU2CMuDD-qFaeWgvQJMQ,24599
6
7
  sapiopycommons/ai/request_validation.py,sha256=TD2EUi_G5cy1OOVK1AmY2SQc3PEoAKGWs2pT8Qnp2Oo,25092
7
8
  sapiopycommons/ai/server.py,sha256=gutSskn_Fenq1uz0DDMvjx4QVFiKt2WVEP3-01a69eU,6384
@@ -105,7 +106,7 @@ sapiopycommons/webhook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
105
106
  sapiopycommons/webhook/webhook_context.py,sha256=D793uLsb1691SalaPnBUk3rOSxn_hYLhdvkaIxjNXss,1909
106
107
  sapiopycommons/webhook/webhook_handlers.py,sha256=7o_wXOruhT9auNh8OfhJAh4WhhiPKij67FMBSpGPICc,39939
107
108
  sapiopycommons/webhook/webservice_handlers.py,sha256=cvW6Mk_110BzYqkbk63Kg7jWrltBCDALOlkJRu8h4VQ,14300
108
- sapiopycommons-2025.10.9a776.dist-info/METADATA,sha256=5yZk5DAAW1IHX_9fduVcHOOjludn5fBGykcvM0i4uE4,3142
109
- sapiopycommons-2025.10.9a776.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
110
- sapiopycommons-2025.10.9a776.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
111
- sapiopycommons-2025.10.9a776.dist-info/RECORD,,
109
+ sapiopycommons-2025.10.9a777.dist-info/METADATA,sha256=jvXJcvHI64AzlqRPyRwn7AJ5n1ZLP6eua8j6uOKZBEs,3142
110
+ sapiopycommons-2025.10.9a777.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
111
+ sapiopycommons-2025.10.9a777.dist-info/licenses/LICENSE,sha256=HyVuytGSiAUQ6ErWBHTqt1iSGHhLmlC8fO7jTCuR8dU,16725
112
+ sapiopycommons-2025.10.9a777.dist-info/RECORD,,