@@ -49,6 +49,7 @@ def __init__(
4949 raise ValueError (f"Invalid environment: { env } " )
5050
5151 self ._retry_strategy = retry_strategy
52+ self ._client = httpx
5253 self ._blob_client = BlobClient (retry_strategy )
5354
5455 access_token = None
@@ -92,6 +93,14 @@ def __init__(
9293 pass
9394 return
9495
96+ def __enter__ (self ):
97+ self ._client = httpx .Client ()
98+ return self
99+
100+ def __exit__ (self , exc_type , exc_value , traceback ):
101+ self ._client .close ()
102+ return
103+
95104 def authenticate (self ):
96105 if self .auth is None :
97106 return None
@@ -155,7 +164,7 @@ def get(self, path: str, params: dict = None) -> dict:
155164 headers .update (self .auth .get_authorization ())
156165
157166 def _get ():
158- return httpx .get (
167+ return self . _client .get (
159168 f"{ self .base_url } { path } " ,
160169 params = params ,
161170 headers = headers ,
@@ -229,7 +238,7 @@ def post(
229238 headers .update (self .auth .get_authorization ())
230239
231240 def _post ():
232- return httpx .post (
241+ return self . _client .post (
233242 f"{ self .base_url } { path } " ,
234243 content = blob ,
235244 json = json ,
@@ -276,7 +285,7 @@ def put(
276285 headers .update (self .auth .get_authorization ())
277286
278287 def _put ():
279- return httpx .put (
288+ return self . _client .put (
280289 f"{ self .base_url } { path } " ,
281290 content = blob ,
282291 json = json ,
@@ -315,7 +324,7 @@ def delete(self, path: str, params: dict = None) -> dict:
315324 headers .update (self .auth .get_authorization ())
316325
317326 def _delete ():
318- return httpx .delete (
327+ return self . _client .delete (
319328 f"{ self .base_url } { path } " ,
320329 headers = headers ,
321330 params = params ,
0 commit comments