From 3b2687c362580bf31282f9be6109bb9fde9cf9b7 Mon Sep 17 00:00:00 2001 From: Patrick Lundquist <1460278+patricklundquist@users.noreply.github.com> Date: Mon, 21 Jul 2025 21:11:52 -0700 Subject: [PATCH 1/2] Add func to return both stub and channel. --- clarifai/client/auth/helper.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clarifai/client/auth/helper.py b/clarifai/client/auth/helper.py index 7be9bc29..091a26a4 100644 --- a/clarifai/client/auth/helper.py +++ b/clarifai/client/auth/helper.py @@ -1,6 +1,7 @@ import os import urllib.request from typing import Any, Dict +import grpc from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel from clarifai_grpc.grpc.api import resources_pb2, service_pb2_grpc @@ -289,7 +290,11 @@ def metadata(self): ) def get_stub(self) -> service_pb2_grpc.V2Stub: - """Get the API gRPC stub using the right channel based on the API endpoint base. + stub, channel = self.get_stub_and_channel() + return stub + + def get_stub_and_channel(self) -> tuple[service_pb2_grpc.V2Stub, grpc.Channel]: + """Get the API gRPC stub and channel based on the API endpoint base. Returns: stub: The service_pb2_grpc.V2Stub stub for the API. @@ -310,7 +315,7 @@ def get_stub(self) -> service_pb2_grpc.V2Stub: port = 80 channel = ClarifaiChannel.get_insecure_grpc_channel(base=host, port=port) stub = service_pb2_grpc.V2Stub(channel) - return stub + return stub, channel def get_async_stub(self) -> service_pb2_grpc.V2Stub: """Get the API gRPC async stub using the right channel based on the API endpoint base. From a97f522e2683f3623eca3e0e0668a8482ffc7379 Mon Sep 17 00:00:00 2001 From: Patrick Lundquist <1460278+patricklundquist@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:16:39 -0700 Subject: [PATCH 2/2] tidy --- clarifai/client/auth/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clarifai/client/auth/helper.py b/clarifai/client/auth/helper.py index 091a26a4..41ebf049 100644 --- a/clarifai/client/auth/helper.py +++ b/clarifai/client/auth/helper.py @@ -1,8 +1,8 @@ import os import urllib.request from typing import Any, Dict -import grpc +import grpc from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel from clarifai_grpc.grpc.api import resources_pb2, service_pb2_grpc