flyte 0.0.1b0__py3-none-any.whl → 2.0.0b46__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.
Files changed (455) hide show
  1. flyte/__init__.py +83 -30
  2. flyte/_bin/connect.py +61 -0
  3. flyte/_bin/debug.py +38 -0
  4. flyte/_bin/runtime.py +87 -19
  5. flyte/_bin/serve.py +351 -0
  6. flyte/_build.py +3 -2
  7. flyte/_cache/cache.py +6 -5
  8. flyte/_cache/local_cache.py +216 -0
  9. flyte/_code_bundle/_ignore.py +31 -5
  10. flyte/_code_bundle/_packaging.py +42 -11
  11. flyte/_code_bundle/_utils.py +57 -34
  12. flyte/_code_bundle/bundle.py +130 -27
  13. flyte/_constants.py +1 -0
  14. flyte/_context.py +21 -5
  15. flyte/_custom_context.py +73 -0
  16. flyte/_debug/constants.py +37 -0
  17. flyte/_debug/utils.py +17 -0
  18. flyte/_debug/vscode.py +315 -0
  19. flyte/_deploy.py +396 -75
  20. flyte/_deployer.py +109 -0
  21. flyte/_environment.py +94 -11
  22. flyte/_excepthook.py +37 -0
  23. flyte/_group.py +2 -1
  24. flyte/_hash.py +1 -16
  25. flyte/_image.py +544 -234
  26. flyte/_initialize.py +443 -294
  27. flyte/_interface.py +40 -5
  28. flyte/_internal/controllers/__init__.py +22 -8
  29. flyte/_internal/controllers/_local_controller.py +159 -35
  30. flyte/_internal/controllers/_trace.py +18 -10
  31. flyte/_internal/controllers/remote/__init__.py +38 -9
  32. flyte/_internal/controllers/remote/_action.py +82 -12
  33. flyte/_internal/controllers/remote/_client.py +6 -2
  34. flyte/_internal/controllers/remote/_controller.py +290 -64
  35. flyte/_internal/controllers/remote/_core.py +155 -95
  36. flyte/_internal/controllers/remote/_informer.py +40 -20
  37. flyte/_internal/controllers/remote/_service_protocol.py +2 -2
  38. flyte/_internal/imagebuild/__init__.py +2 -10
  39. flyte/_internal/imagebuild/docker_builder.py +391 -84
  40. flyte/_internal/imagebuild/image_builder.py +111 -55
  41. flyte/_internal/imagebuild/remote_builder.py +409 -0
  42. flyte/_internal/imagebuild/utils.py +79 -0
  43. flyte/_internal/resolvers/_app_env_module.py +92 -0
  44. flyte/_internal/resolvers/_task_module.py +5 -38
  45. flyte/_internal/resolvers/app_env.py +26 -0
  46. flyte/_internal/resolvers/common.py +8 -1
  47. flyte/_internal/resolvers/default.py +2 -2
  48. flyte/_internal/runtime/convert.py +322 -33
  49. flyte/_internal/runtime/entrypoints.py +106 -18
  50. flyte/_internal/runtime/io.py +71 -23
  51. flyte/_internal/runtime/resources_serde.py +21 -7
  52. flyte/_internal/runtime/reuse.py +125 -0
  53. flyte/_internal/runtime/rusty.py +196 -0
  54. flyte/_internal/runtime/task_serde.py +239 -66
  55. flyte/_internal/runtime/taskrunner.py +48 -8
  56. flyte/_internal/runtime/trigger_serde.py +162 -0
  57. flyte/_internal/runtime/types_serde.py +7 -16
  58. flyte/_keyring/file.py +115 -0
  59. flyte/_link.py +30 -0
  60. flyte/_logging.py +241 -42
  61. flyte/_map.py +312 -0
  62. flyte/_metrics.py +59 -0
  63. flyte/_module.py +74 -0
  64. flyte/_pod.py +30 -0
  65. flyte/_resources.py +296 -33
  66. flyte/_retry.py +1 -7
  67. flyte/_reusable_environment.py +72 -7
  68. flyte/_run.py +461 -132
  69. flyte/_secret.py +47 -11
  70. flyte/_serve.py +333 -0
  71. flyte/_task.py +245 -56
  72. flyte/_task_environment.py +219 -97
  73. flyte/_task_plugins.py +47 -0
  74. flyte/_tools.py +8 -8
  75. flyte/_trace.py +15 -24
  76. flyte/_trigger.py +1027 -0
  77. flyte/_utils/__init__.py +12 -1
  78. flyte/_utils/asyn.py +3 -1
  79. flyte/_utils/async_cache.py +139 -0
  80. flyte/_utils/coro_management.py +5 -4
  81. flyte/_utils/description_parser.py +19 -0
  82. flyte/_utils/docker_credentials.py +173 -0
  83. flyte/_utils/helpers.py +45 -19
  84. flyte/_utils/module_loader.py +123 -0
  85. flyte/_utils/org_discovery.py +57 -0
  86. flyte/_utils/uv_script_parser.py +8 -1
  87. flyte/_version.py +16 -3
  88. flyte/app/__init__.py +27 -0
  89. flyte/app/_app_environment.py +362 -0
  90. flyte/app/_connector_environment.py +40 -0
  91. flyte/app/_deploy.py +130 -0
  92. flyte/app/_parameter.py +343 -0
  93. flyte/app/_runtime/__init__.py +3 -0
  94. flyte/app/_runtime/app_serde.py +383 -0
  95. flyte/app/_types.py +113 -0
  96. flyte/app/extras/__init__.py +9 -0
  97. flyte/app/extras/_auth_middleware.py +217 -0
  98. flyte/app/extras/_fastapi.py +93 -0
  99. flyte/app/extras/_model_loader/__init__.py +3 -0
  100. flyte/app/extras/_model_loader/config.py +7 -0
  101. flyte/app/extras/_model_loader/loader.py +288 -0
  102. flyte/cli/__init__.py +12 -0
  103. flyte/cli/_abort.py +28 -0
  104. flyte/cli/_build.py +114 -0
  105. flyte/cli/_common.py +493 -0
  106. flyte/cli/_create.py +371 -0
  107. flyte/cli/_delete.py +45 -0
  108. flyte/cli/_deploy.py +401 -0
  109. flyte/cli/_gen.py +316 -0
  110. flyte/cli/_get.py +446 -0
  111. flyte/cli/_option.py +33 -0
  112. {union/_cli → flyte/cli}/_params.py +152 -153
  113. flyte/cli/_plugins.py +209 -0
  114. flyte/cli/_prefetch.py +292 -0
  115. flyte/cli/_run.py +690 -0
  116. flyte/cli/_serve.py +338 -0
  117. flyte/cli/_update.py +86 -0
  118. flyte/cli/_user.py +20 -0
  119. flyte/cli/main.py +246 -0
  120. flyte/config/__init__.py +3 -0
  121. flyte/config/_config.py +248 -0
  122. flyte/config/_internal.py +73 -0
  123. flyte/config/_reader.py +225 -0
  124. flyte/connectors/__init__.py +11 -0
  125. flyte/connectors/_connector.py +330 -0
  126. flyte/connectors/_server.py +194 -0
  127. flyte/connectors/utils.py +159 -0
  128. flyte/errors.py +134 -2
  129. flyte/extend.py +24 -0
  130. flyte/extras/_container.py +69 -56
  131. flyte/git/__init__.py +3 -0
  132. flyte/git/_config.py +279 -0
  133. flyte/io/__init__.py +8 -1
  134. flyte/io/{structured_dataset → _dataframe}/__init__.py +32 -30
  135. flyte/io/{structured_dataset → _dataframe}/basic_dfs.py +75 -68
  136. flyte/io/{structured_dataset/structured_dataset.py → _dataframe/dataframe.py} +207 -242
  137. flyte/io/_dir.py +575 -113
  138. flyte/io/_file.py +587 -141
  139. flyte/io/_hashing_io.py +342 -0
  140. flyte/io/extend.py +7 -0
  141. flyte/models.py +635 -0
  142. flyte/prefetch/__init__.py +22 -0
  143. flyte/prefetch/_hf_model.py +563 -0
  144. flyte/remote/__init__.py +14 -3
  145. flyte/remote/_action.py +879 -0
  146. flyte/remote/_app.py +346 -0
  147. flyte/remote/_auth_metadata.py +42 -0
  148. flyte/remote/_client/_protocols.py +62 -4
  149. flyte/remote/_client/auth/_auth_utils.py +19 -0
  150. flyte/remote/_client/auth/_authenticators/base.py +8 -2
  151. flyte/remote/_client/auth/_authenticators/device_code.py +4 -5
  152. flyte/remote/_client/auth/_authenticators/factory.py +4 -0
  153. flyte/remote/_client/auth/_authenticators/passthrough.py +79 -0
  154. flyte/remote/_client/auth/_authenticators/pkce.py +17 -18
  155. flyte/remote/_client/auth/_channel.py +47 -18
  156. flyte/remote/_client/auth/_client_config.py +5 -3
  157. flyte/remote/_client/auth/_keyring.py +15 -2
  158. flyte/remote/_client/auth/_token_client.py +3 -3
  159. flyte/remote/_client/controlplane.py +206 -18
  160. flyte/remote/_common.py +66 -0
  161. flyte/remote/_data.py +107 -22
  162. flyte/remote/_logs.py +116 -33
  163. flyte/remote/_project.py +21 -19
  164. flyte/remote/_run.py +164 -631
  165. flyte/remote/_secret.py +72 -29
  166. flyte/remote/_task.py +387 -46
  167. flyte/remote/_trigger.py +368 -0
  168. flyte/remote/_user.py +43 -0
  169. flyte/report/_report.py +10 -6
  170. flyte/storage/__init__.py +13 -1
  171. flyte/storage/_config.py +237 -0
  172. flyte/storage/_parallel_reader.py +289 -0
  173. flyte/storage/_storage.py +268 -59
  174. flyte/syncify/__init__.py +56 -0
  175. flyte/syncify/_api.py +414 -0
  176. flyte/types/__init__.py +39 -0
  177. flyte/types/_interface.py +22 -7
  178. flyte/{io/pickle/transformer.py → types/_pickle.py} +37 -9
  179. flyte/types/_string_literals.py +8 -9
  180. flyte/types/_type_engine.py +230 -129
  181. flyte/types/_utils.py +1 -1
  182. flyte-2.0.0b46.data/scripts/debug.py +38 -0
  183. flyte-2.0.0b46.data/scripts/runtime.py +194 -0
  184. flyte-2.0.0b46.dist-info/METADATA +352 -0
  185. flyte-2.0.0b46.dist-info/RECORD +221 -0
  186. flyte-2.0.0b46.dist-info/entry_points.txt +8 -0
  187. flyte-2.0.0b46.dist-info/licenses/LICENSE +201 -0
  188. flyte/_api_commons.py +0 -3
  189. flyte/_cli/_common.py +0 -287
  190. flyte/_cli/_create.py +0 -42
  191. flyte/_cli/_delete.py +0 -23
  192. flyte/_cli/_deploy.py +0 -140
  193. flyte/_cli/_get.py +0 -235
  194. flyte/_cli/_run.py +0 -152
  195. flyte/_cli/main.py +0 -72
  196. flyte/_datastructures.py +0 -342
  197. flyte/_internal/controllers/pbhash.py +0 -39
  198. flyte/_protos/common/authorization_pb2.py +0 -66
  199. flyte/_protos/common/authorization_pb2.pyi +0 -108
  200. flyte/_protos/common/authorization_pb2_grpc.py +0 -4
  201. flyte/_protos/common/identifier_pb2.py +0 -71
  202. flyte/_protos/common/identifier_pb2.pyi +0 -82
  203. flyte/_protos/common/identifier_pb2_grpc.py +0 -4
  204. flyte/_protos/common/identity_pb2.py +0 -48
  205. flyte/_protos/common/identity_pb2.pyi +0 -72
  206. flyte/_protos/common/identity_pb2_grpc.py +0 -4
  207. flyte/_protos/common/list_pb2.py +0 -36
  208. flyte/_protos/common/list_pb2.pyi +0 -69
  209. flyte/_protos/common/list_pb2_grpc.py +0 -4
  210. flyte/_protos/common/policy_pb2.py +0 -37
  211. flyte/_protos/common/policy_pb2.pyi +0 -27
  212. flyte/_protos/common/policy_pb2_grpc.py +0 -4
  213. flyte/_protos/common/role_pb2.py +0 -37
  214. flyte/_protos/common/role_pb2.pyi +0 -53
  215. flyte/_protos/common/role_pb2_grpc.py +0 -4
  216. flyte/_protos/common/runtime_version_pb2.py +0 -28
  217. flyte/_protos/common/runtime_version_pb2.pyi +0 -24
  218. flyte/_protos/common/runtime_version_pb2_grpc.py +0 -4
  219. flyte/_protos/logs/dataplane/payload_pb2.py +0 -96
  220. flyte/_protos/logs/dataplane/payload_pb2.pyi +0 -168
  221. flyte/_protos/logs/dataplane/payload_pb2_grpc.py +0 -4
  222. flyte/_protos/secret/definition_pb2.py +0 -49
  223. flyte/_protos/secret/definition_pb2.pyi +0 -93
  224. flyte/_protos/secret/definition_pb2_grpc.py +0 -4
  225. flyte/_protos/secret/payload_pb2.py +0 -62
  226. flyte/_protos/secret/payload_pb2.pyi +0 -94
  227. flyte/_protos/secret/payload_pb2_grpc.py +0 -4
  228. flyte/_protos/secret/secret_pb2.py +0 -38
  229. flyte/_protos/secret/secret_pb2.pyi +0 -6
  230. flyte/_protos/secret/secret_pb2_grpc.py +0 -198
  231. flyte/_protos/secret/secret_pb2_grpc_grpc.py +0 -198
  232. flyte/_protos/validate/validate/validate_pb2.py +0 -76
  233. flyte/_protos/workflow/node_execution_service_pb2.py +0 -26
  234. flyte/_protos/workflow/node_execution_service_pb2.pyi +0 -4
  235. flyte/_protos/workflow/node_execution_service_pb2_grpc.py +0 -32
  236. flyte/_protos/workflow/queue_service_pb2.py +0 -106
  237. flyte/_protos/workflow/queue_service_pb2.pyi +0 -141
  238. flyte/_protos/workflow/queue_service_pb2_grpc.py +0 -172
  239. flyte/_protos/workflow/run_definition_pb2.py +0 -128
  240. flyte/_protos/workflow/run_definition_pb2.pyi +0 -310
  241. flyte/_protos/workflow/run_definition_pb2_grpc.py +0 -4
  242. flyte/_protos/workflow/run_logs_service_pb2.py +0 -41
  243. flyte/_protos/workflow/run_logs_service_pb2.pyi +0 -28
  244. flyte/_protos/workflow/run_logs_service_pb2_grpc.py +0 -69
  245. flyte/_protos/workflow/run_service_pb2.py +0 -133
  246. flyte/_protos/workflow/run_service_pb2.pyi +0 -175
  247. flyte/_protos/workflow/run_service_pb2_grpc.py +0 -412
  248. flyte/_protos/workflow/state_service_pb2.py +0 -58
  249. flyte/_protos/workflow/state_service_pb2.pyi +0 -71
  250. flyte/_protos/workflow/state_service_pb2_grpc.py +0 -138
  251. flyte/_protos/workflow/task_definition_pb2.py +0 -72
  252. flyte/_protos/workflow/task_definition_pb2.pyi +0 -65
  253. flyte/_protos/workflow/task_definition_pb2_grpc.py +0 -4
  254. flyte/_protos/workflow/task_service_pb2.py +0 -44
  255. flyte/_protos/workflow/task_service_pb2.pyi +0 -31
  256. flyte/_protos/workflow/task_service_pb2_grpc.py +0 -104
  257. flyte/io/_dataframe.py +0 -0
  258. flyte/io/pickle/__init__.py +0 -0
  259. flyte/remote/_console.py +0 -18
  260. flyte-0.0.1b0.dist-info/METADATA +0 -179
  261. flyte-0.0.1b0.dist-info/RECORD +0 -390
  262. flyte-0.0.1b0.dist-info/entry_points.txt +0 -3
  263. union/__init__.py +0 -54
  264. union/_api_commons.py +0 -3
  265. union/_bin/__init__.py +0 -0
  266. union/_bin/runtime.py +0 -113
  267. union/_build.py +0 -25
  268. union/_cache/__init__.py +0 -12
  269. union/_cache/cache.py +0 -141
  270. union/_cache/defaults.py +0 -9
  271. union/_cache/policy_function_body.py +0 -42
  272. union/_cli/__init__.py +0 -0
  273. union/_cli/_common.py +0 -263
  274. union/_cli/_create.py +0 -40
  275. union/_cli/_delete.py +0 -23
  276. union/_cli/_deploy.py +0 -120
  277. union/_cli/_get.py +0 -162
  278. union/_cli/_run.py +0 -150
  279. union/_cli/main.py +0 -72
  280. union/_code_bundle/__init__.py +0 -8
  281. union/_code_bundle/_ignore.py +0 -113
  282. union/_code_bundle/_packaging.py +0 -187
  283. union/_code_bundle/_utils.py +0 -342
  284. union/_code_bundle/bundle.py +0 -176
  285. union/_context.py +0 -146
  286. union/_datastructures.py +0 -295
  287. union/_deploy.py +0 -185
  288. union/_doc.py +0 -29
  289. union/_docstring.py +0 -26
  290. union/_environment.py +0 -43
  291. union/_group.py +0 -31
  292. union/_hash.py +0 -23
  293. union/_image.py +0 -760
  294. union/_initialize.py +0 -585
  295. union/_interface.py +0 -84
  296. union/_internal/__init__.py +0 -3
  297. union/_internal/controllers/__init__.py +0 -77
  298. union/_internal/controllers/_local_controller.py +0 -77
  299. union/_internal/controllers/pbhash.py +0 -39
  300. union/_internal/controllers/remote/__init__.py +0 -40
  301. union/_internal/controllers/remote/_action.py +0 -131
  302. union/_internal/controllers/remote/_client.py +0 -43
  303. union/_internal/controllers/remote/_controller.py +0 -169
  304. union/_internal/controllers/remote/_core.py +0 -341
  305. union/_internal/controllers/remote/_informer.py +0 -260
  306. union/_internal/controllers/remote/_service_protocol.py +0 -44
  307. union/_internal/imagebuild/__init__.py +0 -11
  308. union/_internal/imagebuild/docker_builder.py +0 -416
  309. union/_internal/imagebuild/image_builder.py +0 -243
  310. union/_internal/imagebuild/remote_builder.py +0 -0
  311. union/_internal/resolvers/__init__.py +0 -0
  312. union/_internal/resolvers/_task_module.py +0 -31
  313. union/_internal/resolvers/common.py +0 -24
  314. union/_internal/resolvers/default.py +0 -27
  315. union/_internal/runtime/__init__.py +0 -0
  316. union/_internal/runtime/convert.py +0 -163
  317. union/_internal/runtime/entrypoints.py +0 -121
  318. union/_internal/runtime/io.py +0 -136
  319. union/_internal/runtime/resources_serde.py +0 -134
  320. union/_internal/runtime/task_serde.py +0 -202
  321. union/_internal/runtime/taskrunner.py +0 -179
  322. union/_internal/runtime/types_serde.py +0 -53
  323. union/_logging.py +0 -124
  324. union/_protos/__init__.py +0 -0
  325. union/_protos/common/authorization_pb2.py +0 -66
  326. union/_protos/common/authorization_pb2.pyi +0 -106
  327. union/_protos/common/authorization_pb2_grpc.py +0 -4
  328. union/_protos/common/identifier_pb2.py +0 -71
  329. union/_protos/common/identifier_pb2.pyi +0 -82
  330. union/_protos/common/identifier_pb2_grpc.py +0 -4
  331. union/_protos/common/identity_pb2.py +0 -48
  332. union/_protos/common/identity_pb2.pyi +0 -72
  333. union/_protos/common/identity_pb2_grpc.py +0 -4
  334. union/_protos/common/list_pb2.py +0 -36
  335. union/_protos/common/list_pb2.pyi +0 -69
  336. union/_protos/common/list_pb2_grpc.py +0 -4
  337. union/_protos/common/policy_pb2.py +0 -37
  338. union/_protos/common/policy_pb2.pyi +0 -27
  339. union/_protos/common/policy_pb2_grpc.py +0 -4
  340. union/_protos/common/role_pb2.py +0 -37
  341. union/_protos/common/role_pb2.pyi +0 -51
  342. union/_protos/common/role_pb2_grpc.py +0 -4
  343. union/_protos/common/runtime_version_pb2.py +0 -28
  344. union/_protos/common/runtime_version_pb2.pyi +0 -24
  345. union/_protos/common/runtime_version_pb2_grpc.py +0 -4
  346. union/_protos/logs/dataplane/payload_pb2.py +0 -96
  347. union/_protos/logs/dataplane/payload_pb2.pyi +0 -168
  348. union/_protos/logs/dataplane/payload_pb2_grpc.py +0 -4
  349. union/_protos/secret/definition_pb2.py +0 -49
  350. union/_protos/secret/definition_pb2.pyi +0 -93
  351. union/_protos/secret/definition_pb2_grpc.py +0 -4
  352. union/_protos/secret/payload_pb2.py +0 -62
  353. union/_protos/secret/payload_pb2.pyi +0 -94
  354. union/_protos/secret/payload_pb2_grpc.py +0 -4
  355. union/_protos/secret/secret_pb2.py +0 -38
  356. union/_protos/secret/secret_pb2.pyi +0 -6
  357. union/_protos/secret/secret_pb2_grpc.py +0 -198
  358. union/_protos/validate/validate/validate_pb2.py +0 -76
  359. union/_protos/workflow/node_execution_service_pb2.py +0 -26
  360. union/_protos/workflow/node_execution_service_pb2.pyi +0 -4
  361. union/_protos/workflow/node_execution_service_pb2_grpc.py +0 -32
  362. union/_protos/workflow/queue_service_pb2.py +0 -75
  363. union/_protos/workflow/queue_service_pb2.pyi +0 -103
  364. union/_protos/workflow/queue_service_pb2_grpc.py +0 -172
  365. union/_protos/workflow/run_definition_pb2.py +0 -100
  366. union/_protos/workflow/run_definition_pb2.pyi +0 -256
  367. union/_protos/workflow/run_definition_pb2_grpc.py +0 -4
  368. union/_protos/workflow/run_logs_service_pb2.py +0 -41
  369. union/_protos/workflow/run_logs_service_pb2.pyi +0 -28
  370. union/_protos/workflow/run_logs_service_pb2_grpc.py +0 -69
  371. union/_protos/workflow/run_service_pb2.py +0 -133
  372. union/_protos/workflow/run_service_pb2.pyi +0 -173
  373. union/_protos/workflow/run_service_pb2_grpc.py +0 -412
  374. union/_protos/workflow/state_service_pb2.py +0 -58
  375. union/_protos/workflow/state_service_pb2.pyi +0 -69
  376. union/_protos/workflow/state_service_pb2_grpc.py +0 -138
  377. union/_protos/workflow/task_definition_pb2.py +0 -72
  378. union/_protos/workflow/task_definition_pb2.pyi +0 -65
  379. union/_protos/workflow/task_definition_pb2_grpc.py +0 -4
  380. union/_protos/workflow/task_service_pb2.py +0 -44
  381. union/_protos/workflow/task_service_pb2.pyi +0 -31
  382. union/_protos/workflow/task_service_pb2_grpc.py +0 -104
  383. union/_resources.py +0 -226
  384. union/_retry.py +0 -32
  385. union/_reusable_environment.py +0 -25
  386. union/_run.py +0 -374
  387. union/_secret.py +0 -61
  388. union/_task.py +0 -354
  389. union/_task_environment.py +0 -186
  390. union/_timeout.py +0 -47
  391. union/_tools.py +0 -27
  392. union/_utils/__init__.py +0 -11
  393. union/_utils/asyn.py +0 -119
  394. union/_utils/file_handling.py +0 -71
  395. union/_utils/helpers.py +0 -46
  396. union/_utils/lazy_module.py +0 -54
  397. union/_utils/uv_script_parser.py +0 -49
  398. union/_version.py +0 -21
  399. union/connectors/__init__.py +0 -0
  400. union/errors.py +0 -128
  401. union/extras/__init__.py +0 -5
  402. union/extras/_container.py +0 -263
  403. union/io/__init__.py +0 -11
  404. union/io/_dataframe.py +0 -0
  405. union/io/_dir.py +0 -425
  406. union/io/_file.py +0 -418
  407. union/io/pickle/__init__.py +0 -0
  408. union/io/pickle/transformer.py +0 -117
  409. union/io/structured_dataset/__init__.py +0 -122
  410. union/io/structured_dataset/basic_dfs.py +0 -219
  411. union/io/structured_dataset/structured_dataset.py +0 -1057
  412. union/py.typed +0 -0
  413. union/remote/__init__.py +0 -23
  414. union/remote/_client/__init__.py +0 -0
  415. union/remote/_client/_protocols.py +0 -129
  416. union/remote/_client/auth/__init__.py +0 -12
  417. union/remote/_client/auth/_authenticators/__init__.py +0 -0
  418. union/remote/_client/auth/_authenticators/base.py +0 -391
  419. union/remote/_client/auth/_authenticators/client_credentials.py +0 -73
  420. union/remote/_client/auth/_authenticators/device_code.py +0 -120
  421. union/remote/_client/auth/_authenticators/external_command.py +0 -77
  422. union/remote/_client/auth/_authenticators/factory.py +0 -200
  423. union/remote/_client/auth/_authenticators/pkce.py +0 -515
  424. union/remote/_client/auth/_channel.py +0 -184
  425. union/remote/_client/auth/_client_config.py +0 -83
  426. union/remote/_client/auth/_default_html.py +0 -32
  427. union/remote/_client/auth/_grpc_utils/__init__.py +0 -0
  428. union/remote/_client/auth/_grpc_utils/auth_interceptor.py +0 -204
  429. union/remote/_client/auth/_grpc_utils/default_metadata_interceptor.py +0 -144
  430. union/remote/_client/auth/_keyring.py +0 -154
  431. union/remote/_client/auth/_token_client.py +0 -258
  432. union/remote/_client/auth/errors.py +0 -16
  433. union/remote/_client/controlplane.py +0 -86
  434. union/remote/_data.py +0 -149
  435. union/remote/_logs.py +0 -74
  436. union/remote/_project.py +0 -86
  437. union/remote/_run.py +0 -820
  438. union/remote/_secret.py +0 -132
  439. union/remote/_task.py +0 -193
  440. union/report/__init__.py +0 -3
  441. union/report/_report.py +0 -178
  442. union/report/_template.html +0 -124
  443. union/storage/__init__.py +0 -24
  444. union/storage/_remote_fs.py +0 -34
  445. union/storage/_storage.py +0 -247
  446. union/storage/_utils.py +0 -5
  447. union/types/__init__.py +0 -11
  448. union/types/_renderer.py +0 -162
  449. union/types/_string_literals.py +0 -120
  450. union/types/_type_engine.py +0 -2131
  451. union/types/_utils.py +0 -80
  452. /flyte/{_cli → _debug}/__init__.py +0 -0
  453. /flyte/{_protos → _keyring}/__init__.py +0 -0
  454. {flyte-0.0.1b0.dist-info → flyte-2.0.0b46.dist-info}/WHEEL +0 -0
  455. {flyte-0.0.1b0.dist-info → flyte-2.0.0b46.dist-info}/top_level.txt +0 -0
