@@ -46,6 +46,7 @@ def __init__(
4646 logger .warning (
4747 "SSL verification is disabled. This is not recommended unless you absolutely need this config."
4848 )
49+ self ._session = requests .Session ()
4950
5051 def _clear_env_var_cache (self , job_definition_id : Optional [int ]) -> None :
5152 """Clear out any cached environment variables for a given job."""
@@ -79,7 +80,7 @@ def update_job(self, job: JobDefinition) -> JobDefinition:
7980
8081 logger .debug ("Updating {job_name}. {job}" , job_name = job .name , job = job )
8182
82- response = requests .post ( # Yes, it's actually a POST. Ew.
83+ response = self . _session .post ( # Yes, it's actually a POST. Ew.
8384 url = f"{ self .base_url } /api/v2/accounts/{ self .account_id } /jobs/{ job .id } /" ,
8485 headers = self ._headers ,
8586 data = job .to_payload (),
@@ -98,7 +99,7 @@ def create_job(self, job: JobDefinition) -> Optional[JobDefinition]:
9899
99100 logger .debug ("Creating {job_name}. {job}" , job_name = job .name , job = job )
100101
101- response = requests .post (
102+ response = self . _session .post (
102103 url = f"{ self .base_url } /api/v2/accounts/{ self .account_id } /jobs/" ,
103104 headers = self ._headers ,
104105 data = job .to_payload (),
@@ -118,7 +119,7 @@ def delete_job(self, job: JobDefinition) -> None:
118119
119120 logger .debug ("Deleting {job_name}. {job}" , job_name = job .name , job = job )
120121
121- response = requests .delete (
122+ response = self . _session .delete (
122123 url = f"{ self .base_url } /api/v2/accounts/{ self .account_id } /jobs/{ job .id } /" ,
123124 headers = self ._headers ,
124125 verify = self ._verify ,
@@ -134,7 +135,7 @@ def get_job(self, job_id: int) -> Optional[JobDefinition]:
134135
135136 self ._check_for_creds ()
136137
137- response = requests .get (
138+ response = self . _session .get (
138139 url = (f"{ self .base_url } /api/v2/accounts/" f"{ self .account_id } /jobs/{ job_id } /" ),
139140 headers = self ._headers ,
140141 verify = self ._verify ,
@@ -149,7 +150,7 @@ def get_job_missing_fields(self, job_id: int) -> Optional[JobMissingFields]:
149150
150151 self ._check_for_creds ()
151152
152- response = requests .get (
153+ response = self . _session .get (
153154 url = (f"{ self .base_url } /api/v2/accounts/" f"{ self .account_id } /jobs/{ job_id } /" ),
154155 headers = self ._headers ,
155156 verify = self ._verify ,
@@ -222,7 +223,7 @@ def _build_parameters(
222223 return parameters
223224
224225 def _make_request (self , parameters : dict [str , Any ]):
225- response = requests .get (
226+ response = self . _session .get (
226227 url = f"{ self .base_url } /api/v2/accounts/{ self .account_id } /jobs/" ,
227228 params = parameters ,
228229 headers = self ._headers ,
@@ -246,7 +247,7 @@ def get_env_vars(
246247
247248 self ._check_for_creds ()
248249
249- response = requests .get (
250+ response = self . _session .get (
250251 url = (
251252 f"{ self .base_url } /api/v3/accounts/{ self .account_id } /projects/{ project_id } /environment-variables/job/?job_definition_id={ job_id } "
252253 ),
@@ -274,7 +275,7 @@ def create_env_var(
274275 ) -> CustomEnvironmentVariablePayload :
275276 """Create a new Custom Environment Variable in dbt Cloud."""
276277
277- response = requests .post (
278+ response = self . _session .post (
278279 f"{ self .base_url } /api/v3/accounts/{ self .account_id } /projects/{ env_var .project_id } /environment-variables/" ,
279280 headers = self ._headers ,
280281 data = env_var .model_dump_json (),
@@ -322,7 +323,7 @@ def update_env_var(
322323 ** custom_env_var .model_dump (),
323324 )
324325
325- response = requests .post (
326+ response = self . _session .post (
326327 url = url , headers = self ._headers , data = payload .model_dump_json (), verify = self ._verify
327328 )
328329
@@ -339,7 +340,7 @@ def delete_env_var(self, project_id: int, env_var_id: int) -> None:
339340
340341 logger .debug (f"Deleting env var id { env_var_id } " )
341342
342- response = requests .delete (
343+ response = self . _session .delete (
343344 url = f"{ self .base_url } /api/v3/accounts/{ self .account_id } /projects/{ project_id } /environment-variables/{ env_var_id } /" ,
344345 headers = self ._headers ,
345346 verify = self ._verify ,
@@ -351,7 +352,7 @@ def delete_env_var(self, project_id: int, env_var_id: int) -> None:
351352 logger .success ("Env Var Job Overwrite deleted successfully." )
352353
353354 def _fetch_environment (self , url ) -> List [dict ]:
354- response = requests .get (
355+ response = self . _session .get (
355356 url = url ,
356357 headers = self ._headers ,
357358 verify = self ._verify ,
0 commit comments