teradataml 20.0.0.5__py3-none-any.whl → 20.0.0.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of teradataml might be problematic. Click here for more details.

Files changed (119) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/README.md +306 -0
  3. teradataml/__init__.py +1 -1
  4. teradataml/_version.py +1 -1
  5. teradataml/analytics/analytic_function_executor.py +162 -76
  6. teradataml/analytics/byom/__init__.py +1 -1
  7. teradataml/analytics/json_parser/__init__.py +2 -0
  8. teradataml/analytics/json_parser/analytic_functions_argument.py +95 -2
  9. teradataml/analytics/json_parser/metadata.py +22 -4
  10. teradataml/analytics/sqle/DecisionTreePredict.py +3 -2
  11. teradataml/analytics/sqle/NaiveBayesPredict.py +3 -2
  12. teradataml/analytics/sqle/__init__.py +3 -0
  13. teradataml/analytics/utils.py +59 -11
  14. teradataml/automl/__init__.py +2369 -464
  15. teradataml/automl/autodataprep/__init__.py +15 -0
  16. teradataml/automl/custom_json_utils.py +184 -112
  17. teradataml/automl/data_preparation.py +113 -58
  18. teradataml/automl/data_transformation.py +154 -53
  19. teradataml/automl/feature_engineering.py +113 -53
  20. teradataml/automl/feature_exploration.py +548 -25
  21. teradataml/automl/model_evaluation.py +260 -32
  22. teradataml/automl/model_training.py +399 -206
  23. teradataml/clients/auth_client.py +10 -6
  24. teradataml/clients/keycloak_client.py +165 -0
  25. teradataml/common/aed_utils.py +11 -2
  26. teradataml/common/bulk_exposed_utils.py +4 -2
  27. teradataml/common/constants.py +72 -2
  28. teradataml/common/exceptions.py +32 -0
  29. teradataml/common/garbagecollector.py +50 -21
  30. teradataml/common/messagecodes.py +73 -1
  31. teradataml/common/messages.py +27 -1
  32. teradataml/common/sqlbundle.py +25 -7
  33. teradataml/common/utils.py +210 -22
  34. teradataml/context/aed_context.py +16 -10
  35. teradataml/context/context.py +37 -9
  36. teradataml/data/Employee.csv +5 -0
  37. teradataml/data/Employee_Address.csv +4 -0
  38. teradataml/data/Employee_roles.csv +5 -0
  39. teradataml/data/JulesBelvezeDummyData.csv +100 -0
  40. teradataml/data/byom_example.json +5 -0
  41. teradataml/data/creditcard_data.csv +284618 -0
  42. teradataml/data/docs/byom/docs/ONNXSeq2Seq.py +255 -0
  43. teradataml/data/docs/sqle/docs_17_10/NGramSplitter.py +1 -1
  44. teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +1 -1
  45. teradataml/data/docs/sqle/docs_17_20/TextParser.py +1 -1
  46. teradataml/data/jsons/byom/ONNXSeq2Seq.json +287 -0
  47. teradataml/data/jsons/byom/onnxembeddings.json +1 -0
  48. teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +3 -7
  49. teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +3 -7
  50. teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +3 -7
  51. teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +3 -7
  52. teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +3 -7
  53. teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +3 -7
  54. teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +3 -7
  55. teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +3 -7
  56. teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +3 -7
  57. teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +3 -7
  58. teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +3 -7
  59. teradataml/data/jsons/sqle/20.00/TD_API_AzureML.json +151 -0
  60. teradataml/data/jsons/sqle/20.00/TD_API_Sagemaker.json +182 -0
  61. teradataml/data/jsons/sqle/20.00/TD_API_VertexAI.json +183 -0
  62. teradataml/data/load_example_data.py +29 -11
  63. teradataml/data/pattern_matching_data.csv +11 -0
  64. teradataml/data/payment_fraud_dataset.csv +10001 -0
  65. teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
  66. teradataml/data/teradataml_example.json +75 -1
  67. teradataml/data/url_data.csv +10 -9
  68. teradataml/dataframe/copy_to.py +715 -55
  69. teradataml/dataframe/dataframe.py +2115 -97
  70. teradataml/dataframe/dataframe_utils.py +66 -28
  71. teradataml/dataframe/functions.py +1130 -2
  72. teradataml/dataframe/setop.py +4 -1
  73. teradataml/dataframe/sql.py +710 -1039
  74. teradataml/dbutils/dbutils.py +470 -35
  75. teradataml/dbutils/filemgr.py +1 -1
  76. teradataml/hyperparameter_tuner/optimizer.py +456 -142
  77. teradataml/hyperparameter_tuner/utils.py +4 -2
  78. teradataml/lib/aed_0_1.dll +0 -0
  79. teradataml/lib/libaed_0_1.dylib +0 -0
  80. teradataml/lib/libaed_0_1.so +0 -0
  81. teradataml/lib/libaed_0_1_aarch64.so +0 -0
  82. teradataml/opensource/_base.py +7 -1
  83. teradataml/options/configure.py +20 -4
  84. teradataml/scriptmgmt/UserEnv.py +247 -36
  85. teradataml/scriptmgmt/lls_utils.py +140 -39
  86. teradataml/sdk/README.md +79 -0
  87. teradataml/sdk/__init__.py +4 -0
  88. teradataml/sdk/_auth_modes.py +422 -0
  89. teradataml/sdk/_func_params.py +487 -0
  90. teradataml/sdk/_json_parser.py +453 -0
  91. teradataml/sdk/_openapi_spec_constants.py +249 -0
  92. teradataml/sdk/_utils.py +236 -0
  93. teradataml/sdk/api_client.py +900 -0
  94. teradataml/sdk/constants.py +62 -0
  95. teradataml/sdk/modelops/__init__.py +98 -0
  96. teradataml/sdk/modelops/_client.py +409 -0
  97. teradataml/sdk/modelops/_constants.py +304 -0
  98. teradataml/sdk/modelops/models.py +2308 -0
  99. teradataml/sdk/spinner.py +107 -0
  100. teradataml/series/series.py +12 -7
  101. teradataml/store/feature_store/constants.py +601 -234
  102. teradataml/store/feature_store/feature_store.py +2886 -616
  103. teradataml/store/feature_store/mind_map.py +639 -0
  104. teradataml/store/feature_store/models.py +5831 -214
  105. teradataml/store/feature_store/utils.py +390 -0
  106. teradataml/table_operators/query_generator.py +4 -21
  107. teradataml/table_operators/table_operator_util.py +1 -1
  108. teradataml/table_operators/templates/dataframe_register.template +6 -2
  109. teradataml/table_operators/templates/dataframe_udf.template +6 -2
  110. teradataml/utils/docstring.py +527 -0
  111. teradataml/utils/dtypes.py +95 -1
  112. teradataml/utils/internal_buffer.py +2 -2
  113. teradataml/utils/utils.py +41 -3
  114. teradataml/utils/validators.py +699 -18
  115. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/METADATA +312 -2
  116. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/RECORD +119 -87
  117. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/WHEEL +0 -0
  118. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/top_level.txt +0 -0
  119. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/zip-safe +0 -0