flyte/_initialize.py CHANGED
@@ -1,260 +1,28 @@
1
1
  from __future__ import annotations
2
2
 
3
- import datetime
4
3
  import functools
5
- import os
4
+ import sys
6
5
  import threading
7
6
  import typing
8
- from dataclasses import dataclass, replace
9
- from datetime import timedelta
7
+ from dataclasses import dataclass, field, replace
10
8
  from pathlib import Path
11
- from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, List, Literal, Optional, TypeVar
9
+ from typing import TYPE_CHECKING, Callable, List, Literal, Optional, TypeVar
12
10
 
13
11
  from flyte.errors import InitializationError
12
+ from flyte.syncify import syncify
14
13
 
15
- from ._api_commons import syncer
16
- from ._logging import initialize_logger
17
- from ._tools import ipython_check
14
+ from ._logging import LogFormat, initialize_logger, logger
18
15
 
19
16
  if TYPE_CHECKING:
17
+ from flyte._internal.imagebuild import ImageBuildEngine
18
+ from flyte.config import Config
20
19
  from flyte.remote._client.auth import AuthType, ClientConfig
21
20
  from flyte.remote._client.controlplane import ClientSet
21
+ from flyte.storage import Storage
22
22
 
23
23
  Mode = Literal["local", "remote"]
