99import requests
1010from requests .adapters import HTTPAdapter
1111from requests .packages .urllib3 .util .retry import Retry
12+ from requests import Session
1213
1314from .exceptions import PrometheusApiClientException
1415
@@ -36,8 +37,9 @@ class PrometheusConnect:
3637 :param retry: (Retry) Retry adapter to retry on HTTP errors
3738 :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. See python
3839 requests library auth parameter for further explanation.
39- :param proxy: (Optional) Proxies dictonary to enable connection through proxy.
40- Example: {"http_proxy": "<ip_address/hostname:port>", "https_proxy": "<ip_address/hostname:port>"}
40+ :param proxy: (Optional) Proxies dictionary to enable connection through proxy.
41+ Example: {"http_proxy": "<ip_address/hostname:port>", "https_proxy": "<ip_address/hostname:port>"}
42+ :param session (Optional) Custom requests.Session to enable complex HTTP configuration
4143 """
4244
4345 def __init__ (
@@ -47,7 +49,8 @@ def __init__(
4749 disable_ssl : bool = False ,
4850 retry : Retry = None ,
4951 auth : tuple = None ,
50- proxy : dict = None
52+ proxy : dict = None ,
53+ session : Session = None ,
5154 ):
5255 """Functions as a Constructor for the class PrometheusConnect."""
5356 if url is None :
@@ -68,7 +71,8 @@ def __init__(
6871
6972 self .auth = auth
7073
71- self ._session = requests .Session ()
74+ self ._session = session if session is not None else requests .Session ()
75+
7276 if proxy is not None :
7377 self ._session .proxies = proxy
7478 self ._session .mount (self .url , HTTPAdapter (max_retries = retry ))
0 commit comments