@@ -0,0 +1,422 @@
1
+ # ################################################################################################
2
+ #
3
+ # Copyright 2025 Teradata. All rights reserved.
4
+ # TERADATA CONFIDENTIAL AND TRADE SECRET
5
+ #
6
+ # Primary Owner: Adithya Avvaru (adithya.avvaru@teradata.com)
7
+ # Secondary Owner: Pankaj Purandare (pankajvinod.purandare@teradata.com)
8
+ #
9
+ # Version: 1.0
10
+ # SDK Version: 1.0
11
+ #
12
+ # This file contains different authentication modes and corresponding classes for the OpenAPI SDK.
13
+ #
14
+ # ################################################################################################
15
+
16
+ import json
17
+ import logging
18
+ import os
19
+ import re
20
+ import time
21
+ from abc import ABC, abstractmethod
22
+ from enum import Enum
23
+
24
+ import requests
25
+ from oauthlib.oauth2 import BackendApplicationClient
26
+ from requests.auth import HTTPBasicAuth
27
+ from requests_oauthlib import OAuth2Session
28
+
29
+ from teradataml.common.exceptions import TeradataMlException
30
+ from teradataml.common.messages import MessageCodes, Messages
31
+ from teradataml.utils.validators import _Validators
32
+
33
+ from .spinner import spin_it
34
+
35
+ logger = logging.getLogger(__name__)
36
+
37
+
38
+ class AuthMode(Enum):
39
+ DEVICE_CODE = "device_code"
40
+ CLIENT_CREDENTIALS = "client_credentials"
41
+ BEARER = "bearer"
42
+
43
+
44
+ class _BaseAuth(ABC):
45
+ AUTH_MODE = None
46
+
47
+ def __init__(self):
48
+
49
+ self.session = None
50
+ self._ssl_verify = None
51
+ self._base_url = None
52
+
53
+ @abstractmethod
54
+ def authenticate(self, **kwargs):
55
+ raise NotImplementedError("Subclasses must implement authenticate method")
56
+
57
+ def _set_session_tls(self):
58
+ self.session.verify = self._ssl_verify
59
+ if not self._ssl_verify:
60
+ import urllib3
61
+ from urllib3.exceptions import InsecureRequestWarning
62
+
63
+ logger.warning(
64
+ "Certificate validation disabled. Adding certificate verification is"
65
+ " strongly advised"
66
+ )
67
+ urllib3.disable_warnings(InsecureRequestWarning)
68
+
69
+
70
+ class ClientCredentialsAuth(_BaseAuth):
71
+ """
72
+ Class to handle authentication using client credentials.
73
+ """
74
+ AUTH_MODE = AuthMode.CLIENT_CREDENTIALS
75
+
76
+ def __init__(self, auth_token_url, auth_client_id, auth_client_secret):
77
+ """
78
+ DESCRIPTION:
79
+ Initializes the object to authenticate through client credentials authentication.
80
+
81
+ PARAMETERS:
82
+ auth_token_url:
83
+ Required Argument.
84
+ Specifies the token endpoint URL to fetch the access token.
85
+ Types: str
86
+
87
+ auth_client_id:
88
+ Required Argument.
89
+ Specifies the client ID for authentication.
90
+ Types: str
91
+
92
+ auth_client_secret:
93
+ Required Argument.
94
+ Specifies the client secret for authentication.
95
+ Types: str
96
+
97
+ RETURNS:
98
+ None
99
+
100
+ RAISES:
101
+ None
102
+
103
+ EXAMPLES:
104
+ >>> from teradataml.sdk import ClientCredentialsAuth
105
+ >>> auth = ClientCredentialsAuth(
106
+ auth_token_url="https://example.com/token",
107
+ auth_client_id="your_client_id",
108
+ auth_client_secret="your_client_secret"
109
+ )
110
+ """
111
+ arg_info_matrix = []
112
+ arg_info_matrix.append(["auth_token_url", auth_token_url, False, (str,), True])
113
+ arg_info_matrix.append(["auth_client_id", auth_client_id, False, (str,), True])
114
+ arg_info_matrix.append(["auth_client_secret", auth_client_secret, False, (str,), True])
115
+ _Validators._validate_missing_required_arguments(arg_info_matrix)
116
+ _Validators._validate_function_arguments(arg_info_matrix)
117
+
118
+ self._auth_client_id = auth_client_id
119
+ self._auth_client_secret = auth_client_secret
120
+ self._auth_token_url = auth_token_url
121
+
122
+ def authenticate(self):
123
+ """
124
+ DESCRIPTION:
125
+ Authenticates using client credentials and fetches the access token.
126
+
127
+ PARAMETERS:
128
+ None
129
+
130
+ RETURNS:
131
+ requests.Session: Authenticated session with the access token.
132
+
133
+ RAISES:
134
+ None
135
+
136
+ EXAMPLES:
137
+ >>> from teradataml.sdk import ClientCredentialsAuth
138
+ >>> auth = ClientCredentialsAuth(
139
+ auth_token_url="https://example.com/token",
140
+ auth_client_id="your_client_id",
141
+ auth_client_secret="your_client_secret"
142
+ )
143
+ >>> session = auth.authenticate()
144
+ """
145
+ self.session = OAuth2Session(client=BackendApplicationClient(client_id=self._auth_client_id))
146
+
147
+ self._set_session_tls()
148
+ self.session.fetch_token(
149
+ token_url=self._auth_token_url,
150
+ auth=HTTPBasicAuth(self._auth_client_id, self._auth_client_secret),
151
+ verify=self._ssl_verify,
152
+ )
153
+
154
+ return self.session
155
+
156
+
157
+ class DeviceCodeAuth(_BaseAuth):
158
+ """
159
+ Class to handle authentication using device code.
160
+ """
161
+ AUTH_MODE = AuthMode.DEVICE_CODE
162
+
163
+ def __init__(self, auth_token_url, auth_device_auth_url, auth_client_id, auth_client_secret=None):
164
+ """
165
+ DESCRIPTION:
166
+ Initializes the object to authenticate through device code authentication.
167
+
168
+ PARAMETERS:
169
+ auth_token_url:
170
+ Required Argument.
171
+ Specifies the token endpoint URL to fetch the access token.
172
+ Types: str
173
+
174
+ auth_device_auth_url:
175
+ Required Argument.
176
+ Specifies the device code endpoint URL to initiate device code flow.
177
+ Types: str
178
+
179
+ auth_client_id:
180
+ Required Argument.
181
+ Specifies the client ID for authentication.
182
+ Types: str
183
+
184
+ auth_client_secret:
185
+ Optional Argument.
186
+ Specifies the client secret for authentication.
187
+ Types: str or None
188
+
189
+ RETURNS:
190
+ None
191
+
192
+ RAISES:
193
+ None
194
+
195
+ EXAMPLES:
196
+ >>> from teradataml.sdk import DeviceCodeAuth
197
+ >>> auth = DeviceCodeAuth(
198
+ auth_token_url="https://example.com/token",
199
+ auth_device_auth_url="https://example.com/device_auth",
200
+ auth_client_id="your_client_id",
201
+ auth_client_secret="your_client_secret"
202
+ )
203
+ """
204
+ arg_info_matrix = []
205
+ arg_info_matrix.append(["auth_token_url", auth_token_url, False, (str,), True])
206
+ arg_info_matrix.append(["auth_device_auth_url", auth_device_auth_url, False, (str,), True])
207
+ arg_info_matrix.append(["auth_client_id", auth_client_id, False, (str,), True])
208
+ arg_info_matrix.append(["auth_client_secret", auth_client_secret, True, (str,), True])
209
+ _Validators._validate_missing_required_arguments(arg_info_matrix)
210
+ _Validators._validate_function_arguments(arg_info_matrix)
211
+
212
+ self._auth_client_id = auth_client_id
213
+ self._auth_client_secret = auth_client_secret
214
+ self._auth_token_url = auth_token_url
215
+ self._auth_device_auth_url = auth_device_auth_url
216
+
217
+ def authenticate(self, token_cache_file_path=None):
218
+ """
219
+ DESCRIPTION:
220
+ Authenticates using device code flow and fetches the access token.
221
+
222
+ PARAMETERS:
223
+ token_cache_file_path:
224
+ Optional Argument.
225
+ Specifies the file path to load and/or cache the token data.
226
+ Types: str
227
+
228
+ RETURNS:
229
+ requests.Session: Authenticated session with the access token.
230
+
231
+ RAISES:
232
+ None
233
+
234
+ EXAMPLES:
235
+ >>> from teradataml.sdk import DeviceCodeAuth
236
+ >>> auth = DeviceCodeAuth(
237
+ auth_token_url="https://example.com/token",
238
+ auth_device_auth_url="https://example.com/device_auth",
239
+ auth_client_id="your_client_id",
240
+ auth_client_secret="your_client_secret"
241
+ )
242
+ >>> session = auth.authenticate(token_cache_file_path="/path/to/token_cache.json")
243
+ """
244
+ arg_info_matrix = []
245
+ arg_info_matrix.append(["token_cache_file_path", token_cache_file_path, True, (str,), True])
246
+ _Validators._validate_missing_required_arguments(arg_info_matrix)
247
+ _Validators._validate_function_arguments(arg_info_matrix)
248
+
249
+ token = None
250
+ if token_cache_file_path and os.path.exists(token_cache_file_path):
251
+ logger.debug(
252
+ f"Loading cached token data from {token_cache_file_path}"
253
+ )
254
+ with open(token_cache_file_path, "r") as f:
255
+ token = json.load(f)
256
+
257
+ if not token:
258
+ self.session = requests.session()
259
+ self._set_session_tls()
260
+ token = self._get_device_code()
261
+
262
+ if "access_token" in token:
263
+ logger.debug(f"Access token acquired successfully: {token}")
264
+
265
+ self.__prepare_session_for_token()
266
+
267
+ # Create session.
268
+ _bearer = BearerAuth(auth_bearer=token["access_token"])
269
+ _bearer._ssl_verify = self._ssl_verify
270
+ _bearer._base_url = self._base_url
271
+ self.session = _bearer.authenticate()
272
+
273
+ elif "refresh_token" in token:
274
+ logger.debug(f"Refresh token acquired successfully: {token}")
275
+
276
+ self.__prepare_session_for_token()
277
+
278
+ # Refresh token for the session.
279
+ self.session.refresh_token(
280
+ token_url=self._auth_token_url,
281
+ refresh_token=token["refresh_token"],
282
+ auth=HTTPBasicAuth(self._auth_client_id, self._auth_client_secret),
283
+ verify=self._ssl_verify,
284
+ )
285
+
286
+ else:
287
+ raise TeradataMlException(Messages.get_message(MessageCodes.REST_DEVICE_CODE_NO_BOTH, token),
288
+ MessageCodes.REST_DEVICE_CODE_NO_BOTH)
289
+
290
+ with open(token_cache_file_path, "w") as f:
291
+ json.dump(token, f)
292
+
293
+ return self.session
294
+
295
+ def __prepare_session_for_token(self):
296
+ session = OAuth2Session(client_id=self._auth_client_id)
297
+
298
+ # don't chase certs/print warning for TLS if already done for _get_device_code
299
+ if hasattr(self, "session"):
300
+ session.verify = self.session.verify
301
+ self.session = session
302
+ else:
303
+ self.session = session
304
+ self._set_session_tls()
305
+
306
+ def _get_device_code(self):
307
+ device_code_response = self.session.post(
308
+ self._auth_device_auth_url,
309
+ data={"client_id": self._auth_client_id, "scope": "openid profile"},
310
+ )
311
+
312
+ if device_code_response.status_code != 200:
313
+ raise TeradataMlException(Messages.get_message(MessageCodes.REST_DEVICE_CODE_GEN_FAILED,
314
+ device_code_response.status_code),
315
+ MessageCodes.REST_DEVICE_CODE_GEN_FAILED)
316
+
317
+ device_code_data = device_code_response.json()
318
+ print(
319
+ "1. On your computer or mobile device navigate to: ",
320
+ device_code_data["verification_uri_complete"],
321
+ )
322
+ print("2. Enter the following code: ", device_code_data["user_code"])
323
+
324
+ def authorize():
325
+ authenticated = False
326
+ token_data = None
327
+
328
+ while not authenticated:
329
+ token_response = self.session.post(
330
+ self._auth_token_url,
331
+ data={
332
+ "grant_type": "urn:ietf:params:oauth:grant-type:device_code",
333
+ "device_code": device_code_data["device_code"],
334
+ "client_id": self._auth_client_id,
335
+ },
336
+ )
337
+
338
+ token_data = token_response.json()
339
+ if token_response.status_code == 200:
340
+ authenticated = True
341
+
342
+ elif "error" in token_data:
343
+ if token_data["error"] in ("authorization_pending", "slow_down"):
344
+ time.sleep(device_code_data["interval"])
345
+ else:
346
+ raise TeradataMlException(Messages.get_message(MessageCodes.REST_DEVICE_CODE_AUTH_FAILED,
347
+ token_data["error_description"]),
348
+ MessageCodes.REST_DEVICE_CODE_AUTH_FAILED)
349
+
350
+ else:
351
+ raise TeradataMlException(Messages.get_message(MessageCodes.REST_DEVICE_CODE_AUTH_FAILED,
352
+ f"Bad response code: {token_response.status_code}"),
353
+ MessageCodes.REST_DEVICE_CODE_AUTH_FAILED)
354
+
355
+ return token_data
356
+
357
+ msg = "Waiting for device code to be authorized\n"
358
+ res = spin_it(authorize, msg, 3)
359
+ print(
360
+ "\033[32m\U0001f512 This device has been authorized successfully.\033[0m\n"
361
+ )
362
+ return res
363
+
364
+
365
+ class BearerAuth(_BaseAuth):
366
+ """
367
+ Class to handle authentication using bearer token.
368
+ """
369
+ AUTH_MODE = AuthMode.BEARER
370
+
371
+ def __init__(self, auth_bearer):
372
+ """
373
+ DESCRIPTION:
374
+ Initializes the object to authenticate through bearer token authentication.
375
+
376
+ PARAMETERS:
377
+ auth_bearer:
378
+ Required Argument.
379
+ Specifies the raw bearer token to be used for authentication.
380
+ Types: str
381
+
382
+ RETURNS:
383
+ None
384
+
385
+ RAISES:
386
+ None
387
+
388
+ EXAMPLES:
389
+ >>> from teradataml.sdk import BearerAuth
390
+ >>> auth = BearerAuth(auth_bearer="your_bearer_token")
391
+ """
392
+ arg_info_matrix = [["auth_bearer", auth_bearer, False, (str,), True]]
393
+ _Validators._validate_missing_required_arguments(arg_info_matrix)
394
+ _Validators._validate_function_arguments(arg_info_matrix)
395
+
396
+ self._auth_bearer = f"Bearer {auth_bearer}"
397
+
398
+ def authenticate(self):
399
+ """
400
+ DESCRIPTION:
401
+ Authenticates using the provided bearer token.
402
+
403
+ PARAMETERS:
404
+ None
405
+
406
+ RETURNS:
407
+ requests.Session: Authenticated session with the bearer token.
408
+
409
+ RAISES:
410
+ None
411
+
412
+ EXAMPLES:
413
+ >>> from teradataml.sdk import BearerAuth
414
+ >>> auth = BearerAuth(auth_bearer="your_bearer_token")
415
+ >>> session = auth.authenticate()
416
+ """
417
+ self.session = requests.session()
418
+ self.session.headers.update({"Authorization": self._auth_bearer})
419
+
420
+ self._set_session_tls()
421
+
422
+ return self.session