5050from databricks .sql .session import Session
5151from databricks .sql .backend .types import CommandId , BackendType , CommandState , SessionId
5252
53+ from databricks .sql .auth .common import ClientContext
54+ from databricks .sql .common .unified_http_client import UnifiedHttpClient
55+
5356from databricks .sql .thrift_api .TCLIService .ttypes import (
5457 TOpenSessionResp ,
5558 TSparkParameter ,
@@ -251,10 +254,14 @@ def read(self) -> Optional[OAuthToken]:
251254 "telemetry_batch_size" , TelemetryClientFactory .DEFAULT_BATCH_SIZE
252255 )
253256
257+ client_context = self ._build_client_context (server_hostname , ** kwargs )
258+ http_client = UnifiedHttpClient (client_context )
259+
254260 try :
255261 self .session = Session (
256262 server_hostname ,
257263 http_path ,
264+ http_client ,
258265 http_headers ,
259266 session_configuration ,
260267 catalog ,
@@ -270,6 +277,7 @@ def read(self) -> Optional[OAuthToken]:
270277 host_url = server_hostname ,
271278 http_path = http_path ,
272279 port = kwargs .get ("_port" , 443 ),
280+ http_client = http_client ,
273281 user_agent = self .session .useragent_header
274282 if hasattr (self , "session" )
275283 else None ,
@@ -342,6 +350,46 @@ def _set_use_inline_params_with_warning(self, value: Union[bool, str]):
342350
343351 return value
344352
353+ def _build_client_context (self , server_hostname : str , ** kwargs ):
354+ """Build ClientContext for HTTP client configuration."""
355+ from databricks .sql .auth .common import ClientContext
356+ from databricks .sql .types import SSLOptions
357+
358+ # Extract SSL options
359+ ssl_options = SSLOptions (
360+ tls_verify = not kwargs .get ("_tls_no_verify" , False ),
361+ tls_verify_hostname = kwargs .get ("_tls_verify_hostname" , True ),
362+ tls_trusted_ca_file = kwargs .get ("_tls_trusted_ca_file" ),
363+ tls_client_cert_file = kwargs .get ("_tls_client_cert_file" ),
364+ tls_client_cert_key_file = kwargs .get ("_tls_client_cert_key_file" ),
365+ tls_client_cert_key_password = kwargs .get ("_tls_client_cert_key_password" ),
366+ )
367+
368+ # Build user agent
369+ user_agent_entry = kwargs .get ("user_agent_entry" , "" )
370+ if user_agent_entry :
371+ user_agent = f"PyDatabricksSqlConnector/{ __version__ } ({ user_agent_entry } )"
372+ else :
373+ user_agent = f"PyDatabricksSqlConnector/{ __version__ } "
374+
375+ return ClientContext (
376+ hostname = server_hostname ,
377+ ssl_options = ssl_options ,
378+ socket_timeout = kwargs .get ("_socket_timeout" ),
379+ retry_stop_after_attempts_count = kwargs .get ("_retry_stop_after_attempts_count" , 30 ),
380+ retry_delay_min = kwargs .get ("_retry_delay_min" , 1.0 ),
381+ retry_delay_max = kwargs .get ("_retry_delay_max" , 60.0 ),
382+ retry_stop_after_attempts_duration = kwargs .get ("_retry_stop_after_attempts_duration" , 900.0 ),
383+ retry_delay_default = kwargs .get ("_retry_delay_default" , 1.0 ),
384+ retry_dangerous_codes = kwargs .get ("_retry_dangerous_codes" , []),
385+ http_proxy = kwargs .get ("_http_proxy" ),
386+ proxy_username = kwargs .get ("_proxy_username" ),
387+ proxy_password = kwargs .get ("_proxy_password" ),
388+ pool_connections = kwargs .get ("_pool_connections" , 1 ),
389+ pool_maxsize = kwargs .get ("_pool_maxsize" , 1 ),
390+ user_agent = user_agent ,
391+ )
392+
345393 # The ideal return type for this method is perhaps Self, but that was not added until 3.11, and we support pre-3.11 pythons, currently.
346394 def __enter__ (self ) -> "Connection" :
347395 return self
0 commit comments