24
24
 
25
25
 
26
- def set_if_exists(d: dict, k: str, val: typing.Any) -> dict:
27
- """
28
- Given a dict ``d`` sets the key ``k`` with value of config ``v``, if the config value ``v`` is set
29
- and return the updated dictionary.
30
- """
31
- exists = isinstance(val, bool) or bool(val is not None and val)
32
- if exists:
33
- d[k] = val
34
- return d
35
-
36
-
37
- @dataclass(init=True, repr=True, eq=True, frozen=True)
38
- class Storage(object):
39
- """
40
- Data storage configuration that applies across any provider.
41
- """
42
-
43
- retries: int = 3
44
- backoff: datetime.timedelta = datetime.timedelta(seconds=5)
45
- enable_debug: bool = False
46
- attach_execution_metadata: bool = True
47
-
48
- _KEY_ENV_VAR_MAPPING: ClassVar[typing.Dict[str, str]] = {
49
- "enable_debug": "UNION_STORAGE_DEBUG",
50
- "retries": "UNION_STORAGE_RETRIES",
51
- "backoff": "UNION_STORAGE_BACKOFF_SECONDS",
52
- }
53
-
54
- def get_fsspec_kwargs(self, anonymous: bool = False, /, **kwargs) -> Dict[str, Any]:
55
- """
56
- Returns the configuration as kwargs for constructing an fsspec filesystem.
57
- """
58
- return {}
59
-
60
- @classmethod
61
- def _auto_as_kwargs(cls) -> Dict[str, Any]:
62
- retries = os.getenv(cls._KEY_ENV_VAR_MAPPING["retries"])
63
- backoff = os.getenv(cls._KEY_ENV_VAR_MAPPING["backoff"])
64
- enable_debug = os.getenv(cls._KEY_ENV_VAR_MAPPING["enable_debug"])
65
-
66
- kwargs: Dict[str, Any] = {}
67
- kwargs = set_if_exists(kwargs, "enable_debug", enable_debug)
68
- kwargs = set_if_exists(kwargs, "retries", retries)
69
- kwargs = set_if_exists(kwargs, "backoff", backoff)
70
- return kwargs
71
-
72
- @classmethod
73
- def auto(cls) -> Storage:
74
- """
75
- Construct the config object automatically from environment variables.
76
- """
77
- return cls(**cls._auto_as_kwargs())
78
-
79
-
80
- @dataclass(init=True, repr=True, eq=True, frozen=True)
81
- class S3(Storage):
82
- """
83
- S3 specific configuration
84
- """
85
-
86
- endpoint: typing.Optional[str] = None
87
- access_key_id: typing.Optional[str] = None
88
- secret_access_key: typing.Optional[str] = None
89
-
90
- _KEY_ENV_VAR_MAPPING: ClassVar[typing.Dict[str, str]] = {
91
- "endpoint": "FLYTE_AWS_ENDPOINT",
92
- "access_key_id": "FLYTE_AWS_ACCESS_KEY_ID",
93
- "secret_access_key": "FLYTE_AWS_SECRET_ACCESS_KEY",
94
- } | Storage._KEY_ENV_VAR_MAPPING
95
-
96
- # Refer to https://github.com/developmentseed/obstore/blob/33654fc37f19a657689eb93327b621e9f9e01494/obstore/python/obstore/store/_aws.pyi#L11
97
- # for key and secret
98
- _CONFIG_KEY_FSSPEC_S3_KEY_ID: ClassVar = "access_key_id"
99
- _CONFIG_KEY_FSSPEC_S3_SECRET: ClassVar = "secret_access_key"
100
- _CONFIG_KEY_ENDPOINT: ClassVar = "endpoint_url"
101
- _KEY_SKIP_SIGNATURE: ClassVar = "skip_signature"
102
-
103
- @classmethod
104
- def auto(cls) -> S3:
105
- """
106
- :return: Config
107
- """
108
- endpoint = os.getenv(cls._KEY_ENV_VAR_MAPPING["endpoint"], None)
109
- access_key_id = os.getenv(cls._KEY_ENV_VAR_MAPPING["access_key_id"], None)
110
- secret_access_key = os.getenv(cls._KEY_ENV_VAR_MAPPING["secret_access_key"], None)
111
-
112
- kwargs = super()._auto_as_kwargs()
113
- kwargs = set_if_exists(kwargs, "endpoint", endpoint)
114
- kwargs = set_if_exists(kwargs, "access_key_id", access_key_id)
115
- kwargs = set_if_exists(kwargs, "secret_access_key", secret_access_key)
116
-
117
- return S3(**kwargs)
118
-
119
- @classmethod
120
- def for_sandbox(cls) -> S3:
121
- """
122
- :return:
123
- """
124
- kwargs = super()._auto_as_kwargs()
125
- final_kwargs = kwargs | {
126
- "endpoint": "http://localhost:4566",
127
- "access_key_id": "minio",
128
- "secret_access_key": "miniostorage",
129
- }
130
- return S3(**final_kwargs)
131
-
132
- def get_fsspec_kwargs(self, anonymous: bool = False, /, **kwargs) -> Dict[str, Any]:
133
- # Construct the config object
134
- config: Dict[str, Any] = {}
135
- if self._CONFIG_KEY_FSSPEC_S3_KEY_ID in kwargs or self.access_key_id:
136
- config[self._CONFIG_KEY_FSSPEC_S3_KEY_ID] = kwargs.pop(
137
- self._CONFIG_KEY_FSSPEC_S3_KEY_ID, self.access_key_id
138
- )
139
- if self._CONFIG_KEY_FSSPEC_S3_SECRET in kwargs or self.secret_access_key:
140
- config[self._CONFIG_KEY_FSSPEC_S3_SECRET] = kwargs.pop(
141
- self._CONFIG_KEY_FSSPEC_S3_SECRET, self.secret_access_key
142
- )
143
- if self._CONFIG_KEY_ENDPOINT in kwargs or self.endpoint:
144
- config["endpoint_url"] = kwargs.pop(self._CONFIG_KEY_ENDPOINT, self.endpoint)
145
-
146
- retries = kwargs.pop("retries", self.retries)
147
- backoff = kwargs.pop("backoff", self.backoff)
148
-
149
- if anonymous:
150
- config[self._KEY_SKIP_SIGNATURE] = True
151
-
152
- retry_config = {
153
- "max_retries": retries,
154
- "backoff": {
155
- "base": 2,
156
- "init_backoff": backoff,
157
- "max_backoff": timedelta(seconds=16),
158
- },
159
- "retry_timeout": timedelta(minutes=3),
160
- }
161
-
162
- client_options = {"timeout": "99999s", "allow_http": True}
163
-
164
- if config:
165
- kwargs["config"] = config
166
- kwargs["client_options"] = client_options or None
167
- kwargs["retry_config"] = retry_config or None
168
-
169
- return kwargs
170
-
171
-
172
- @dataclass(init=True, repr=True, eq=True, frozen=True)
173
- class GCS(Storage):
174
- """
175
- Any GCS specific configuration.
176
- """
177
-
178
- gsutil_parallelism: bool = False
179
-
180
- _KEY_ENV_VAR_MAPPING: ClassVar[dict[str, str]] = {
181
- "gsutil_parallelism": "GCP_GSUTIL_PARALLELISM",
182
- }
183
-
184
- @classmethod
185
- def auto(cls) -> GCS:
186
- gsutil_parallelism = os.getenv(cls._KEY_ENV_VAR_MAPPING["gsutil_parallelism"], None)
187
-
188
- kwargs: Dict[str, Any] = {}
189
- kwargs = set_if_exists(kwargs, "gsutil_parallelism", gsutil_parallelism)
190
- return GCS(**kwargs)
191
-
192
- def get_fsspec_kwargs(self, anonymous: bool = False, /, **kwargs) -> Dict[str, Any]:
193
- return kwargs
194
-
195
-
196
- @dataclass(init=True, repr=True, eq=True, frozen=True)
197
- class ABFS(Storage):
198
- """
199
- Any Azure Blob Storage specific configuration.
200
- """
201
-
202
- account_name: typing.Optional[str] = None
203
- account_key: typing.Optional[str] = None
204
- tenant_id: typing.Optional[str] = None
205
- client_id: typing.Optional[str] = None
206
- client_secret: typing.Optional[str] = None
207
-
208
- _KEY_ENV_VAR_MAPPING: ClassVar[dict[str, str]] = {
209
- "account_name": "AZURE_STORAGE_ACCOUNT_NAME",
210
- "account_key": "AZURE_STORAGE_ACCOUNT_KEY",
211
- "tenant_id": "AZURE_TENANT_ID",
212
- "client_id": "AZURE_CLIENT_ID",
213
- "client_secret": "AZURE_CLIENT_SECRET",
214
- }
215
- _KEY_SKIP_SIGNATURE: ClassVar = "skip_signature"
216
-
217
- @classmethod
218
- def auto(cls) -> ABFS:
219
- account_name = os.getenv(cls._KEY_ENV_VAR_MAPPING["account_name"], None)
220
- account_key = os.getenv(cls._KEY_ENV_VAR_MAPPING["account_key"], None)
221
- tenant_id = os.getenv(cls._KEY_ENV_VAR_MAPPING["tenant_id"], None)
222
- client_id = os.getenv(cls._KEY_ENV_VAR_MAPPING["client_id"], None)
223
- client_secret = os.getenv(cls._KEY_ENV_VAR_MAPPING["client_secret"], None)
224
-
225
- kwargs: Dict[str, Any] = {}
226
- kwargs = set_if_exists(kwargs, "account_name", account_name)
227
- kwargs = set_if_exists(kwargs, "account_key", account_key)
228
- kwargs = set_if_exists(kwargs, "tenant_id", tenant_id)
229
- kwargs = set_if_exists(kwargs, "client_id", client_id)
230
- kwargs = set_if_exists(kwargs, "client_secret", client_secret)
231
- return ABFS(**kwargs)
232
-
233
- def get_fsspec_kwargs(self, anonymous: bool = False, /, **kwargs) -> Dict[str, Any]:
234
- config: Dict[str, Any] = {}
235
- if "account_name" in kwargs or self.account_name:
236
- config["account_name"] = kwargs.get("account_name", self.account_name)
237
- if "account_key" in kwargs or self.account_key:
238
- config["account_key"] = kwargs.get("account_key", self.account_key)
239
- if "client_id" in kwargs or self.client_id:
240
- config["client_id"] = kwargs.get("client_id", self.client_id)
241
- if "client_secret" in kwargs or self.client_secret:
242
- config["client_secret"] = kwargs.get("client_secret", self.client_secret)
243
- if "tenant_id" in kwargs or self.tenant_id:
244
- config["tenant_id"] = kwargs.get("tenant_id", self.tenant_id)
245
-
246
- if anonymous:
247
- config[self._KEY_SKIP_SIGNATURE] = True
248
-
249
- client_options = {"timeout": "99999s", "allow_http": "true"}
250
-
251
- if config:
252
- kwargs["config"] = config
253
- kwargs["client_options"] = client_options
254
-
255
- return kwargs
256
-
257
-
258
26
  @dataclass(init=True, repr=True, eq=True, frozen=True, kw_only=True)
