@@ -75,6 +75,7 @@ def create_channel(
7575 transport_mode : str ,
7676 host : str | None = None ,
7777 port : int | str | None = None ,
78+ uds_fullpath : str | Path | None = None ,
7879 uds_service : str | None = None ,
7980 uds_dir : str | Path | None = None ,
8081 uds_id : str | None = None ,
@@ -97,6 +98,9 @@ def create_channel(
9798 Port in which the server is running.
9899 By default `None` - however, if not using UDS transport mode,
99100 it will be requested.
101+ uds_fullpath : str | Path | None
102+ Full path to the UDS socket file.
103+ By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
100104 uds_service : str | None
101105 Optional service name for the UDS socket.
102106 By default `None` - however, if UDS is selected, it will
@@ -141,7 +145,7 @@ def check_host_port(transport_mode, host, port) -> tuple[str, str, str]:
141145 transport_mode , host , port = check_host_port (transport_mode , host , port )
142146 return create_insecure_channel (host , port , grpc_options )
143147 case "uds" :
144- return create_uds_channel (uds_service , uds_dir , uds_id , grpc_options )
148+ return create_uds_channel (uds_fullpath , uds_service , uds_dir , uds_id , grpc_options )
145149 case "wnua" :
146150 transport_mode , host , port = check_host_port (transport_mode , host , port )
147151 return create_wnua_channel (host , port , grpc_options )
@@ -186,7 +190,8 @@ def create_insecure_channel(
186190
187191
188192def create_uds_channel (
189- uds_service : str | None ,
193+ uds_fullpath : str | Path | None = None ,
194+ uds_service : str | None = None ,
190195 uds_dir : str | Path | None = None ,
191196 uds_id : str | None = None ,
192197 grpc_options : list [tuple [str , object ]] | None = None ,
@@ -195,6 +200,9 @@ def create_uds_channel(
195200
196201 Parameters
197202 ----------
203+ uds_fullpath : str | Path | None
204+ Full path to the UDS socket file.
205+ By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
198206 uds_service : str
199207 Service name for the UDS socket.
200208 uds_dir : str | Path | None
@@ -218,18 +226,22 @@ def create_uds_channel(
218226 if not is_uds_supported ():
219227 raise RuntimeError ("Unix Domain Sockets are not supported on this platform or gRPC version." )
220228
221- if not uds_service :
222- raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
229+ if uds_fullpath :
230+ target = f"unix:{ uds_fullpath } "
231+ else :
232+ if not uds_service :
233+ raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
234+
235+ # Determine UDS folder
236+ uds_folder = determine_uds_folder (uds_dir )
223237
224- # Determine UDS folder
225- uds_folder = determine_uds_folder ( uds_dir )
238+ # Make sure the folder exists
239+ uds_folder . mkdir ( parents = True , exist_ok = True )
226240
227- # Make sure the folder exists
228- uds_folder .mkdir (parents = True , exist_ok = True )
241+ # Generate socket filename with optional ID
242+ socket_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
243+ target = f"unix:{ uds_folder / socket_filename } "
229244
230- # Generate socket filename with optional ID
231- socket_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
232- target = f"unix:{ uds_folder / socket_filename } "
233245 # Set default authority to "localhost" for UDS connection
234246 # This is needed to avoid issues with some gRPC implementations,
235247 # see https://github.com/grpc/grpc/issues/34305
@@ -476,7 +488,12 @@ def verify_transport_mode(transport_mode: str, mode: str | None = None) -> None:
476488 raise ValueError (f"Invalid transport mode: { transport_mode } . Valid options are: { ', ' .join (valid_modes )} ." )
477489
478490
479- def verify_uds_socket (uds_service : str , uds_dir : Path | None = None , uds_id : str | None = None ) -> bool :
491+ def verify_uds_socket (
492+ uds_fullpath : str | Path | None = None ,
493+ uds_service : str | None = None ,
494+ uds_dir : Path | None = None ,
495+ uds_id : str | None = None ,
496+ ) -> bool :
480497 """Verify that the UDS socket file has been created.
481498
482499 Parameters
@@ -496,11 +513,18 @@ def verify_uds_socket(uds_service: str, uds_dir: Path | None = None, uds_id: str
496513 bool
497514 True if the UDS socket file exists, False otherwise.
498515 """
499- # Generate socket filename with optional ID
500- uds_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
516+ if uds_fullpath :
517+ return Path (uds_fullpath ).exists ()
518+
519+ else :
520+ if not uds_service :
521+ raise ValueError ("When using UDS transport mode, 'uds_service' must be provided." )
522+
523+ # Generate socket filename with optional ID
524+ uds_filename = f"{ uds_service } -{ uds_id } .sock" if uds_id else f"{ uds_service } .sock"
501525
502- # Full path to the UDS socket file
503- uds_socket_path = determine_uds_folder (uds_dir ) / uds_filename
526+ # Full path to the UDS socket file
527+ uds_socket_path = determine_uds_folder (uds_dir ) / uds_filename
504528
505- # Check if the UDS socket file exists
506- return uds_socket_path .exists ()
529+ # Check if the UDS socket file exists
530+ return uds_socket_path .exists ()
0 commit comments