From 2e65ec630852f2f24c82536eefae7d179908a1f8 Mon Sep 17 00:00:00 2001 From: Bhagavath Vasudeva Prasad Achani Date: Wed, 19 Jun 2024 12:31:20 +0200 Subject: [PATCH] enable with syntax and use dedicated httpx.Client instance --- src/sumo/wrapper/sumo_client.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sumo/wrapper/sumo_client.py b/src/sumo/wrapper/sumo_client.py index 7c788db..af8fa29 100644 --- a/src/sumo/wrapper/sumo_client.py +++ b/src/sumo/wrapper/sumo_client.py @@ -49,6 +49,7 @@ def __init__( raise ValueError(f"Invalid environment: {env}") self._retry_strategy = retry_strategy + self._client = httpx self._blob_client = BlobClient(retry_strategy) access_token = None @@ -92,6 +93,14 @@ def __init__( pass return + def __enter__(self): + self._client = httpx.Client() + return self + + def __exit__(self, exc_type, exc_value, traceback): + self._client.close() + return + def authenticate(self): if self.auth is None: return None @@ -155,7 +164,7 @@ def get(self, path: str, params: dict = None) -> dict: headers.update(self.auth.get_authorization()) def _get(): - return httpx.get( + return self._client.get( f"{self.base_url}{path}", params=params, headers=headers, @@ -229,7 +238,7 @@ def post( headers.update(self.auth.get_authorization()) def _post(): - return httpx.post( + return self._client.post( f"{self.base_url}{path}", content=blob, json=json, @@ -276,7 +285,7 @@ def put( headers.update(self.auth.get_authorization()) def _put(): - return httpx.put( + return self._client.put( f"{self.base_url}{path}", content=blob, json=json, @@ -315,7 +324,7 @@ def delete(self, path: str, params: dict = None) -> dict: headers.update(self.auth.get_authorization()) def _delete(): - return httpx.delete( + return self._client.delete( f"{self.base_url}{path}", headers=headers, params=params,