1616
1717from __future__ import annotations
1818
19- from typing import Literal , Optional
19+ from typing import Literal , Optional , Sequence , Tuple
2020import warnings
2121
2222import google .auth .credentials
23+ import requests .adapters
2324
2425import bigframes .enums
2526import bigframes .exceptions as bfe
@@ -90,6 +91,9 @@ def __init__(
9091 allow_large_results : bool = False ,
9192 ordering_mode : Literal ["strict" , "partial" ] = "strict" ,
9293 client_endpoints_override : Optional [dict ] = None ,
94+ requests_transport_adapters : Sequence [
95+ Tuple [str , requests .adapters .BaseAdapter ]
96+ ] = (),
9397 ):
9498 self ._credentials = credentials
9599 self ._project = project
@@ -100,6 +104,7 @@ def __init__(
100104 self ._kms_key_name = kms_key_name
101105 self ._skip_bq_connection_check = skip_bq_connection_check
102106 self ._allow_large_results = allow_large_results
107+ self ._requests_transport_adapters = requests_transport_adapters
103108 self ._session_started = False
104109 # Determines the ordering strictness for the session.
105110 self ._ordering_mode = _validate_ordering_mode (ordering_mode )
@@ -379,3 +384,43 @@ def client_endpoints_override(self, value: dict):
379384 )
380385
381386 self ._client_endpoints_override = value
387+
388+ @property
389+ def requests_transport_adapters (
390+ self ,
391+ ) -> Sequence [Tuple [str , requests .adapters .BaseAdapter ]]:
392+ """Transport adapters for requests-based REST clients such as the
393+ google-cloud-bigquery package.
394+
395+ For more details, see the explanation in `requests guide to transport
396+ adapters
397+ <https://requests.readthedocs.io/en/latest/user/advanced/#transport-adapters>`_.
398+
399+ **Examples:**
400+
401+ Increase the connection pool size using the requests `HTTPAdapter
402+ <https://requests.readthedocs.io/en/latest/api/#requests.adapters.HTTPAdapter>`_.
403+
404+ >>> import bigframes.pandas as bpd
405+ >>> bpd.options.bigquery.requests_transport_adapters = (
406+ ... ("http://", requests.adapters.HTTPAdapter(pool_maxsize=100)),
407+ ... ("https://", requests.adapters.HTTPAdapter(pool_maxsize=100)),
408+ ... ) # doctest: +SKIP
409+
410+ Returns:
411+ Sequence[Tuple[str, requests.adapters.BaseAdapter]]:
412+ Prefixes and corresponding transport adapters to `mount
413+ <https://requests.readthedocs.io/en/latest/api/#requests.Session.mount>`_
414+ in requests-based REST clients.
415+ """
416+ return self ._requests_transport_adapters
417+
418+ @requests_transport_adapters .setter
419+ def requests_transport_adapters (
420+ self , value : Sequence [Tuple [str , requests .adapters .BaseAdapter ]]
421+ ) -> None :
422+ if self ._session_started and self ._requests_transport_adapters != value :
423+ raise ValueError (
424+ SESSION_STARTED_MESSAGE .format (attribute = "requests_transport_adapters" )
425+ )
426+ self ._requests_transport_adapters = value
0 commit comments