259
27
  class CommonInit:
260
28
  """
@@ -265,12 +33,17 @@ class CommonInit:
265
33
  org: str | None = None
266
34
  project: str | None = None
267
35
  domain: str | None = None
36
+ batch_size: int = 1000
37
+ source_config_path: Optional[Path] = None # Only used for documentation
38
+ sync_local_sys_paths: bool = True
268
39
 
269
40
 
270
41
  @dataclass(init=True, kw_only=True, repr=True, eq=True, frozen=True)
271
42
  class _InitConfig(CommonInit):
272
43
  client: Optional[ClientSet] = None
273
44
  storage: Optional[Storage] = None
45
+ image_builder: "ImageBuildEngine.ImageBuilderType" = "local"
46
+ images: typing.Dict[str, str] = field(default_factory=dict)
274
47
 
275
48
  def replace(self, **kwargs) -> _InitConfig:
276
49
  return replace(self, **kwargs)
@@ -303,11 +76,19 @@ async def _initialize_client(
303
76
  """
304
77
  from flyte.remote._client.controlplane import ClientSet
305
78
 
306
- if endpoint is not None:
79
+ # https://grpc.io/docs/guides/keepalive/#keepalive-configuration-specification
80
+ channel_options = [
81
+ ("grpc.keepalive_permit_without_calls", 1),
82
+ ("grpc.keepalive_time_ms", 30000), # Send keepalive ping every 30 seconds
83
+ ("grpc.keepalive_timeout_ms", 10000), # Wait 10 seconds for keepalive response
84
+ ("grpc.http2.max_pings_without_data", 0), # Allow unlimited pings without data
85
+ ("grpc.http2.min_ping_interval_without_data_ms", 30000), # Min 30s between pings
86
+ ]
87
+
88
+ if endpoint and api_key is None:
307
89
  return await ClientSet.for_endpoint(
308
90
  endpoint,
309
91
  insecure=insecure,
310
- api_key=api_key,
311
92
  insecure_skip_verify=insecure_skip_verify,
312
93
  auth_type=auth_type,
313
94
  headless=headless,
@@ -319,17 +100,46 @@ async def _initialize_client(
319
100
  client_config=client_config,
320
101
  rpc_retries=rpc_retries,
321
102
  http_proxy_url=http_proxy_url,
103
+ grpc_options=channel_options,
104
+ )
105
+ elif api_key:
106
+ return await ClientSet.for_api_key(
107
+ api_key,
108
+ insecure=insecure,
109
+ insecure_skip_verify=insecure_skip_verify,
110
+ auth_type=auth_type,
111
+ headless=headless,
112
+ ca_cert_file_path=ca_cert_file_path,
113
+ command=command,
114
+ proxy_command=proxy_command,
115
+ client_id=client_id,
116
+ client_credentials_secret=client_credentials_secret,
117
+ client_config=client_config,
118
+ rpc_retries=rpc_retries,
119
+ http_proxy_url=http_proxy_url,
120
+ grpc_options=channel_options,
322
121
  )
323
- raise NotImplementedError("Currently only endpoints are supported.")
324
122
 
123
+ raise InitializationError(
124
+ "MissingEndpointOrApiKeyError", "user", "Either endpoint or api_key must be provided to initialize the client."
125
+ )
325
126
 
326
- @syncer.wrap
127
+
128
+ def _initialize_logger(
129
+ log_level: int | None = None, log_format: LogFormat | None = None, reset_root_logger: bool = False
130
+ ) -> None:
131
+ initialize_logger(log_level=log_level, log_format=log_format, enable_rich=True, reset_root_logger=reset_root_logger)
132
+
133
+
134
+ @syncify
327
135
  async def init(
328
136
  org: str | None = None,
329
137
  project: str | None = None,
330
138
  domain: str | None = None,
331
139
  root_dir: Path | None = None,
332
140
  log_level: int | None = None,
141
+ log_format: LogFormat | None = None,
142
+ reset_root_logger: bool = False,
333
143
  endpoint: str | None = None,
334
144
  headless: bool = False,
335
145
  insecure: bool = False,
@@ -345,6 +155,12 @@ async def init(
345
155
  rpc_retries: int = 3,
346
156
  http_proxy_url: str | None = None,
347
157
  storage: Storage | None = None,
158
+ batch_size: int = 1000,
159
+ image_builder: ImageBuildEngine.ImageBuilderType = "local",
160
+ images: typing.Dict[str, str] | None = None,
161
+ source_config_path: Optional[Path] = None,
162
+ sync_local_sys_paths: bool = True,
163
+ load_plugin_type_transformers: bool = True,
348
164
  ) -> None:
349
165
  """
350
166
  Initialize the Flyte system with the given configuration. This method should be called before any other Flyte
@@ -353,14 +169,15 @@ async def init(
353
169
  :param project: Optional project name (not used in this implementation)
354
170
  :param domain: Optional domain name (not used in this implementation)
355
171
  :param root_dir: Optional root directory from which to determine how to load files, and find paths to files.
172
+ This is useful for determining the root directory for the current project, and for locating files like config etc.
173
+ also use to determine all the code that needs to be copied to the remote location.
356
174
  defaults to the editable install directory if the cwd is in a Python editable install, else just the cwd.
357
175
  :param log_level: Optional logging level for the logger, default is set using the default initialization policies
176
+ :param log_format: Optional logging format for the logger, default is "console"
177
+ :param reset_root_logger: By default, we clear out root logger handlers and set up our own.
358
178
  :param api_key: Optional API key for authentication
359
179
  :param endpoint: Optional API endpoint URL
360
180
  :param headless: Optional Whether to run in headless mode
361
- :param mode: Optional execution model (local, remote). Default is local. When local is used,
362
- the execution will be done locally. When remote is used, the execution will be sent to a remote server,
363
- In the remote case, the endpoint or api_key must be set.
364
181
  :param insecure_skip_verify: Whether to skip SSL certificate verification
365
182
  :param auth_client_config: Optional client configuration for authentication
366
183
  :param auth_type: The authentication type to use (Pkce, ClientSecret, ExternalCommand, DeviceFlow)
@@ -374,23 +191,31 @@ async def init(
374
191
  :param ca_cert_file_path: [optional] str Root Cert to be loaded and used to verify admin
375
192
  :param http_proxy_url: [optional] HTTP Proxy to be used for OAuth requests
376
193
  :param rpc_retries: [optional] int Number of times to retry the platform calls
377
- :param audience: oauth2 audience for the token request. This is used to validate the token
378
194
  :param insecure: insecure flag for the client
379
195
  :param storage: Optional blob store (S3, GCS, Azure) configuration if needed to access (i.e. using Minio)
380
196
  :param org: Optional organization override for the client. Should be set by auth instead.
381
-
197
+ :param batch_size: Optional batch size for operations that use listings, defaults to 1000, so limit larger than
198
+ batch_size will be split into multiple requests.
199
+ :param image_builder: Optional image builder configuration, if not provided, the default image builder will be used.
200
+ :param images: Optional dict of images that can be used by referencing the image name.
201
+ :param source_config_path: Optional path to the source configuration file (This is only used for documentation)
202
+ :param sync_local_sys_paths: Whether to include and synchronize local sys.path entries under the root directory
203
+ into the remote container (default: True).
204
+ :param load_plugin_type_transformers: If enabled (default True), load the type transformer plugins registered under
205
+ the "flyte.plugins.types" entry point group.
382
206
  :return: None
383
207
  """
384
- from flyte._utils import get_cwd_editable_install
208
+ from flyte._utils import get_cwd_editable_install, org_from_endpoint, sanitize_endpoint
209
+ from flyte.types import _load_custom_type_transformers
385
210
 
386
- interactive_mode = ipython_check()
387
-
388
- initialize_logger(enable_rich=interactive_mode)
389
- if log_level:
390
- initialize_logger(log_level=log_level, enable_rich=interactive_mode)
211
+ _initialize_logger(log_level=log_level, log_format=log_format, reset_root_logger=reset_root_logger)
212
+ if load_plugin_type_transformers:
213
+ _load_custom_type_transformers()
391
214
 
392
215
  global _init_config # noqa: PLW0603
393
216
 
217
+ endpoint = sanitize_endpoint(endpoint)
218
+
394
219
  with _init_lock:
395
220
  client = None
396
221
  if endpoint or api_key:
@@ -411,17 +236,293 @@ async def init(
411
236
  http_proxy_url=http_proxy_url,
412
237
  )
413
238
 
414
- root_dir = root_dir or get_cwd_editable_install() or Path.cwd()
239
+ if not root_dir:
240
+ editable_root = get_cwd_editable_install()
241
+ if editable_root:
242
+ logger.info(f"Using editable install as root directory: {editable_root}")
243
+ root_dir = editable_root
244
+ else:
245
+ logger.info("No editable install found, using current working directory as root directory.")
246
+ root_dir = Path.cwd()
247
+ # We will inject the root_dir into the sys,path for module resolution
248
+ sys.path.append(str(root_dir))
249
+
415
250
  _init_config = _InitConfig(
416
251
  root_dir=root_dir,
417
252
  project=project,
418
253
  domain=domain,
419
254
  client=client,
420
255
  storage=storage,
421
- org=org,
256
+ org=org or org_from_endpoint(endpoint),
257
+ batch_size=batch_size,
258
+ image_builder=image_builder,
259
+ images=images or {},
260
+ source_config_path=source_config_path,
261
+ sync_local_sys_paths=sync_local_sys_paths,
422
262
  )
423
263
 
424
264
 
265
+ @syncify
266
+ async def init_from_config(
267
+ path_or_config: str | Path | Config | None = None,
268
+ root_dir: Path | None = None,
269
+ log_level: int | None = None,
270
+ log_format: LogFormat = "console",
271
+ project: str | None = None,
272
+ domain: str | None = None,
273
+ storage: Storage | None = None,
274
+ batch_size: int = 1000,
275
+ image_builder: ImageBuildEngine.ImageBuilderType | None = None,
276
+ images: tuple[str, ...] | None = None,
277
+ sync_local_sys_paths: bool = True,
278
+ ) -> None:
279
+ """
280
+ Initialize the Flyte system using a configuration file or Config object. This method should be called before any
281
+ other Flyte remote API methods are called. Thread-safe implementation.
282
+
283
+ :param path_or_config: Path to the configuration file or Config object
284
+ :param project: Project name, this will override any project names in the configuration file
285
+ :param domain: Domain name, this will override any domain names in the configuration file
286
+ :param root_dir: Optional root directory from which to determine how to load files, and find paths to
287
+ files like config etc. For example if one uses the copy-style=="all", it is essential to determine the
288
+ root directory for the current project. If not provided, it defaults to the editable install directory or
289
+ if not available, the current working directory.
290
+ :param log_level: Optional logging level for the framework logger,
291
+ default is set using the default initialization policies
292
+ :param log_format: Optional logging format for the logger, default is "console"
293
+ :param storage: Optional blob store (S3, GCS, Azure) configuration if needed to access (i.e. using Minio)
294
+ :param images: List of image strings in format "imagename=imageuri" or just "imageuri".
295
+ :param sync_local_sys_paths: Whether to include and synchronize local sys.path entries under the root directory
296
+ into the remote container (default: True).
297
+ :param batch_size: Optional batch size for operations that use listings, defaults to 1000
298
+ :param image_builder: Optional image builder configuration, if provided,
299
+ will override any defaults set in the configuration.
300
+ :return: None
301
+ """
302
+ from rich.highlighter import ReprHighlighter
303
+
304
+ import flyte.config as config
305
+ from flyte.cli._common import parse_images
306
+
307
+ cfg: config.Config
308
+ cfg_path: Optional[Path] = None
309
+ if path_or_config is None:
310
+ # If no path is provided, use the default config file
311
+ cfg = config.auto()
312
+ elif isinstance(path_or_config, (str, Path)):
313
+ if root_dir:
314
+ cfg_path = root_dir.expanduser() / path_or_config
315
+ else:
316
+ cfg_path = Path(path_or_config).expanduser()
317
+ if not Path(cfg_path).exists():
318
+ raise InitializationError(
319
+ "ConfigFileNotFoundError",
320
+ "user",
321
+ f"Configuration file '{cfg_path}' does not exist., current working directory is {Path.cwd()}",
322
+ )
323
+ cfg = config.auto(cfg_path)
324
+ else:
325
+ cfg = path_or_config
326
+
327
+ logger.info(f"Flyte config initialized as {cfg}", extra={"highlighter": ReprHighlighter()})
328
+
329
+ # parse image, this will overwrite the image_refs set in the config file
330
+ parse_images(cfg, images)
331
+
332
+ await init.aio(
333
+ org=cfg.task.org,
334
+ project=project or cfg.task.project,
335
+ domain=domain or cfg.task.domain,
336
+ endpoint=cfg.platform.endpoint,
337
+ insecure=cfg.platform.insecure,
338
+ insecure_skip_verify=cfg.platform.insecure_skip_verify,
339
+ ca_cert_file_path=cfg.platform.ca_cert_file_path,
340
+ auth_type=cfg.platform.auth_mode,
341
+ command=cfg.platform.command,
342
+ proxy_command=cfg.platform.proxy_command,
343
+ client_id=cfg.platform.client_id,
344
+ client_credentials_secret=cfg.platform.client_credentials_secret,
345
+ root_dir=root_dir,
346
+ log_level=log_level,
347
+ log_format=log_format,
348
+ image_builder=image_builder or cfg.image.builder,
349
+ batch_size=batch_size,
350
+ images=cfg.image.image_refs,
351
+ storage=storage,
352
+ source_config_path=cfg_path,
353
+ sync_local_sys_paths=sync_local_sys_paths,
354
+ )
355
+
356
+
357
+ @syncify
358
+ async def init_from_api_key(
359
+ api_key: str | None = None,
360
+ project: str | None = None,
361
+ domain: str | None = None,
362
+ root_dir: Path | None = None,
363
+ log_level: int | None = None,
364
+ log_format: LogFormat | None = None,
365
+ storage: Storage | None = None,
366
+ batch_size: int = 1000,
367
+ image_builder: ImageBuildEngine.ImageBuilderType = "local",
368
+ images: typing.Dict[str, str] | None = None,
369
+ sync_local_sys_paths: bool = True,
370
+ ) -> None:
371
+ """
372
+ Initialize the Flyte system using an API key for authentication. This is a convenience
373
+ method for API key-based authentication. Thread-safe implementation.
374
+
375
+ The API key should be an encoded API key that contains the endpoint, client ID, client secret,
376
+ and organization information. You can obtain this encoded API key from your Flyte administrator
377
+ or cloud provider.
378
+
379
+ :param api_key: Optional encoded API key for authentication. If None, reads from FLYTE_API_KEY
380
+ environment variable. The API key is a base64-encoded string containing endpoint, client_id,
381
+ client_secret, and org information.
382
+ :param project: Optional project name
383
+ :param domain: Optional domain name
384
+ :param root_dir: Optional root directory from which to determine how to load files, and find paths to files.
385
+ defaults to the editable install directory if the cwd is in a Python editable install, else just the cwd.
386
+ :param log_level: Optional logging level for the logger
387
+ :param log_format: Optional logging format for the logger, default is "console"
388
+ :param storage: Optional blob store (S3, GCS, Azure) configuration
389
+ :param batch_size: Optional batch size for operations that use listings, defaults to 1000
390
+ :param image_builder: Optional image builder configuration
391
+ :param images: Optional dict of images that can be used by referencing the image name
392
+ :param sync_local_sys_paths: Whether to include and synchronize local sys.path entries under the root directory
393
+ into the remote container (default: True)
394
+ :return: None
395
+ """
396
+ import os
397
+
398
+ from flyte._utils import sanitize_endpoint
399
+ from flyte.remote._client.auth._auth_utils import decode_api_key
400
+
401
+ # If api_key is not provided, read from environment variable
402
+ if api_key is None:
403
+ api_key = os.getenv("FLYTE_API_KEY")
404
+ if api_key is None:
405
+ raise InitializationError(
406
+ "MissingApiKeyError",
407
+ "user",
408
+ "API key must be provided either as a parameter or via the FLYTE_API_KEY environment variable.",
409
+ )
410
+
411
+ # Decode the API key to extract endpoint, client_id, client_secret, and org
412
+ endpoint, client_id, client_secret, org = decode_api_key(api_key)
413
+
414
+ # Sanitize the endpoint
415
+ endpoint = sanitize_endpoint(endpoint) # type: ignore[assignment]
416
+
417
+ await init.aio(
418
+ org=None if org == "None" else org,
419
+ project=project,
420
+ domain=domain,
421
+ endpoint=endpoint,
422
+ api_key=api_key,
423
+ client_id=client_id,
424
+ client_credentials_secret=client_secret,
425
+ auth_type="ClientSecret", # API keys use client credentials flow
426
+ root_dir=root_dir,
427
+ log_level=log_level,
428
+ log_format=log_format,
429
+ insecure=False,
430
+ insecure_skip_verify=False,
431
+ storage=storage,
432
+ batch_size=batch_size,
433
+ image_builder=image_builder,
434
+ images=images,
435
+ sync_local_sys_paths=sync_local_sys_paths,
436
+ )
437
+
438
+
439
+ @syncify
440
+ async def init_in_cluster(
441
+ org: str | None = None,
442
+ project: str | None = None,
443
+ domain: str | None = None,
444
+ api_key: str | None = None,
445
+ endpoint: str | None = None,
446
+ insecure: bool = False,
447
+ ) -> dict[str, typing.Any]:
448
+ import os
449
+
450
+ from flyte._utils import str2bool
451
+
452
+ PROJECT_NAME = "FLYTE_INTERNAL_EXECUTION_PROJECT"
453
+ DOMAIN_NAME = "FLYTE_INTERNAL_EXECUTION_DOMAIN"
454
+ ORG_NAME = "_U_ORG_NAME"
455
+ ENDPOINT_OVERRIDE = "_U_EP_OVERRIDE"
456
+ INSECURE_SKIP_VERIFY_OVERRIDE = "_U_INSECURE_SKIP_VERIFY"
457
+ INSECURE_OVERRIDE = "_U_INSECURE"
458
+ _UNION_EAGER_API_KEY_ENV_VAR = "_UNION_EAGER_API_KEY"
459
+ EAGER_API_KEY = "EAGER_API_KEY"
460
+
461
+ org = org or os.getenv(ORG_NAME)
462
+ project = project or os.getenv(PROJECT_NAME)
463
+ domain = domain or os.getenv(DOMAIN_NAME)
464
+ api_key = api_key or os.getenv(_UNION_EAGER_API_KEY_ENV_VAR) or os.getenv(EAGER_API_KEY)
465
+
466
+ remote_kwargs: dict[str, typing.Any] = {"insecure": insecure}
467
+ if api_key:
468
+ logger.info("Using api key from environment")
469
+ remote_kwargs["api_key"] = api_key
470
+ else:
471
+ ep = endpoint or os.environ.get(ENDPOINT_OVERRIDE, "host.docker.internal:8090")
472
+ remote_kwargs["endpoint"] = ep
473
+ if not insecure:
474
+ if "localhost" in ep or "docker" in ep:
475
+ remote_kwargs["insecure"] = True
476
+ if str2bool(os.getenv(INSECURE_OVERRIDE, "")):
477
+ remote_kwargs["insecure"] = True
478
+ logger.debug(f"Using controller endpoint: {ep} with kwargs: {remote_kwargs}")
479
+
480
+ # Check for insecure_skip_verify override (e.g. for self-signed certs)
481
+ insecure_skip_verify_str = os.getenv(INSECURE_SKIP_VERIFY_OVERRIDE, "")
482
+ if str2bool(insecure_skip_verify_str):
483
+ remote_kwargs["insecure_skip_verify"] = True
484
+ logger.info("SSL certificate verification disabled (insecure_skip_verify=True)")
485
+
486
+ await init.aio(
487
+ org=org, project=project, domain=domain, root_dir=Path.cwd(), image_builder="remote", **remote_kwargs
488
+ )
489
+ return remote_kwargs
490
+
491
+
492
+ @syncify
493
+ async def init_passthrough(
494
+ endpoint: str | None = None,
495
+ org: str | None = None,
496
+ project: str | None = None,
497
+ domain: str | None = None,
498
+ insecure: bool = False,
499
+ ) -> dict[str, typing.Any]:
500
+ """
501
+ Initialize the Flyte system with passthrough authentication.
502
+
503
+ This authentication mode allows you to pass custom authentication metadata
504
+ using the `flyte.remote.auth_metadata()` context manager.
505
+
506
+ :param org: Optional organization name
507
+ :param project: Optional project name
508
+ :param domain: Optional domain name
509
+ :param endpoint: Optional API endpoint URL
510
+ :param insecure: Whether to use an insecure channel
511
+ :return: Dictionary of remote kwargs used for initialization
512
+ """
513
+ await init.aio(
514
+ org=org,
515
+ project=project,
516
+ domain=domain,
517
+ root_dir=Path.cwd(),
518
+ image_builder="remote",
519
+ endpoint=endpoint,
520
+ insecure=insecure,
521
+ auth_type="Passthrough",
522
+ )
523
+ return {"endpoint": endpoint, "insecure": insecure}
524
+
525
+
425
526
  def _get_init_config() -> Optional[_InitConfig]:
426
527
  """
427
528
  Get the current initialization configuration. Thread-safe implementation.
@@ -432,7 +533,7 @@ def _get_init_config() -> Optional[_InitConfig]:
432
533
  return _init_config
433
534
 
434
535
 
435
- def get_common_config() -> CommonInit:
536
+ def get_init_config() -> _InitConfig:
436
537
  """
437
538
  Get the current initialization configuration. Thread-safe implementation.
438
539
 
@@ -441,15 +542,15 @@ def get_common_config() -> CommonInit:
441
542
  cfg = _get_init_config()
442
543
  if cfg is None:
443
544
  raise InitializationError(
444
- "StorageNotInitializedError",
545
+ "ClientNotInitializedError",
445
546
  "user",
446
- "Configuration has not been initialized. Call flyte.init() with a valid endpoint or",
447
- " api-key before using this function.",
547
+ "Configuration has not been initialized. Call flyte.init() with a valid endpoint/api-key before",
548
+ " using this function or Call flyte.init_from_config() with a valid path to the config file",
448
549
  )
449
550
  return cfg
450
551
 
451
552
 
452
- def get_storage() -> Storage:
553
+ def get_storage() -> Storage | None:
453
554
  """
454
555
  Get the current storage configuration. Thread-safe implementation.
455
556
 
@@ -460,12 +561,10 @@ def get_storage() -> Storage:
460
561
  raise InitializationError(
461
562
  "StorageNotInitializedError",
462
563
  "user",
463
- "Configuration has not been initialized. Call flyte.init() with a valid endpoint or",
464
- " api-key before using this function.",
564
+ "Configuration has not been initialized. Call flyte.init() with a valid"
565
+ " storage configuration before using this function or Call flyte.init_from_config()"
566
+ " with a valid path to the config file",
465
567
  )
466
- if cfg.storage is None:
467
- # return default local storage
468
- return typing.cast(Storage, cfg.replace(storage=Storage()).storage)
469
568
  return cfg.storage
470
569
 
471
570
 
@@ -480,8 +579,8 @@ def get_client() -> ClientSet:
480
579
  raise InitializationError(
481
580
  "ClientNotInitializedError",
482
581
  "user",
483
- "Client has not been initialized. Call flyte.init() with a valid endpoint or"
484
- " api-key before using this function.",
582
+ "Client has not been initialized. Call flyte.init() with a valid endpoint/api-key "
583
+ "before using this function or Call flyte.init_from_config() with a valid path to the config file",
485
584
  )
486
585
  return cfg.client
487
586
 
@@ -495,41 +594,31 @@ def is_initialized() -> bool:
495
594
  return _get_init_config() is not None
496
595
 
497
596
 
498
- def initialize_in_cluster(storage: Storage | None = None) -> None:
597
+ def initialize_in_cluster() -> None:
499
598
  """
500
599
  Initialize the system for in-cluster execution. This is a placeholder function and does not perform any actions.
501
600
 
502
601
  :return: None
503
602
  """
504
- init(storage=storage)
603
+ init()
505
604
 
506
605
 
507
606
  # Define a generic type variable for the decorated function
508
607
  T = TypeVar("T", bound=Callable)
509
608
 
510
609
 
511
- def requires_client(func: T) -> T:
610
+ def ensure_client():
512
611
  """
513
- Decorator that checks if the client has been initialized before executing the function.
514
- Raises InitializationError if the client is not initialized.
515
-
516
- :param func: Function to decorate
517
- :return: Decorated function that checks for initialization
612
+ Ensure that the client is initialized. If not, raise an InitializationError.
613
+ This function is used to check if the client is initialized before executing any Flyte remote API methods.
518
614
  """
519
-
520
- @functools.wraps(func)
521
- def wrapper(*args, **kwargs) -> T:
522
- init_config = _get_init_config()
523
- if init_config is None or init_config.client is None:
524
- raise InitializationError(
525
- "ClientNotInitializedError",
526
- "user",
527
- f"Function '{func.__name__}' requires client to be initialized. "
528
- f"Call flyte.init() with a valid endpoint or api-key before using this function.",
529
- )
530
- return func(*args, **kwargs)
531
-
532
- return typing.cast(T, wrapper)
615
+ if _get_init_config() is None or _get_init_config().client is None:
616
+ raise InitializationError(
617
+ "ClientNotInitializedError",
618
+ "user",
619
+ "Client has not been initialized. Call flyte.init() with a valid endpoint/api-key before using"
620
+ " this function or Call flyte.init_from_config() with a valid path to the config file",
621
+ )
533
622
 
534
623
 
535
624
  def requires_storage(func: T) -> T:
@@ -548,7 +637,8 @@ def requires_storage(func: T) -> T:
548
637
  "StorageNotInitializedError",
549
638
  "user",
550
639
  f"Function '{func.__name__}' requires storage to be initialized. "
551
- f"Call flyte.init() with a valid storage configuration before using this function.",
640
+ "Call flyte.init() with a valid storage configuration before using this function."
641
+ "or Call flyte.init_from_config() with a valid path to the config file",
552
642
  )
553
643
  return func(*args, **kwargs)
554
644
 
@@ -574,7 +664,8 @@ def requires_upload_location(func: T) -> T:
574
664
  "No upload path configured",
575
665
  "user",
576
666
  f"Function '{func.__name__}' requires client to be initialized. "
577
- f"Call flyte.init() with storage configuration before using this function.",
667
+ "Call flyte.init() with storage configuration before using this function."
668
+ "or Call flyte.init_from_config() with a valid path to the config file."
578
669
  )
579
670
  return func(*args, **kwargs)
580
671
 
@@ -596,13 +687,42 @@ def requires_initialization(func: T) -> T:
596
687
  raise InitializationError(
597
688
  "NotInitConfiguredError",
598
689
  "user",
599
- f"Function '{func.__name__}' requires initialization. Call flyte.init() before using this function.",
690
+ f"Function '{func.__name__}' requires initialization. Call flyte.init() before using this function"
691
+ " or Call flyte.init_from_config() with a valid path to the config file."
600
692
  )
601
693
  return func(*args, **kwargs)
602
694
 
603
695
  return typing.cast(T, wrapper)
604
696
 
605
697
 
698
+ def require_project_and_domain(func):
699
+ """
700
+ Decorator that ensures the current Flyte configuration defines
701
+ both 'project' and 'domain'. Raises a clear error if not found.
702
+ """
703
+
704
+ @functools.wraps(func)
705
+ def wrapper(*args, **kwargs):
706
+ cfg = get_init_config()
707
+ if cfg.project is None:
708
+ raise ValueError(
709
+ "Project must be provided to initialize the client. "
710
+ "Please set 'project' in the 'task' section of your config file, "
711
+ "or pass it directly to flyte.init(project='your-project-name')."
712
+ )
713
+
714
+ if cfg.domain is None:
715
+ raise ValueError(
716
+ "Domain must be provided to initialize the client. "
717
+ "Please set 'domain' in the 'task' section of your config file, "
718
+ "or pass it directly to flyte.init(domain='your-domain-name')."
719
+ )
720
+
721
+ return func(*args, **kwargs)
722
+
723
+ return wrapper
724
+
725
+
606
726
  async def _init_for_testing(
607
727
  project: str | None = None,
608
728
  domain: str | None = None,
@@ -632,3 +752,32 @@ def replace_client(client):
632
752
 
633
753
  with _init_lock:
634
754
  _init_config = _init_config.replace(client=client)
755
+
756
+
757
+ def current_domain() -> str:
758
+ """
759
+ Returns the current domain from Runtime environment (on the cluster) or from the initialized configuration.
760
+ This is safe to be used during `deploy`, `run` and within `task` code.
761
+
762
+ NOTE: This will not work if you deploy a task to a domain and then run it in another domain.
763
+
764
+ Raises InitializationError if the configuration is not initialized or domain is not set.
765
+ :return: The current domain
766
+ """
767
+ from ._context import ctx
768
+
769
+ tctx = ctx()
770
+ if tctx is not None:
771
+ domain = tctx.action.domain
772
+ if domain is not None:
773
+ return domain
774
+
775
+ cfg = _get_init_config()
776
+ if cfg is None or cfg.domain is None:
777
+ raise InitializationError(
778
+ "DomainNotInitializedError",
779
+ "user",
780
+ "Domain has not been initialized. Call flyte.init() with a valid domain before using this function"
781
+ " or Call flyte.init_from_config() with a valid path to the config file"
782
+ )
783
+ return cfg.domain