truefoundry 0.3.4rc1__py3-none-any.whl → 0.4.0__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 truefoundry might be problematic. Click here for more details.

Files changed (253) hide show
  1. truefoundry/__init__.py +2 -0
  2. truefoundry/autodeploy/agents/developer.py +1 -1
  3. truefoundry/autodeploy/agents/project_identifier.py +2 -2
  4. truefoundry/autodeploy/agents/tester.py +1 -1
  5. truefoundry/autodeploy/cli.py +1 -1
  6. truefoundry/autodeploy/tools/list_files.py +1 -1
  7. truefoundry/cli/__main__.py +3 -17
  8. truefoundry/common/__init__.py +0 -0
  9. truefoundry/{deploy/lib/auth → common}/auth_service_client.py +50 -40
  10. truefoundry/common/constants.py +12 -0
  11. truefoundry/{deploy/lib/auth → common}/credential_file_manager.py +7 -7
  12. truefoundry/{deploy/lib/auth → common}/credential_provider.py +10 -23
  13. truefoundry/common/entities.py +124 -0
  14. truefoundry/common/exceptions.py +12 -0
  15. truefoundry/common/request_utils.py +84 -0
  16. truefoundry/common/servicefoundry_client.py +91 -0
  17. truefoundry/common/utils.py +56 -0
  18. truefoundry/deploy/auto_gen/models.py +4 -6
  19. truefoundry/deploy/cli/cli.py +3 -1
  20. truefoundry/deploy/cli/commands/apply_command.py +1 -1
  21. truefoundry/deploy/cli/commands/build_command.py +1 -1
  22. truefoundry/deploy/cli/commands/deploy_command.py +1 -1
  23. truefoundry/deploy/cli/commands/login_command.py +2 -2
  24. truefoundry/deploy/cli/commands/patch_application_command.py +1 -1
  25. truefoundry/deploy/cli/commands/patch_command.py +1 -1
  26. truefoundry/deploy/cli/commands/terminate_comand.py +1 -1
  27. truefoundry/deploy/cli/util.py +1 -1
  28. truefoundry/deploy/function_service/remote/remote.py +1 -1
  29. truefoundry/deploy/lib/auth/servicefoundry_session.py +2 -2
  30. truefoundry/deploy/lib/clients/servicefoundry_client.py +120 -159
  31. truefoundry/deploy/lib/const.py +1 -35
  32. truefoundry/deploy/lib/exceptions.py +0 -16
  33. truefoundry/deploy/lib/model/entity.py +1 -112
  34. truefoundry/deploy/lib/session.py +14 -42
  35. truefoundry/deploy/lib/util.py +0 -37
  36. truefoundry/{python_deploy_codegen.py → deploy/python_deploy_codegen.py} +2 -2
  37. truefoundry/deploy/v2/lib/deploy.py +3 -3
  38. truefoundry/deploy/v2/lib/deployable_patched_models.py +1 -1
  39. truefoundry/langchain/truefoundry_chat.py +1 -1
  40. truefoundry/langchain/truefoundry_embeddings.py +1 -1
  41. truefoundry/langchain/truefoundry_llm.py +1 -1
  42. truefoundry/langchain/utils.py +0 -41
  43. truefoundry/ml/__init__.py +37 -6
  44. truefoundry/ml/artifact/__init__.py +0 -0
  45. truefoundry/ml/artifact/truefoundry_artifact_repo.py +1161 -0
  46. truefoundry/ml/autogen/__init__.py +0 -0
  47. truefoundry/ml/autogen/client/__init__.py +370 -0
  48. truefoundry/ml/autogen/client/api/__init__.py +16 -0
  49. truefoundry/ml/autogen/client/api/auth_api.py +184 -0
  50. truefoundry/ml/autogen/client/api/deprecated_api.py +605 -0
  51. truefoundry/ml/autogen/client/api/experiments_api.py +1944 -0
  52. truefoundry/ml/autogen/client/api/health_api.py +299 -0
  53. truefoundry/ml/autogen/client/api/metrics_api.py +371 -0
  54. truefoundry/ml/autogen/client/api/mlfoundry_artifacts_api.py +7213 -0
  55. truefoundry/ml/autogen/client/api/python_deployment_config_api.py +201 -0
  56. truefoundry/ml/autogen/client/api/run_artifacts_api.py +231 -0
  57. truefoundry/ml/autogen/client/api/runs_api.py +2919 -0
  58. truefoundry/ml/autogen/client/api_client.py +822 -0
  59. truefoundry/ml/autogen/client/api_response.py +30 -0
  60. truefoundry/ml/autogen/client/configuration.py +489 -0
  61. truefoundry/ml/autogen/client/exceptions.py +161 -0
  62. truefoundry/ml/autogen/client/models/__init__.py +341 -0
  63. truefoundry/ml/autogen/client/models/add_custom_metrics_to_model_version_request_dto.py +69 -0
  64. truefoundry/ml/autogen/client/models/add_features_to_model_version_request_dto.py +83 -0
  65. truefoundry/ml/autogen/client/models/agent.py +125 -0
  66. truefoundry/ml/autogen/client/models/agent_app.py +118 -0
  67. truefoundry/ml/autogen/client/models/agent_open_api_tool.py +143 -0
  68. truefoundry/ml/autogen/client/models/agent_open_api_tool_with_fqn.py +144 -0
  69. truefoundry/ml/autogen/client/models/agent_with_fqn.py +127 -0
  70. truefoundry/ml/autogen/client/models/artifact_dto.py +115 -0
  71. truefoundry/ml/autogen/client/models/artifact_response_dto.py +75 -0
  72. truefoundry/ml/autogen/client/models/artifact_type.py +39 -0
  73. truefoundry/ml/autogen/client/models/artifact_version_dto.py +141 -0
  74. truefoundry/ml/autogen/client/models/artifact_version_response_dto.py +77 -0
  75. truefoundry/ml/autogen/client/models/artifact_version_status.py +35 -0
  76. truefoundry/ml/autogen/client/models/assistant_message.py +89 -0
  77. truefoundry/ml/autogen/client/models/authorize_user_for_model_request_dto.py +69 -0
  78. truefoundry/ml/autogen/client/models/authorize_user_for_model_version_request_dto.py +69 -0
  79. truefoundry/ml/autogen/client/models/blob_storage_reference.py +93 -0
  80. truefoundry/ml/autogen/client/models/body_get_search_runs_get.py +72 -0
  81. truefoundry/ml/autogen/client/models/chat_prompt.py +156 -0
  82. truefoundry/ml/autogen/client/models/chat_prompt_messages_inner.py +171 -0
  83. truefoundry/ml/autogen/client/models/columns_dto.py +73 -0
  84. truefoundry/ml/autogen/client/models/content.py +153 -0
  85. truefoundry/ml/autogen/client/models/content1.py +153 -0
  86. truefoundry/ml/autogen/client/models/content2.py +174 -0
  87. truefoundry/ml/autogen/client/models/content2_any_of_inner.py +150 -0
  88. truefoundry/ml/autogen/client/models/create_artifact_request_dto.py +74 -0
  89. truefoundry/ml/autogen/client/models/create_artifact_response_dto.py +65 -0
  90. truefoundry/ml/autogen/client/models/create_artifact_version_request_dto.py +74 -0
  91. truefoundry/ml/autogen/client/models/create_artifact_version_response_dto.py +65 -0
  92. truefoundry/ml/autogen/client/models/create_dataset_request_dto.py +76 -0
  93. truefoundry/ml/autogen/client/models/create_experiment_request_dto.py +94 -0
  94. truefoundry/ml/autogen/client/models/create_experiment_response_dto.py +67 -0
  95. truefoundry/ml/autogen/client/models/create_model_version_request_dto.py +95 -0
  96. truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_request_dto.py +73 -0
  97. truefoundry/ml/autogen/client/models/create_multi_part_upload_for_dataset_response_dto.py +79 -0
  98. truefoundry/ml/autogen/client/models/create_multi_part_upload_request_dto.py +73 -0
  99. truefoundry/ml/autogen/client/models/create_python_deployment_config_request_dto.py +72 -0
  100. truefoundry/ml/autogen/client/models/create_python_deployment_config_response_dto.py +67 -0
  101. truefoundry/ml/autogen/client/models/create_run_request_dto.py +97 -0
  102. truefoundry/ml/autogen/client/models/create_run_response_dto.py +75 -0
  103. truefoundry/ml/autogen/client/models/dataset_dto.py +112 -0
  104. truefoundry/ml/autogen/client/models/dataset_response_dto.py +75 -0
  105. truefoundry/ml/autogen/client/models/delete_artifact_versions_request_dto.py +65 -0
  106. truefoundry/ml/autogen/client/models/delete_dataset_request_dto.py +74 -0
  107. truefoundry/ml/autogen/client/models/delete_model_version_request_dto.py +65 -0
  108. truefoundry/ml/autogen/client/models/delete_run_request.py +65 -0
  109. truefoundry/ml/autogen/client/models/delete_tag_request_dto.py +68 -0
  110. truefoundry/ml/autogen/client/models/experiment_dto.py +127 -0
  111. truefoundry/ml/autogen/client/models/experiment_id_request_dto.py +67 -0
  112. truefoundry/ml/autogen/client/models/experiment_response_dto.py +75 -0
  113. truefoundry/ml/autogen/client/models/experiment_tag_dto.py +69 -0
  114. truefoundry/ml/autogen/client/models/feature_dto.py +68 -0
  115. truefoundry/ml/autogen/client/models/feature_value_type.py +35 -0
  116. truefoundry/ml/autogen/client/models/file_info_dto.py +76 -0
  117. truefoundry/ml/autogen/client/models/finalize_artifact_version_request_dto.py +101 -0
  118. truefoundry/ml/autogen/client/models/get_experiment_response_dto.py +88 -0
  119. truefoundry/ml/autogen/client/models/get_latest_run_log_response_dto.py +75 -0
  120. truefoundry/ml/autogen/client/models/get_metric_history_response.py +79 -0
  121. truefoundry/ml/autogen/client/models/get_signed_url_for_dataset_write_request_dto.py +68 -0
  122. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_request_dto.py +68 -0
  123. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_read_response_dto.py +81 -0
  124. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_request_dto.py +69 -0
  125. truefoundry/ml/autogen/client/models/get_signed_urls_for_artifact_version_write_response_dto.py +83 -0
  126. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_request_dto.py +68 -0
  127. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_read_response_dto.py +81 -0
  128. truefoundry/ml/autogen/client/models/get_signed_urls_for_dataset_write_response_dto.py +81 -0
  129. truefoundry/ml/autogen/client/models/get_tenant_id_response_dto.py +73 -0
  130. truefoundry/ml/autogen/client/models/http_validation_error.py +82 -0
  131. truefoundry/ml/autogen/client/models/image_content_part.py +87 -0
  132. truefoundry/ml/autogen/client/models/image_url.py +75 -0
  133. truefoundry/ml/autogen/client/models/internal_metadata.py +180 -0
  134. truefoundry/ml/autogen/client/models/latest_run_log_dto.py +78 -0
  135. truefoundry/ml/autogen/client/models/list_artifact_versions_request_dto.py +107 -0
  136. truefoundry/ml/autogen/client/models/list_artifact_versions_response_dto.py +87 -0
  137. truefoundry/ml/autogen/client/models/list_artifacts_request_dto.py +96 -0
  138. truefoundry/ml/autogen/client/models/list_artifacts_response_dto.py +86 -0
  139. truefoundry/ml/autogen/client/models/list_colums_response_dto.py +75 -0
  140. truefoundry/ml/autogen/client/models/list_datasets_request_dto.py +78 -0
  141. truefoundry/ml/autogen/client/models/list_datasets_response_dto.py +86 -0
  142. truefoundry/ml/autogen/client/models/list_experiments_response_dto.py +86 -0
  143. truefoundry/ml/autogen/client/models/list_files_for_artifact_version_request_dto.py +76 -0
  144. truefoundry/ml/autogen/client/models/list_files_for_artifact_versions_response_dto.py +82 -0
  145. truefoundry/ml/autogen/client/models/list_files_for_dataset_request_dto.py +76 -0
  146. truefoundry/ml/autogen/client/models/list_files_for_dataset_response_dto.py +82 -0
  147. truefoundry/ml/autogen/client/models/list_latest_run_logs_response_dto.py +82 -0
  148. truefoundry/ml/autogen/client/models/list_metric_history_request_dto.py +69 -0
  149. truefoundry/ml/autogen/client/models/list_metric_history_response_dto.py +84 -0
  150. truefoundry/ml/autogen/client/models/list_model_version_response_dto.py +87 -0
  151. truefoundry/ml/autogen/client/models/list_model_versions_request_dto.py +93 -0
  152. truefoundry/ml/autogen/client/models/list_models_request_dto.py +89 -0
  153. truefoundry/ml/autogen/client/models/list_models_response_dto.py +84 -0
  154. truefoundry/ml/autogen/client/models/list_run_artifacts_response_dto.py +84 -0
  155. truefoundry/ml/autogen/client/models/list_run_logs_response_dto.py +82 -0
  156. truefoundry/ml/autogen/client/models/list_seed_experiments_response_dto.py +81 -0
  157. truefoundry/ml/autogen/client/models/log_batch_request_dto.py +106 -0
  158. truefoundry/ml/autogen/client/models/log_metric_request_dto.py +80 -0
  159. truefoundry/ml/autogen/client/models/log_param_request_dto.py +76 -0
  160. truefoundry/ml/autogen/client/models/method.py +37 -0
  161. truefoundry/ml/autogen/client/models/metric_collection_dto.py +82 -0
  162. truefoundry/ml/autogen/client/models/metric_dto.py +76 -0
  163. truefoundry/ml/autogen/client/models/mime_type.py +37 -0
  164. truefoundry/ml/autogen/client/models/model_configuration.py +103 -0
  165. truefoundry/ml/autogen/client/models/model_dto.py +122 -0
  166. truefoundry/ml/autogen/client/models/model_response_dto.py +75 -0
  167. truefoundry/ml/autogen/client/models/model_schema_dto.py +85 -0
  168. truefoundry/ml/autogen/client/models/model_version_dto.py +170 -0
  169. truefoundry/ml/autogen/client/models/model_version_response_dto.py +75 -0
  170. truefoundry/ml/autogen/client/models/multi_part_upload_dto.py +107 -0
  171. truefoundry/ml/autogen/client/models/multi_part_upload_response_dto.py +79 -0
  172. truefoundry/ml/autogen/client/models/multi_part_upload_storage_provider.py +34 -0
  173. truefoundry/ml/autogen/client/models/notify_artifact_version_failure_dto.py +65 -0
  174. truefoundry/ml/autogen/client/models/openapi_spec.py +152 -0
  175. truefoundry/ml/autogen/client/models/param_dto.py +66 -0
  176. truefoundry/ml/autogen/client/models/parameters.py +84 -0
  177. truefoundry/ml/autogen/client/models/prediction_type.py +34 -0
  178. truefoundry/ml/autogen/client/models/resolve_agent_app_response_dto.py +75 -0
  179. truefoundry/ml/autogen/client/models/restore_run_request_dto.py +65 -0
  180. truefoundry/ml/autogen/client/models/run_data_dto.py +104 -0
  181. truefoundry/ml/autogen/client/models/run_dto.py +84 -0
  182. truefoundry/ml/autogen/client/models/run_info_dto.py +105 -0
  183. truefoundry/ml/autogen/client/models/run_log_dto.py +90 -0
  184. truefoundry/ml/autogen/client/models/run_log_input_dto.py +80 -0
  185. truefoundry/ml/autogen/client/models/run_response_dto.py +75 -0
  186. truefoundry/ml/autogen/client/models/run_tag_dto.py +66 -0
  187. truefoundry/ml/autogen/client/models/search_runs_request_dto.py +94 -0
  188. truefoundry/ml/autogen/client/models/search_runs_response_dto.py +84 -0
  189. truefoundry/ml/autogen/client/models/set_experiment_tag_request_dto.py +73 -0
  190. truefoundry/ml/autogen/client/models/set_tag_request_dto.py +76 -0
  191. truefoundry/ml/autogen/client/models/signed_url_dto.py +69 -0
  192. truefoundry/ml/autogen/client/models/stop.py +152 -0
  193. truefoundry/ml/autogen/client/models/store_run_logs_request_dto.py +83 -0
  194. truefoundry/ml/autogen/client/models/system_message.py +89 -0
  195. truefoundry/ml/autogen/client/models/text.py +153 -0
  196. truefoundry/ml/autogen/client/models/text_content_part.py +84 -0
  197. truefoundry/ml/autogen/client/models/update_artifact_version_request_dto.py +74 -0
  198. truefoundry/ml/autogen/client/models/update_dataset_request_dto.py +74 -0
  199. truefoundry/ml/autogen/client/models/update_experiment_request_dto.py +74 -0
  200. truefoundry/ml/autogen/client/models/update_model_version_request_dto.py +93 -0
  201. truefoundry/ml/autogen/client/models/update_run_request_dto.py +78 -0
  202. truefoundry/ml/autogen/client/models/update_run_response_dto.py +75 -0
  203. truefoundry/ml/autogen/client/models/url.py +153 -0
  204. truefoundry/ml/autogen/client/models/user_message.py +89 -0
  205. truefoundry/ml/autogen/client/models/validation_error.py +87 -0
  206. truefoundry/ml/autogen/client/models/validation_error_loc_inner.py +154 -0
  207. truefoundry/ml/autogen/client/rest.py +426 -0
  208. truefoundry/ml/autogen/client_README.md +320 -0
  209. truefoundry/ml/cli/__init__.py +0 -0
  210. truefoundry/ml/cli/cli.py +18 -0
  211. truefoundry/ml/cli/commands/__init__.py +3 -0
  212. truefoundry/ml/cli/commands/download.py +87 -0
  213. truefoundry/ml/clients/__init__.py +0 -0
  214. truefoundry/ml/clients/entities.py +8 -0
  215. truefoundry/ml/clients/servicefoundry_client.py +45 -0
  216. truefoundry/ml/clients/utils.py +122 -0
  217. truefoundry/ml/constants.py +84 -0
  218. truefoundry/ml/entities.py +62 -0
  219. truefoundry/ml/enums.py +70 -0
  220. truefoundry/ml/env_vars.py +9 -0
  221. truefoundry/ml/exceptions.py +8 -0
  222. truefoundry/ml/git_info.py +60 -0
  223. truefoundry/ml/internal_namespace.py +52 -0
  224. truefoundry/ml/log_types/__init__.py +4 -0
  225. truefoundry/ml/log_types/artifacts/artifact.py +431 -0
  226. truefoundry/ml/log_types/artifacts/constants.py +33 -0
  227. truefoundry/ml/log_types/artifacts/dataset.py +384 -0
  228. truefoundry/ml/log_types/artifacts/general_artifact.py +110 -0
  229. truefoundry/ml/log_types/artifacts/model.py +611 -0
  230. truefoundry/ml/log_types/artifacts/model_extras.py +48 -0
  231. truefoundry/ml/log_types/artifacts/utils.py +161 -0
  232. truefoundry/ml/log_types/image/__init__.py +3 -0
  233. truefoundry/ml/log_types/image/constants.py +8 -0
  234. truefoundry/ml/log_types/image/image.py +357 -0
  235. truefoundry/ml/log_types/image/image_normalizer.py +102 -0
  236. truefoundry/ml/log_types/image/types.py +68 -0
  237. truefoundry/ml/log_types/plot.py +281 -0
  238. truefoundry/ml/log_types/pydantic_base.py +10 -0
  239. truefoundry/ml/log_types/utils.py +12 -0
  240. truefoundry/ml/logger.py +17 -0
  241. truefoundry/ml/mlfoundry_api.py +1575 -0
  242. truefoundry/ml/mlfoundry_run.py +1203 -0
  243. truefoundry/ml/run_utils.py +93 -0
  244. truefoundry/ml/session.py +168 -0
  245. truefoundry/ml/validation_utils.py +346 -0
  246. truefoundry/pydantic_v1.py +8 -1
  247. truefoundry/workflow/__init__.py +16 -1
  248. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/METADATA +21 -14
  249. truefoundry-0.4.0.dist-info/RECORD +344 -0
  250. truefoundry/deploy/lib/clients/utils.py +0 -41
  251. truefoundry-0.3.4rc1.dist-info/RECORD +0 -136
  252. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/WHEEL +0 -0
  253. {truefoundry-0.3.4rc1.dist-info → truefoundry-0.4.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,822 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+ import atexit
15
+ import datetime
16
+ import json
17
+ import mimetypes
18
+ import os
19
+ import re
20
+ import tempfile
21
+ from multiprocessing.pool import ThreadPool
22
+ from urllib.parse import quote
23
+
24
+ from dateutil.parser import parse
25
+
26
+ import truefoundry.ml.autogen.client.models
27
+ from truefoundry.ml.autogen.client import rest
28
+ from truefoundry.ml.autogen.client.api_response import ApiResponse
29
+ from truefoundry.ml.autogen.client.configuration import Configuration
30
+ from truefoundry.ml.autogen.client.exceptions import ApiException, ApiValueError
31
+
32
+
33
+ class ApiClient:
34
+ """Generic API client for OpenAPI client library builds.
35
+
36
+ OpenAPI generic API client. This client handles the client-
37
+ server communication, and is invariant across implementations. Specifics of
38
+ the methods and models for each application are generated from the OpenAPI
39
+ templates.
40
+
41
+ :param configuration: .Configuration object for this client
42
+ :param header_name: a header to pass when making calls to the API.
43
+ :param header_value: a header value to pass when making calls to
44
+ the API.
45
+ :param cookie: a cookie to include in the header when making calls
46
+ to the API
47
+ :param pool_threads: The number of threads to use for async requests
48
+ to the API. More threads means more concurrent API requests.
49
+ """
50
+
51
+ PRIMITIVE_TYPES = (float, bool, bytes, str, int)
52
+ NATIVE_TYPES_MAPPING = {
53
+ "int": int,
54
+ "long": int, # TODO remove as only py3 is supported?
55
+ "float": float,
56
+ "str": str,
57
+ "bool": bool,
58
+ "date": datetime.date,
59
+ "datetime": datetime.datetime,
60
+ "object": object,
61
+ }
62
+ _pool = None
63
+
64
+ def __init__(
65
+ self,
66
+ configuration=None,
67
+ header_name=None,
68
+ header_value=None,
69
+ cookie=None,
70
+ pool_threads=1,
71
+ ) -> None:
72
+ # use default configuration if none is provided
73
+ if configuration is None:
74
+ configuration = Configuration.get_default()
75
+ self.configuration = configuration
76
+ self.pool_threads = pool_threads
77
+
78
+ self.rest_client = rest.RESTClientObject(configuration)
79
+ self.default_headers = {}
80
+ if header_name is not None:
81
+ self.default_headers[header_name] = header_value
82
+ self.cookie = cookie
83
+ # Set default User-Agent.
84
+ self.user_agent = "OpenAPI-Generator/0.1.0/python"
85
+ self.client_side_validation = configuration.client_side_validation
86
+
87
+ def __enter__(self):
88
+ return self
89
+
90
+ def __exit__(self, exc_type, exc_value, traceback):
91
+ self.close()
92
+
93
+ def close(self):
94
+ if self._pool:
95
+ self._pool.close()
96
+ self._pool.join()
97
+ self._pool = None
98
+ if hasattr(atexit, "unregister"):
99
+ atexit.unregister(self.close)
100
+
101
+ @property
102
+ def pool(self):
103
+ """Create thread pool on first request
104
+ avoids instantiating unused threadpool for blocking clients.
105
+ """
106
+ if self._pool is None:
107
+ atexit.register(self.close)
108
+ self._pool = ThreadPool(self.pool_threads)
109
+ return self._pool
110
+
111
+ @property
112
+ def user_agent(self):
113
+ """User agent for this API client"""
114
+ return self.default_headers["User-Agent"]
115
+
116
+ @user_agent.setter
117
+ def user_agent(self, value):
118
+ self.default_headers["User-Agent"] = value
119
+
120
+ def set_default_header(self, header_name, header_value):
121
+ self.default_headers[header_name] = header_value
122
+
123
+ _default = None
124
+
125
+ @classmethod
126
+ def get_default(cls):
127
+ """Return new instance of ApiClient.
128
+
129
+ This method returns newly created, based on default constructor,
130
+ object of ApiClient class or returns a copy of default
131
+ ApiClient.
132
+
133
+ :return: The ApiClient object.
134
+ """
135
+ if cls._default is None:
136
+ cls._default = ApiClient()
137
+ return cls._default
138
+
139
+ @classmethod
140
+ def set_default(cls, default):
141
+ """Set default instance of ApiClient.
142
+
143
+ It stores default ApiClient.
144
+
145
+ :param default: object of ApiClient.
146
+ """
147
+ cls._default = default
148
+
149
+ def __call_api(
150
+ self,
151
+ resource_path,
152
+ method,
153
+ path_params=None,
154
+ query_params=None,
155
+ header_params=None,
156
+ body=None,
157
+ post_params=None,
158
+ files=None,
159
+ response_types_map=None,
160
+ auth_settings=None,
161
+ _return_http_data_only=None,
162
+ collection_formats=None,
163
+ _preload_content=True,
164
+ _request_timeout=None,
165
+ _host=None,
166
+ _request_auth=None,
167
+ ):
168
+ config = self.configuration
169
+
170
+ # header parameters
171
+ header_params = header_params or {}
172
+ header_params.update(self.default_headers)
173
+ if self.cookie:
174
+ header_params["Cookie"] = self.cookie
175
+ if header_params:
176
+ header_params = self.sanitize_for_serialization(header_params)
177
+ header_params = dict(
178
+ self.parameters_to_tuples(header_params, collection_formats)
179
+ )
180
+
181
+ # path parameters
182
+ if path_params:
183
+ path_params = self.sanitize_for_serialization(path_params)
184
+ path_params = self.parameters_to_tuples(path_params, collection_formats)
185
+ for k, v in path_params:
186
+ # specified safe chars, encode everything
187
+ resource_path = resource_path.replace(
188
+ "{%s}" % k, quote(str(v), safe=config.safe_chars_for_path_param)
189
+ )
190
+
191
+ # post parameters
192
+ if post_params or files:
193
+ post_params = post_params if post_params else []
194
+ post_params = self.sanitize_for_serialization(post_params)
195
+ post_params = self.parameters_to_tuples(post_params, collection_formats)
196
+ post_params.extend(self.files_parameters(files))
197
+
198
+ # auth setting
199
+ self.update_params_for_auth(
200
+ header_params,
201
+ query_params,
202
+ auth_settings,
203
+ resource_path,
204
+ method,
205
+ body,
206
+ request_auth=_request_auth,
207
+ )
208
+
209
+ # body
210
+ if body:
211
+ body = self.sanitize_for_serialization(body)
212
+
213
+ # request url
214
+ if _host is None:
215
+ url = self.configuration.host + resource_path
216
+ else:
217
+ # use server/host defined in path or operation instead
218
+ url = _host + resource_path
219
+
220
+ # query parameters
221
+ if query_params:
222
+ query_params = self.sanitize_for_serialization(query_params)
223
+ url_query = self.parameters_to_url_query(query_params, collection_formats)
224
+ url += "?" + url_query
225
+
226
+ try:
227
+ # perform request and return response
228
+ response_data = self.request(
229
+ method,
230
+ url,
231
+ query_params=query_params,
232
+ headers=header_params,
233
+ post_params=post_params,
234
+ body=body,
235
+ _preload_content=_preload_content,
236
+ _request_timeout=_request_timeout,
237
+ )
238
+ except ApiException as e:
239
+ if e.body:
240
+ e.body = e.body.decode("utf-8")
241
+ raise e
242
+
243
+ self.last_response = response_data
244
+
245
+ return_data = None # assuming deserialization is not needed
246
+ # data needs deserialization or returns HTTP data (deserialized) only
247
+ if _preload_content or _return_http_data_only:
248
+ response_type = response_types_map.get(str(response_data.status), None)
249
+ if (
250
+ not response_type
251
+ and isinstance(response_data.status, int)
252
+ and 100 <= response_data.status <= 599
253
+ ):
254
+ # if not found, look for '1XX', '2XX', etc.
255
+ response_type = response_types_map.get(
256
+ str(response_data.status)[0] + "XX", None
257
+ )
258
+
259
+ if response_type == "bytearray":
260
+ response_data.data = response_data.data
261
+ else:
262
+ match = None
263
+ content_type = response_data.getheader("content-type")
264
+ if content_type is not None:
265
+ match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
266
+ encoding = match.group(1) if match else "utf-8"
267
+ response_data.data = response_data.data.decode(encoding)
268
+
269
+ # deserialize response data
270
+ if response_type == "bytearray":
271
+ return_data = response_data.data
272
+ elif response_type:
273
+ return_data = self.deserialize(response_data, response_type)
274
+ else:
275
+ return_data = None
276
+
277
+ if _return_http_data_only:
278
+ return return_data
279
+ else:
280
+ return ApiResponse(
281
+ status_code=response_data.status,
282
+ data=return_data,
283
+ headers=response_data.getheaders(),
284
+ raw_data=response_data.data,
285
+ )
286
+
287
+ def sanitize_for_serialization(self, obj):
288
+ """Builds a JSON POST object.
289
+
290
+ If obj is None, return None.
291
+ If obj is str, int, long, float, bool, return directly.
292
+ If obj is datetime.datetime, datetime.date
293
+ convert to string in iso8601 format.
294
+ If obj is list, sanitize each element in the list.
295
+ If obj is dict, return the dict.
296
+ If obj is OpenAPI model, return the properties dict.
297
+
298
+ :param obj: The data to serialize.
299
+ :return: The serialized form of data.
300
+ """
301
+ if obj is None:
302
+ return None
303
+ elif isinstance(obj, self.PRIMITIVE_TYPES):
304
+ return obj
305
+ elif isinstance(obj, list):
306
+ return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
307
+ elif isinstance(obj, tuple):
308
+ return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj)
309
+ elif isinstance(obj, (datetime.datetime, datetime.date)):
310
+ return obj.isoformat()
311
+
312
+ if isinstance(obj, dict):
313
+ obj_dict = obj
314
+ else:
315
+ # Convert model obj to dict except
316
+ # attributes `openapi_types`, `attribute_map`
317
+ # and attributes which value is not None.
318
+ # Convert attribute name to json key in
319
+ # model definition for request.
320
+ obj_dict = obj.to_dict()
321
+
322
+ return {
323
+ key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()
324
+ }
325
+
326
+ def deserialize(self, response, response_type):
327
+ """Deserializes response into an object.
328
+
329
+ :param response: RESTResponse object to be deserialized.
330
+ :param response_type: class literal for
331
+ deserialized object, or string of class name.
332
+
333
+ :return: deserialized object.
334
+ """
335
+ # handle file downloading
336
+ # save response body into a tmp file and return the instance
337
+ if response_type == "file":
338
+ return self.__deserialize_file(response)
339
+
340
+ # fetch data from response object
341
+ try:
342
+ data = json.loads(response.data)
343
+ except ValueError:
344
+ data = response.data
345
+
346
+ return self.__deserialize(data, response_type)
347
+
348
+ def __deserialize(self, data, klass):
349
+ """Deserializes dict, list, str into an object.
350
+
351
+ :param data: dict, list or str.
352
+ :param klass: class literal, or string of class name.
353
+
354
+ :return: object.
355
+ """
356
+ if data is None:
357
+ return None
358
+
359
+ if isinstance(klass, str):
360
+ if klass.startswith("List["):
361
+ sub_kls = re.match(r"List\[(.*)]", klass).group(1)
362
+ return [self.__deserialize(sub_data, sub_kls) for sub_data in data]
363
+
364
+ if klass.startswith("Dict["):
365
+ sub_kls = re.match(r"Dict\[([^,]*), (.*)]", klass).group(2)
366
+ return {k: self.__deserialize(v, sub_kls) for k, v in data.items()}
367
+
368
+ # convert str to class
369
+ if klass in self.NATIVE_TYPES_MAPPING:
370
+ klass = self.NATIVE_TYPES_MAPPING[klass]
371
+ else:
372
+ klass = getattr(truefoundry.ml.autogen.client.models, klass)
373
+
374
+ if klass in self.PRIMITIVE_TYPES:
375
+ return self.__deserialize_primitive(data, klass)
376
+ elif klass == object:
377
+ return self.__deserialize_object(data)
378
+ elif klass == datetime.date:
379
+ return self.__deserialize_date(data)
380
+ elif klass == datetime.datetime:
381
+ return self.__deserialize_datetime(data)
382
+ else:
383
+ return self.__deserialize_model(data, klass)
384
+
385
+ def call_api(
386
+ self,
387
+ resource_path,
388
+ method,
389
+ path_params=None,
390
+ query_params=None,
391
+ header_params=None,
392
+ body=None,
393
+ post_params=None,
394
+ files=None,
395
+ response_types_map=None,
396
+ auth_settings=None,
397
+ async_req=None,
398
+ _return_http_data_only=None,
399
+ collection_formats=None,
400
+ _preload_content=True,
401
+ _request_timeout=None,
402
+ _host=None,
403
+ _request_auth=None,
404
+ ):
405
+ """Makes the HTTP request (synchronous) and returns deserialized data.
406
+
407
+ To make an async_req request, set the async_req parameter.
408
+
409
+ :param resource_path: Path to method endpoint.
410
+ :param method: Method to call.
411
+ :param path_params: Path parameters in the url.
412
+ :param query_params: Query parameters in the url.
413
+ :param header_params: Header parameters to be
414
+ placed in the request header.
415
+ :param body: Request body.
416
+ :param post_params dict: Request post form parameters,
417
+ for `application/x-www-form-urlencoded`, `multipart/form-data`.
418
+ :param auth_settings list: Auth Settings names for the request.
419
+ :param response: Response data type.
420
+ :param files dict: key -> filename, value -> filepath,
421
+ for `multipart/form-data`.
422
+ :param async_req bool: execute request asynchronously
423
+ :param _return_http_data_only: response data instead of ApiResponse
424
+ object with status code, headers, etc
425
+ :param _preload_content: if False, the ApiResponse.data will
426
+ be set to none and raw_data will store the
427
+ HTTP response body without reading/decoding.
428
+ Default is True.
429
+ :param collection_formats: dict of collection formats for path, query,
430
+ header, and post parameters.
431
+ :param _request_timeout: timeout setting for this request. If one
432
+ number provided, it will be total request
433
+ timeout. It can also be a pair (tuple) of
434
+ (connection, read) timeouts.
435
+ :param _request_auth: set to override the auth_settings for an a single
436
+ request; this effectively ignores the authentication
437
+ in the spec for a single request.
438
+ :type _request_token: dict, optional
439
+ :return:
440
+ If async_req parameter is True,
441
+ the request will be called asynchronously.
442
+ The method will return the request thread.
443
+ If parameter async_req is False or missing,
444
+ then the method will return the response directly.
445
+ """
446
+ args = (
447
+ resource_path,
448
+ method,
449
+ path_params,
450
+ query_params,
451
+ header_params,
452
+ body,
453
+ post_params,
454
+ files,
455
+ response_types_map,
456
+ auth_settings,
457
+ _return_http_data_only,
458
+ collection_formats,
459
+ _preload_content,
460
+ _request_timeout,
461
+ _host,
462
+ _request_auth,
463
+ )
464
+ if not async_req:
465
+ return self.__call_api(*args)
466
+
467
+ return self.pool.apply_async(self.__call_api, args)
468
+
469
+ def request(
470
+ self,
471
+ method,
472
+ url,
473
+ query_params=None,
474
+ headers=None,
475
+ post_params=None,
476
+ body=None,
477
+ _preload_content=True,
478
+ _request_timeout=None,
479
+ ):
480
+ """Makes the HTTP request using RESTClient."""
481
+ if method == "GET":
482
+ return self.rest_client.get_request(
483
+ url,
484
+ query_params=query_params,
485
+ _preload_content=_preload_content,
486
+ _request_timeout=_request_timeout,
487
+ headers=headers,
488
+ )
489
+ elif method == "HEAD":
490
+ return self.rest_client.head_request(
491
+ url,
492
+ query_params=query_params,
493
+ _preload_content=_preload_content,
494
+ _request_timeout=_request_timeout,
495
+ headers=headers,
496
+ )
497
+ elif method == "OPTIONS":
498
+ return self.rest_client.options_request(
499
+ url,
500
+ query_params=query_params,
501
+ headers=headers,
502
+ _preload_content=_preload_content,
503
+ _request_timeout=_request_timeout,
504
+ )
505
+ elif method == "POST":
506
+ return self.rest_client.post_request(
507
+ url,
508
+ query_params=query_params,
509
+ headers=headers,
510
+ post_params=post_params,
511
+ _preload_content=_preload_content,
512
+ _request_timeout=_request_timeout,
513
+ body=body,
514
+ )
515
+ elif method == "PUT":
516
+ return self.rest_client.put_request(
517
+ url,
518
+ query_params=query_params,
519
+ headers=headers,
520
+ post_params=post_params,
521
+ _preload_content=_preload_content,
522
+ _request_timeout=_request_timeout,
523
+ body=body,
524
+ )
525
+ elif method == "PATCH":
526
+ return self.rest_client.patch_request(
527
+ url,
528
+ query_params=query_params,
529
+ headers=headers,
530
+ post_params=post_params,
531
+ _preload_content=_preload_content,
532
+ _request_timeout=_request_timeout,
533
+ body=body,
534
+ )
535
+ elif method == "DELETE":
536
+ return self.rest_client.delete_request(
537
+ url,
538
+ query_params=query_params,
539
+ headers=headers,
540
+ _preload_content=_preload_content,
541
+ _request_timeout=_request_timeout,
542
+ body=body,
543
+ )
544
+ else:
545
+ raise ApiValueError(
546
+ "http method must be `GET`, `HEAD`, `OPTIONS`,"
547
+ " `POST`, `PATCH`, `PUT` or `DELETE`."
548
+ )
549
+
550
+ def parameters_to_tuples(self, params, collection_formats):
551
+ """Get parameters as list of tuples, formatting collections.
552
+
553
+ :param params: Parameters as dict or list of two-tuples
554
+ :param dict collection_formats: Parameter collection formats
555
+ :return: Parameters as list of tuples, collections formatted
556
+ """
557
+ new_params = []
558
+ if collection_formats is None:
559
+ collection_formats = {}
560
+ for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
561
+ if k in collection_formats:
562
+ collection_format = collection_formats[k]
563
+ if collection_format == "multi":
564
+ new_params.extend((k, value) for value in v)
565
+ else:
566
+ if collection_format == "ssv":
567
+ delimiter = " "
568
+ elif collection_format == "tsv":
569
+ delimiter = "\t"
570
+ elif collection_format == "pipes":
571
+ delimiter = "|"
572
+ else: # csv is the default
573
+ delimiter = ","
574
+ new_params.append((k, delimiter.join(str(value) for value in v)))
575
+ else:
576
+ new_params.append((k, v))
577
+ return new_params
578
+
579
+ def parameters_to_url_query(self, params, collection_formats):
580
+ """Get parameters as list of tuples, formatting collections.
581
+
582
+ :param params: Parameters as dict or list of two-tuples
583
+ :param dict collection_formats: Parameter collection formats
584
+ :return: URL query string (e.g. a=Hello%20World&b=123)
585
+ """
586
+ new_params = []
587
+ if collection_formats is None:
588
+ collection_formats = {}
589
+ for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501
590
+ if isinstance(v, bool):
591
+ v = str(v).lower()
592
+ if isinstance(v, (int, float)):
593
+ v = str(v)
594
+ if isinstance(v, dict):
595
+ v = json.dumps(v)
596
+
597
+ if k in collection_formats:
598
+ collection_format = collection_formats[k]
599
+ if collection_format == "multi":
600
+ new_params.extend((k, str(value)) for value in v)
601
+ else:
602
+ if collection_format == "ssv":
603
+ delimiter = " "
604
+ elif collection_format == "tsv":
605
+ delimiter = "\t"
606
+ elif collection_format == "pipes":
607
+ delimiter = "|"
608
+ else: # csv is the default
609
+ delimiter = ","
610
+ new_params.append(
611
+ (k, delimiter.join(quote(str(value)) for value in v))
612
+ )
613
+ else:
614
+ new_params.append((k, quote(str(v))))
615
+
616
+ return "&".join(["=".join(map(str, item)) for item in new_params])
617
+
618
+ def files_parameters(self, files=None):
619
+ """Builds form parameters.
620
+
621
+ :param files: File parameters.
622
+ :return: Form parameters with files.
623
+ """
624
+ params = []
625
+
626
+ if files:
627
+ for k, v in files.items():
628
+ if not v:
629
+ continue
630
+ file_names = v if type(v) is list else [v]
631
+ for n in file_names:
632
+ with open(n, "rb") as f:
633
+ filename = os.path.basename(f.name)
634
+ filedata = f.read()
635
+ mimetype = (
636
+ mimetypes.guess_type(filename)[0]
637
+ or "application/octet-stream"
638
+ )
639
+ params.append(tuple([k, tuple([filename, filedata, mimetype])]))
640
+
641
+ return params
642
+
643
+ def select_header_accept(self, accepts):
644
+ """Returns `Accept` based on an array of accepts provided.
645
+
646
+ :param accepts: List of headers.
647
+ :return: Accept (e.g. application/json).
648
+ """
649
+ if not accepts:
650
+ return
651
+
652
+ for accept in accepts:
653
+ if re.search("json", accept, re.IGNORECASE):
654
+ return accept
655
+
656
+ return accepts[0]
657
+
658
+ def select_header_content_type(self, content_types):
659
+ """Returns `Content-Type` based on an array of content_types provided.
660
+
661
+ :param content_types: List of content-types.
662
+ :return: Content-Type (e.g. application/json).
663
+ """
664
+ if not content_types:
665
+ return None
666
+
667
+ for content_type in content_types:
668
+ if re.search("json", content_type, re.IGNORECASE):
669
+ return content_type
670
+
671
+ return content_types[0]
672
+
673
+ def update_params_for_auth(
674
+ self,
675
+ headers,
676
+ queries,
677
+ auth_settings,
678
+ resource_path,
679
+ method,
680
+ body,
681
+ request_auth=None,
682
+ ):
683
+ """Updates header and query params based on authentication setting.
684
+
685
+ :param headers: Header parameters dict to be updated.
686
+ :param queries: Query parameters tuple list to be updated.
687
+ :param auth_settings: Authentication setting identifiers list.
688
+ :resource_path: A string representation of the HTTP request resource path.
689
+ :method: A string representation of the HTTP request method.
690
+ :body: A object representing the body of the HTTP request.
691
+ The object type is the return value of sanitize_for_serialization().
692
+ :param request_auth: if set, the provided settings will
693
+ override the token in the configuration.
694
+ """
695
+ if not auth_settings:
696
+ return
697
+
698
+ if request_auth:
699
+ self._apply_auth_params(
700
+ headers, queries, resource_path, method, body, request_auth
701
+ )
702
+ return
703
+
704
+ for auth in auth_settings:
705
+ auth_setting = self.configuration.auth_settings().get(auth)
706
+ if auth_setting:
707
+ self._apply_auth_params(
708
+ headers, queries, resource_path, method, body, auth_setting
709
+ )
710
+
711
+ def _apply_auth_params(
712
+ self, headers, queries, resource_path, method, body, auth_setting
713
+ ):
714
+ """Updates the request parameters based on a single auth_setting
715
+
716
+ :param headers: Header parameters dict to be updated.
717
+ :param queries: Query parameters tuple list to be updated.
718
+ :resource_path: A string representation of the HTTP request resource path.
719
+ :method: A string representation of the HTTP request method.
720
+ :body: A object representing the body of the HTTP request.
721
+ The object type is the return value of sanitize_for_serialization().
722
+ :param auth_setting: auth settings for the endpoint
723
+ """
724
+ if auth_setting["in"] == "cookie":
725
+ headers["Cookie"] = auth_setting["value"]
726
+ elif auth_setting["in"] == "header":
727
+ if auth_setting["type"] != "http-signature":
728
+ headers[auth_setting["key"]] = auth_setting["value"]
729
+ elif auth_setting["in"] == "query":
730
+ queries.append((auth_setting["key"], auth_setting["value"]))
731
+ else:
732
+ raise ApiValueError("Authentication token must be in `query` or `header`")
733
+
734
+ def __deserialize_file(self, response):
735
+ """Deserializes body to file
736
+
737
+ Saves response body into a file in a temporary folder,
738
+ using the filename from the `Content-Disposition` header if provided.
739
+
740
+ :param response: RESTResponse.
741
+ :return: file path.
742
+ """
743
+ fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
744
+ os.close(fd)
745
+ os.remove(path)
746
+
747
+ content_disposition = response.getheader("Content-Disposition")
748
+ if content_disposition:
749
+ filename = re.search(
750
+ r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition
751
+ ).group(1)
752
+ path = os.path.join(os.path.dirname(path), filename)
753
+
754
+ with open(path, "wb") as f:
755
+ f.write(response.data)
756
+
757
+ return path
758
+
759
+ def __deserialize_primitive(self, data, klass):
760
+ """Deserializes string to primitive type.
761
+
762
+ :param data: str.
763
+ :param klass: class literal.
764
+
765
+ :return: int, long, float, str, bool.
766
+ """
767
+ try:
768
+ return klass(data)
769
+ except UnicodeEncodeError:
770
+ return str(data)
771
+ except TypeError:
772
+ return data
773
+
774
+ def __deserialize_object(self, value):
775
+ """Return an original value.
776
+
777
+ :return: object.
778
+ """
779
+ return value
780
+
781
+ def __deserialize_date(self, string):
782
+ """Deserializes string to date.
783
+
784
+ :param string: str.
785
+ :return: date.
786
+ """
787
+ try:
788
+ return parse(string).date()
789
+ except ImportError:
790
+ return string
791
+ except ValueError:
792
+ raise rest.ApiException(
793
+ status=0, reason="Failed to parse `{0}` as date object".format(string)
794
+ )
795
+
796
+ def __deserialize_datetime(self, string):
797
+ """Deserializes string to datetime.
798
+
799
+ The string should be in iso8601 datetime format.
800
+
801
+ :param string: str.
802
+ :return: datetime.
803
+ """
804
+ try:
805
+ return parse(string)
806
+ except ImportError:
807
+ return string
808
+ except ValueError:
809
+ raise rest.ApiException(
810
+ status=0,
811
+ reason=("Failed to parse `{0}` as datetime object".format(string)),
812
+ )
813
+
814
+ def __deserialize_model(self, data, klass):
815
+ """Deserializes list or dict to model.
816
+
817
+ :param data: dict, list.
818
+ :param klass: class literal.
819
+ :return: model object.
820
+ """
821
+
822
+ return klass.from_dict(data)