hatchet-sdk 0.47.0__py3-none-any.whl → 1.0.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.
Files changed (303) hide show
  1. hatchet_sdk/__init__.py +25 -16
  2. hatchet_sdk/client.py +14 -39
  3. hatchet_sdk/clients/admin.py +203 -362
  4. hatchet_sdk/clients/dispatcher/action_listener.py +106 -84
  5. hatchet_sdk/clients/dispatcher/dispatcher.py +21 -21
  6. hatchet_sdk/clients/event_ts.py +23 -10
  7. hatchet_sdk/clients/events.py +96 -99
  8. hatchet_sdk/clients/rest/__init__.py +24 -0
  9. hatchet_sdk/clients/rest/api/__init__.py +2 -0
  10. hatchet_sdk/clients/rest/api/task_api.py +2174 -0
  11. hatchet_sdk/clients/rest/api/workflow_runs_api.py +638 -106
  12. hatchet_sdk/clients/rest/api_client.py +1 -1
  13. hatchet_sdk/clients/rest/configuration.py +8 -1
  14. hatchet_sdk/clients/rest/exceptions.py +21 -0
  15. hatchet_sdk/clients/rest/models/__init__.py +22 -0
  16. hatchet_sdk/clients/rest/models/tenant.py +4 -0
  17. hatchet_sdk/clients/rest/models/tenant_version.py +37 -0
  18. hatchet_sdk/clients/rest/models/update_tenant_request.py +7 -0
  19. hatchet_sdk/clients/rest/models/v1_cancel_task_request.py +104 -0
  20. hatchet_sdk/clients/rest/models/v1_dag_children.py +102 -0
  21. hatchet_sdk/clients/rest/models/v1_replay_task_request.py +104 -0
  22. hatchet_sdk/clients/rest/models/v1_task.py +174 -0
  23. hatchet_sdk/clients/rest/models/v1_task_event.py +118 -0
  24. hatchet_sdk/clients/rest/models/v1_task_event_list.py +110 -0
  25. hatchet_sdk/clients/rest/models/v1_task_event_type.py +55 -0
  26. hatchet_sdk/clients/rest/models/v1_task_filter.py +106 -0
  27. hatchet_sdk/clients/rest/models/v1_task_point_metric.py +92 -0
  28. hatchet_sdk/clients/rest/models/v1_task_point_metrics.py +100 -0
  29. hatchet_sdk/clients/rest/models/v1_task_run_metric.py +88 -0
  30. hatchet_sdk/clients/rest/models/v1_task_run_status.py +40 -0
  31. hatchet_sdk/clients/rest/models/v1_task_status.py +40 -0
  32. hatchet_sdk/clients/rest/models/v1_task_summary.py +212 -0
  33. hatchet_sdk/clients/rest/models/v1_task_summary_list.py +110 -0
  34. hatchet_sdk/clients/rest/models/v1_workflow_run.py +171 -0
  35. hatchet_sdk/clients/rest/models/v1_workflow_run_details.py +145 -0
  36. hatchet_sdk/clients/rest/models/v1_workflow_type.py +37 -0
  37. hatchet_sdk/clients/rest/models/workflow_run_shape_item_for_workflow_run_details.py +99 -0
  38. hatchet_sdk/clients/rest/rest.py +37 -26
  39. hatchet_sdk/clients/rest/tenacity_utils.py +1 -1
  40. hatchet_sdk/clients/rest_client.py +141 -116
  41. hatchet_sdk/clients/run_event_listener.py +66 -60
  42. hatchet_sdk/clients/workflow_listener.py +75 -66
  43. hatchet_sdk/config.py +117 -0
  44. hatchet_sdk/connection.py +27 -13
  45. hatchet_sdk/context/__init__.py +0 -1
  46. hatchet_sdk/context/context.py +118 -218
  47. hatchet_sdk/features/cron.py +43 -57
  48. hatchet_sdk/features/scheduled.py +60 -74
  49. hatchet_sdk/hatchet.py +192 -195
  50. hatchet_sdk/labels.py +4 -6
  51. hatchet_sdk/metadata.py +1 -1
  52. hatchet_sdk/opentelemetry/instrumentor.py +9 -5
  53. hatchet_sdk/rate_limit.py +9 -18
  54. hatchet_sdk/token.py +13 -9
  55. hatchet_sdk/utils/aio_utils.py +0 -40
  56. hatchet_sdk/utils/proto_enums.py +54 -0
  57. hatchet_sdk/utils/typing.py +9 -1
  58. hatchet_sdk/v0/__init__.py +251 -0
  59. hatchet_sdk/v0/client.py +119 -0
  60. hatchet_sdk/v0/clients/admin.py +541 -0
  61. hatchet_sdk/v0/clients/dispatcher/action_listener.py +422 -0
  62. hatchet_sdk/v0/clients/dispatcher/dispatcher.py +204 -0
  63. hatchet_sdk/v0/clients/event_ts.py +28 -0
  64. hatchet_sdk/v0/clients/events.py +182 -0
  65. hatchet_sdk/v0/clients/rest/__init__.py +307 -0
  66. hatchet_sdk/v0/clients/rest/api/__init__.py +19 -0
  67. hatchet_sdk/v0/clients/rest/api/api_token_api.py +858 -0
  68. hatchet_sdk/v0/clients/rest/api/default_api.py +2259 -0
  69. hatchet_sdk/v0/clients/rest/api/event_api.py +2548 -0
  70. hatchet_sdk/v0/clients/rest/api/github_api.py +331 -0
  71. hatchet_sdk/v0/clients/rest/api/healthcheck_api.py +483 -0
  72. hatchet_sdk/v0/clients/rest/api/log_api.py +449 -0
  73. hatchet_sdk/v0/clients/rest/api/metadata_api.py +728 -0
  74. hatchet_sdk/v0/clients/rest/api/rate_limits_api.py +423 -0
  75. hatchet_sdk/v0/clients/rest/api/slack_api.py +577 -0
  76. hatchet_sdk/v0/clients/rest/api/sns_api.py +872 -0
  77. hatchet_sdk/v0/clients/rest/api/step_run_api.py +2202 -0
  78. hatchet_sdk/v0/clients/rest/api/tenant_api.py +4430 -0
  79. hatchet_sdk/v0/clients/rest/api/user_api.py +2888 -0
  80. hatchet_sdk/v0/clients/rest/api/worker_api.py +858 -0
  81. hatchet_sdk/v0/clients/rest/api/workflow_api.py +6312 -0
  82. hatchet_sdk/v0/clients/rest/api/workflow_run_api.py +1932 -0
  83. hatchet_sdk/v0/clients/rest/api/workflow_runs_api.py +610 -0
  84. hatchet_sdk/v0/clients/rest/api_client.py +759 -0
  85. hatchet_sdk/v0/clients/rest/api_response.py +22 -0
  86. hatchet_sdk/v0/clients/rest/configuration.py +611 -0
  87. hatchet_sdk/v0/clients/rest/exceptions.py +200 -0
  88. hatchet_sdk/v0/clients/rest/models/__init__.py +274 -0
  89. hatchet_sdk/v0/clients/rest/models/accept_invite_request.py +83 -0
  90. hatchet_sdk/v0/clients/rest/models/api_error.py +102 -0
  91. hatchet_sdk/v0/clients/rest/models/api_errors.py +100 -0
  92. hatchet_sdk/v0/clients/rest/models/api_meta.py +144 -0
  93. hatchet_sdk/v0/clients/rest/models/api_meta_auth.py +85 -0
  94. hatchet_sdk/v0/clients/rest/models/api_meta_integration.py +88 -0
  95. hatchet_sdk/v0/clients/rest/models/api_meta_posthog.py +90 -0
  96. hatchet_sdk/v0/clients/rest/models/api_resource_meta.py +98 -0
  97. hatchet_sdk/v0/clients/rest/models/api_token.py +105 -0
  98. hatchet_sdk/v0/clients/rest/models/bulk_create_event_request.py +100 -0
  99. hatchet_sdk/v0/clients/rest/models/bulk_create_event_response.py +110 -0
  100. hatchet_sdk/v0/clients/rest/models/cancel_event_request.py +85 -0
  101. hatchet_sdk/v0/clients/rest/models/cancel_step_run_request.py +83 -0
  102. hatchet_sdk/v0/clients/rest/models/concurrency_limit_strategy.py +39 -0
  103. hatchet_sdk/v0/clients/rest/models/create_api_token_request.py +92 -0
  104. hatchet_sdk/v0/clients/rest/models/create_api_token_response.py +83 -0
  105. hatchet_sdk/v0/clients/rest/models/create_cron_workflow_trigger_request.py +98 -0
  106. hatchet_sdk/v0/clients/rest/models/create_event_request.py +95 -0
  107. hatchet_sdk/v0/clients/rest/models/create_pull_request_from_step_run.py +83 -0
  108. hatchet_sdk/v0/clients/rest/models/create_sns_integration_request.py +85 -0
  109. hatchet_sdk/v0/clients/rest/models/create_tenant_alert_email_group_request.py +83 -0
  110. hatchet_sdk/v0/clients/rest/models/create_tenant_invite_request.py +86 -0
  111. hatchet_sdk/v0/clients/rest/models/create_tenant_request.py +84 -0
  112. hatchet_sdk/v0/clients/rest/models/cron_workflows.py +131 -0
  113. hatchet_sdk/v0/clients/rest/models/cron_workflows_list.py +110 -0
  114. hatchet_sdk/v0/clients/rest/models/cron_workflows_method.py +37 -0
  115. hatchet_sdk/v0/clients/rest/models/cron_workflows_order_by_field.py +37 -0
  116. hatchet_sdk/v0/clients/rest/models/event.py +143 -0
  117. hatchet_sdk/v0/clients/rest/models/event_data.py +83 -0
  118. hatchet_sdk/v0/clients/rest/models/event_key_list.py +98 -0
  119. hatchet_sdk/v0/clients/rest/models/event_list.py +110 -0
  120. hatchet_sdk/v0/clients/rest/models/event_order_by_direction.py +37 -0
  121. hatchet_sdk/v0/clients/rest/models/event_order_by_field.py +36 -0
  122. hatchet_sdk/v0/clients/rest/models/event_update_cancel200_response.py +85 -0
  123. hatchet_sdk/v0/clients/rest/models/event_workflow_run_summary.py +116 -0
  124. hatchet_sdk/v0/clients/rest/models/events.py +110 -0
  125. hatchet_sdk/v0/clients/rest/models/get_step_run_diff_response.py +100 -0
  126. hatchet_sdk/v0/clients/rest/models/github_app_installation.py +107 -0
  127. hatchet_sdk/v0/clients/rest/models/github_branch.py +86 -0
  128. hatchet_sdk/v0/clients/rest/models/github_repo.py +86 -0
  129. hatchet_sdk/v0/clients/rest/models/info_get_version200_response.py +83 -0
  130. hatchet_sdk/v0/clients/rest/models/job.py +132 -0
  131. hatchet_sdk/v0/clients/rest/models/job_run.py +176 -0
  132. hatchet_sdk/v0/clients/rest/models/job_run_status.py +41 -0
  133. hatchet_sdk/v0/clients/rest/models/link_github_repository_request.py +106 -0
  134. hatchet_sdk/v0/clients/rest/models/list_api_tokens_response.py +110 -0
  135. hatchet_sdk/v0/clients/rest/models/list_github_app_installations_response.py +112 -0
  136. hatchet_sdk/v0/clients/rest/models/list_pull_requests_response.py +100 -0
  137. hatchet_sdk/v0/clients/rest/models/list_slack_webhooks.py +110 -0
  138. hatchet_sdk/v0/clients/rest/models/list_sns_integrations.py +110 -0
  139. hatchet_sdk/v0/clients/rest/models/log_line.py +94 -0
  140. hatchet_sdk/v0/clients/rest/models/log_line_level.py +39 -0
  141. hatchet_sdk/v0/clients/rest/models/log_line_list.py +110 -0
  142. hatchet_sdk/v0/clients/rest/models/log_line_order_by_direction.py +37 -0
  143. hatchet_sdk/v0/clients/rest/models/log_line_order_by_field.py +36 -0
  144. hatchet_sdk/v0/clients/rest/models/pagination_response.py +95 -0
  145. hatchet_sdk/v0/clients/rest/models/pull_request.py +112 -0
  146. hatchet_sdk/v0/clients/rest/models/pull_request_state.py +37 -0
  147. hatchet_sdk/v0/clients/rest/models/queue_metrics.py +97 -0
  148. hatchet_sdk/v0/clients/rest/models/rate_limit.py +117 -0
  149. hatchet_sdk/v0/clients/rest/models/rate_limit_list.py +110 -0
  150. hatchet_sdk/v0/clients/rest/models/rate_limit_order_by_direction.py +37 -0
  151. hatchet_sdk/v0/clients/rest/models/rate_limit_order_by_field.py +38 -0
  152. hatchet_sdk/v0/clients/rest/models/recent_step_runs.py +118 -0
  153. hatchet_sdk/v0/clients/rest/models/reject_invite_request.py +83 -0
  154. hatchet_sdk/v0/clients/rest/models/replay_event_request.py +85 -0
  155. hatchet_sdk/v0/clients/rest/models/replay_workflow_runs_request.py +85 -0
  156. hatchet_sdk/v0/clients/rest/models/replay_workflow_runs_response.py +100 -0
  157. hatchet_sdk/v0/clients/rest/models/rerun_step_run_request.py +83 -0
  158. hatchet_sdk/v0/clients/rest/models/schedule_workflow_run_request.py +92 -0
  159. hatchet_sdk/v0/clients/rest/models/scheduled_run_status.py +42 -0
  160. hatchet_sdk/v0/clients/rest/models/scheduled_workflows.py +149 -0
  161. hatchet_sdk/v0/clients/rest/models/scheduled_workflows_list.py +110 -0
  162. hatchet_sdk/v0/clients/rest/models/scheduled_workflows_method.py +37 -0
  163. hatchet_sdk/v0/clients/rest/models/scheduled_workflows_order_by_field.py +37 -0
  164. hatchet_sdk/v0/clients/rest/models/semaphore_slots.py +113 -0
  165. hatchet_sdk/v0/clients/rest/models/slack_webhook.py +127 -0
  166. hatchet_sdk/v0/clients/rest/models/sns_integration.py +114 -0
  167. hatchet_sdk/v0/clients/rest/models/step.py +123 -0
  168. hatchet_sdk/v0/clients/rest/models/step_run.py +202 -0
  169. hatchet_sdk/v0/clients/rest/models/step_run_archive.py +142 -0
  170. hatchet_sdk/v0/clients/rest/models/step_run_archive_list.py +110 -0
  171. hatchet_sdk/v0/clients/rest/models/step_run_diff.py +91 -0
  172. hatchet_sdk/v0/clients/rest/models/step_run_event.py +122 -0
  173. hatchet_sdk/v0/clients/rest/models/step_run_event_list.py +110 -0
  174. hatchet_sdk/v0/clients/rest/models/step_run_event_reason.py +52 -0
  175. hatchet_sdk/v0/clients/rest/models/step_run_event_severity.py +38 -0
  176. hatchet_sdk/v0/clients/rest/models/step_run_status.py +44 -0
  177. hatchet_sdk/v0/clients/rest/models/tenant.py +118 -0
  178. hatchet_sdk/v0/clients/rest/models/tenant_alert_email_group.py +98 -0
  179. hatchet_sdk/v0/clients/rest/models/tenant_alert_email_group_list.py +112 -0
  180. hatchet_sdk/v0/clients/rest/models/tenant_alerting_settings.py +143 -0
  181. hatchet_sdk/v0/clients/rest/models/tenant_invite.py +120 -0
  182. hatchet_sdk/v0/clients/rest/models/tenant_invite_list.py +110 -0
  183. hatchet_sdk/v0/clients/rest/models/tenant_list.py +110 -0
  184. hatchet_sdk/v0/clients/rest/models/tenant_member.py +123 -0
  185. hatchet_sdk/v0/clients/rest/models/tenant_member_list.py +110 -0
  186. hatchet_sdk/v0/clients/rest/models/tenant_member_role.py +38 -0
  187. hatchet_sdk/v0/clients/rest/models/tenant_queue_metrics.py +116 -0
  188. hatchet_sdk/v0/clients/rest/models/tenant_resource.py +40 -0
  189. hatchet_sdk/v0/clients/rest/models/tenant_resource_limit.py +135 -0
  190. hatchet_sdk/v0/clients/rest/models/tenant_resource_policy.py +102 -0
  191. hatchet_sdk/v0/clients/rest/models/tenant_step_run_queue_metrics.py +83 -0
  192. hatchet_sdk/v0/clients/rest/models/trigger_workflow_run_request.py +91 -0
  193. hatchet_sdk/v0/clients/rest/models/update_tenant_alert_email_group_request.py +83 -0
  194. hatchet_sdk/v0/clients/rest/models/update_tenant_invite_request.py +85 -0
  195. hatchet_sdk/v0/clients/rest/models/update_tenant_request.py +137 -0
  196. hatchet_sdk/v0/clients/rest/models/update_worker_request.py +87 -0
  197. hatchet_sdk/v0/clients/rest/models/user.py +126 -0
  198. hatchet_sdk/v0/clients/rest/models/user_change_password_request.py +88 -0
  199. hatchet_sdk/v0/clients/rest/models/user_login_request.py +86 -0
  200. hatchet_sdk/v0/clients/rest/models/user_register_request.py +91 -0
  201. hatchet_sdk/v0/clients/rest/models/user_tenant_memberships_list.py +110 -0
  202. hatchet_sdk/v0/clients/rest/models/user_tenant_public.py +86 -0
  203. hatchet_sdk/v0/clients/rest/models/webhook_worker.py +100 -0
  204. hatchet_sdk/v0/clients/rest/models/webhook_worker_create_request.py +94 -0
  205. hatchet_sdk/v0/clients/rest/models/webhook_worker_create_response.py +98 -0
  206. hatchet_sdk/v0/clients/rest/models/webhook_worker_created.py +102 -0
  207. hatchet_sdk/v0/clients/rest/models/webhook_worker_list_response.py +110 -0
  208. hatchet_sdk/v0/clients/rest/models/webhook_worker_request.py +102 -0
  209. hatchet_sdk/v0/clients/rest/models/webhook_worker_request_list_response.py +104 -0
  210. hatchet_sdk/v0/clients/rest/models/webhook_worker_request_method.py +38 -0
  211. hatchet_sdk/v0/clients/rest/models/worker.py +239 -0
  212. hatchet_sdk/v0/clients/rest/models/worker_label.py +102 -0
  213. hatchet_sdk/v0/clients/rest/models/worker_list.py +110 -0
  214. hatchet_sdk/v0/clients/rest/models/worker_runtime_info.py +103 -0
  215. hatchet_sdk/v0/clients/rest/models/worker_runtime_sdks.py +38 -0
  216. hatchet_sdk/v0/clients/rest/models/worker_type.py +38 -0
  217. hatchet_sdk/v0/clients/rest/models/workflow.py +165 -0
  218. hatchet_sdk/v0/clients/rest/models/workflow_concurrency.py +107 -0
  219. hatchet_sdk/v0/clients/rest/models/workflow_deployment_config.py +136 -0
  220. hatchet_sdk/v0/clients/rest/models/workflow_kind.py +38 -0
  221. hatchet_sdk/v0/clients/rest/models/workflow_list.py +120 -0
  222. hatchet_sdk/v0/clients/rest/models/workflow_metrics.py +97 -0
  223. hatchet_sdk/v0/clients/rest/models/workflow_run.py +188 -0
  224. hatchet_sdk/v0/clients/rest/models/workflow_run_cancel200_response.py +85 -0
  225. hatchet_sdk/v0/clients/rest/models/workflow_run_list.py +110 -0
  226. hatchet_sdk/v0/clients/rest/models/workflow_run_order_by_direction.py +37 -0
  227. hatchet_sdk/v0/clients/rest/models/workflow_run_order_by_field.py +39 -0
  228. hatchet_sdk/v0/clients/rest/models/workflow_run_shape.py +186 -0
  229. hatchet_sdk/v0/clients/rest/models/workflow_run_status.py +42 -0
  230. hatchet_sdk/v0/clients/rest/models/workflow_run_triggered_by.py +112 -0
  231. hatchet_sdk/v0/clients/rest/models/workflow_runs_cancel_request.py +85 -0
  232. hatchet_sdk/v0/clients/rest/models/workflow_runs_metrics.py +94 -0
  233. hatchet_sdk/v0/clients/rest/models/workflow_runs_metrics_counts.py +104 -0
  234. hatchet_sdk/v0/clients/rest/models/workflow_tag.py +84 -0
  235. hatchet_sdk/v0/clients/rest/models/workflow_trigger_cron_ref.py +86 -0
  236. hatchet_sdk/v0/clients/rest/models/workflow_trigger_event_ref.py +86 -0
  237. hatchet_sdk/v0/clients/rest/models/workflow_triggers.py +141 -0
  238. hatchet_sdk/v0/clients/rest/models/workflow_update_request.py +85 -0
  239. hatchet_sdk/v0/clients/rest/models/workflow_version.py +170 -0
  240. hatchet_sdk/v0/clients/rest/models/workflow_version_concurrency.py +114 -0
  241. hatchet_sdk/v0/clients/rest/models/workflow_version_definition.py +85 -0
  242. hatchet_sdk/v0/clients/rest/models/workflow_version_meta.py +123 -0
  243. hatchet_sdk/v0/clients/rest/models/workflow_workers_count.py +95 -0
  244. hatchet_sdk/v0/clients/rest/rest.py +187 -0
  245. hatchet_sdk/v0/clients/rest/tenacity_utils.py +39 -0
  246. hatchet_sdk/v0/clients/rest_client.py +613 -0
  247. hatchet_sdk/v0/clients/run_event_listener.py +260 -0
  248. hatchet_sdk/v0/clients/workflow_listener.py +277 -0
  249. hatchet_sdk/v0/connection.py +63 -0
  250. hatchet_sdk/v0/context/__init__.py +1 -0
  251. hatchet_sdk/v0/context/context.py +446 -0
  252. hatchet_sdk/v0/context/worker_context.py +28 -0
  253. hatchet_sdk/v0/contracts/dispatcher_pb2.py +102 -0
  254. hatchet_sdk/v0/contracts/dispatcher_pb2.pyi +387 -0
  255. hatchet_sdk/v0/contracts/dispatcher_pb2_grpc.py +621 -0
  256. hatchet_sdk/v0/contracts/events_pb2.py +46 -0
  257. hatchet_sdk/v0/contracts/events_pb2.pyi +87 -0
  258. hatchet_sdk/v0/contracts/events_pb2_grpc.py +274 -0
  259. hatchet_sdk/v0/contracts/workflows_pb2.py +80 -0
  260. hatchet_sdk/v0/contracts/workflows_pb2.pyi +312 -0
  261. hatchet_sdk/v0/contracts/workflows_pb2_grpc.py +277 -0
  262. hatchet_sdk/v0/features/cron.py +286 -0
  263. hatchet_sdk/v0/features/scheduled.py +248 -0
  264. hatchet_sdk/v0/hatchet.py +310 -0
  265. hatchet_sdk/v0/labels.py +10 -0
  266. hatchet_sdk/v0/logger.py +13 -0
  267. hatchet_sdk/v0/metadata.py +2 -0
  268. hatchet_sdk/v0/opentelemetry/instrumentor.py +396 -0
  269. hatchet_sdk/v0/rate_limit.py +126 -0
  270. hatchet_sdk/v0/semver.py +30 -0
  271. hatchet_sdk/v0/token.py +27 -0
  272. hatchet_sdk/v0/utils/aio_utils.py +137 -0
  273. hatchet_sdk/v0/utils/backoff.py +9 -0
  274. hatchet_sdk/v0/utils/typing.py +12 -0
  275. hatchet_sdk/{v2 → v0/v2}/callable.py +8 -8
  276. hatchet_sdk/{v2 → v0/v2}/concurrency.py +2 -2
  277. hatchet_sdk/{v2 → v0/v2}/hatchet.py +10 -10
  278. hatchet_sdk/v0/worker/__init__.py +1 -0
  279. hatchet_sdk/v0/worker/action_listener_process.py +278 -0
  280. hatchet_sdk/v0/worker/runner/run_loop_manager.py +112 -0
  281. hatchet_sdk/v0/worker/runner/runner.py +460 -0
  282. hatchet_sdk/v0/worker/runner/utils/capture_logs.py +81 -0
  283. hatchet_sdk/v0/worker/runner/utils/error_with_traceback.py +6 -0
  284. hatchet_sdk/v0/worker/worker.py +391 -0
  285. hatchet_sdk/v0/workflow.py +261 -0
  286. hatchet_sdk/v0/workflow_run.py +59 -0
  287. hatchet_sdk/worker/__init__.py +0 -1
  288. hatchet_sdk/worker/action_listener_process.py +36 -33
  289. hatchet_sdk/worker/runner/run_loop_manager.py +18 -16
  290. hatchet_sdk/worker/runner/runner.py +32 -60
  291. hatchet_sdk/worker/runner/utils/capture_logs.py +25 -14
  292. hatchet_sdk/worker/runner/utils/error_with_traceback.py +1 -1
  293. hatchet_sdk/worker/worker.py +61 -75
  294. hatchet_sdk/workflow.py +473 -207
  295. hatchet_sdk/workflow_run.py +5 -18
  296. {hatchet_sdk-0.47.0.dist-info → hatchet_sdk-1.0.0.dist-info}/METADATA +2 -1
  297. hatchet_sdk-1.0.0.dist-info/RECORD +485 -0
  298. hatchet_sdk/utils/serialization.py +0 -18
  299. hatchet_sdk-0.47.0.dist-info/RECORD +0 -237
  300. /hatchet_sdk/{loader.py → v0/loader.py} +0 -0
  301. /hatchet_sdk/{utils → v0/utils}/types.py +0 -0
  302. {hatchet_sdk-0.47.0.dist-info → hatchet_sdk-1.0.0.dist-info}/WHEEL +0 -0
  303. {hatchet_sdk-0.47.0.dist-info → hatchet_sdk-1.0.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,396 @@
1
+ from importlib.metadata import version
2
+ from typing import Any, Callable, Collection, Coroutine
3
+
4
+ try:
5
+ from opentelemetry.context import Context
6
+ from opentelemetry.instrumentation.instrumentor import ( # type: ignore[attr-defined]
7
+ BaseInstrumentor,
8
+ )
9
+ from opentelemetry.instrumentation.utils import unwrap
10
+ from opentelemetry.metrics import MeterProvider, NoOpMeterProvider, get_meter
11
+ from opentelemetry.trace import (
12
+ NoOpTracerProvider,
13
+ StatusCode,
14
+ TracerProvider,
15
+ get_tracer,
16
+ get_tracer_provider,
17
+ )
18
+ from opentelemetry.trace.propagation.tracecontext import (
19
+ TraceContextTextMapPropagator,
20
+ )
21
+ from wrapt import wrap_function_wrapper # type: ignore[import-untyped]
22
+ except (RuntimeError, ImportError, ModuleNotFoundError):
23
+ raise ModuleNotFoundError(
24
+ "To use the HatchetInstrumentor, you must install Hatchet's `otel` extra using (e.g.) `pip install hatchet-sdk[otel]`"
25
+ )
26
+
27
+ import hatchet_sdk
28
+ from hatchet_sdk.v0.clients.admin import (
29
+ AdminClient,
30
+ TriggerWorkflowOptions,
31
+ WorkflowRunDict,
32
+ )
33
+ from hatchet_sdk.v0.clients.dispatcher.action_listener import Action
34
+ from hatchet_sdk.v0.clients.events import (
35
+ BulkPushEventWithMetadata,
36
+ EventClient,
37
+ PushEventOptions,
38
+ )
39
+ from hatchet_sdk.v0.contracts.events_pb2 import Event
40
+ from hatchet_sdk.v0.worker.runner.runner import Runner
41
+ from hatchet_sdk.v0.workflow_run import WorkflowRunRef
42
+
43
+ hatchet_sdk_version = version("hatchet-sdk")
44
+
45
+ InstrumentKwargs = TracerProvider | MeterProvider | None
46
+
47
+ OTEL_TRACEPARENT_KEY = "traceparent"
48
+
49
+
50
+ def create_traceparent() -> str | None:
51
+ """
52
+ Creates and returns a W3C traceparent header value using OpenTelemetry's context propagation.
53
+
54
+ The traceparent header is used to propagate context information across service boundaries
55
+ in distributed tracing systems. It follows the W3C Trace Context specification.
56
+
57
+ :returns: A W3C-formatted traceparent header value if successful, None if the context
58
+ injection fails or no active span exists.\n
59
+ Example: `00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01`
60
+ :rtype: str | None:
61
+ """
62
+
63
+ carrier: dict[str, str] = {}
64
+ TraceContextTextMapPropagator().inject(carrier)
65
+
66
+ return carrier.get("traceparent")
67
+
68
+
69
+ def parse_carrier_from_metadata(metadata: dict[str, str] | None) -> Context | None:
70
+ """
71
+ Parses OpenTelemetry trace context from a metadata dictionary.
72
+
73
+ Extracts the trace context from metadata using the W3C Trace Context format,
74
+ specifically looking for the `traceparent` header.
75
+
76
+ :param metadata: A dictionary containing metadata key-value pairs,
77
+ potentially including the `traceparent` header. Can be None.
78
+ :type metadata: dict[str, str] | None
79
+ :returns: The extracted OpenTelemetry Context object if a valid `traceparent`
80
+ is found in the metadata, otherwise None.
81
+ :rtype: Context | None
82
+
83
+ :Example:
84
+
85
+ >>> metadata = {"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"}
86
+ >>> context = parse_carrier_from_metadata(metadata)
87
+ """
88
+
89
+ if not metadata:
90
+ return None
91
+
92
+ traceparent = metadata.get(OTEL_TRACEPARENT_KEY)
93
+
94
+ if not traceparent:
95
+ return None
96
+
97
+ return TraceContextTextMapPropagator().extract({OTEL_TRACEPARENT_KEY: traceparent})
98
+
99
+
100
+ def inject_traceparent_into_metadata(
101
+ metadata: dict[str, str], traceparent: str | None = None
102
+ ) -> dict[str, str]:
103
+ """
104
+ Injects OpenTelemetry `traceparent` into a metadata dictionary.
105
+
106
+ Takes a metadata dictionary and an optional `traceparent` string,
107
+ returning a new metadata dictionary with the `traceparent` added under the
108
+ `OTEL_TRACEPARENT_KEY`. If no `traceparent` is provided, it attempts to create one.
109
+
110
+ :param metadata: The metadata dictionary to inject the `traceparent` into.
111
+ :type metadata: dict[str, str]
112
+ :param traceparent: The `traceparent` string to inject. If None, attempts to use
113
+ the current span.
114
+ :type traceparent: str | None, optional
115
+ :returns: A new metadata dictionary containing the original metadata plus
116
+ the injected `traceparent`, if one was available or could be created.
117
+ :rtype: dict[str, str]
118
+
119
+ :Example:
120
+
121
+ >>> metadata = {"key": "value"}
122
+ >>> new_metadata = inject_traceparent(metadata, "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01")
123
+ >>> print(new_metadata)
124
+ {"key": "value", "traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"}
125
+ """
126
+
127
+ if not traceparent:
128
+ traceparent = create_traceparent()
129
+
130
+ if not traceparent:
131
+ return metadata
132
+
133
+ return {
134
+ **metadata,
135
+ OTEL_TRACEPARENT_KEY: traceparent,
136
+ }
137
+
138
+
139
+ class HatchetInstrumentor(BaseInstrumentor): # type: ignore[misc]
140
+ def __init__(
141
+ self,
142
+ tracer_provider: TracerProvider | None = None,
143
+ meter_provider: MeterProvider | None = None,
144
+ ):
145
+ """
146
+ Hatchet OpenTelemetry instrumentor.
147
+
148
+ The instrumentor provides an OpenTelemetry integration for Hatchet by setting up
149
+ tracing and metrics collection.
150
+
151
+ :param tracer_provider: TracerProvider | None: The OpenTelemetry TracerProvider to use.
152
+ If not provided, the global tracer provider will be used.
153
+ :param meter_provider: MeterProvider | None: The OpenTelemetry MeterProvider to use.
154
+ If not provided, a no-op meter provider will be used.
155
+ """
156
+
157
+ self.tracer_provider = tracer_provider or get_tracer_provider()
158
+ self.meter_provider = meter_provider or NoOpMeterProvider()
159
+
160
+ super().__init__()
161
+
162
+ def instrumentation_dependencies(self) -> Collection[str]:
163
+ return tuple()
164
+
165
+ def _instrument(self, **kwargs: InstrumentKwargs) -> None:
166
+ self._tracer = get_tracer(__name__, hatchet_sdk_version, self.tracer_provider)
167
+ self._meter = get_meter(__name__, hatchet_sdk_version, self.meter_provider)
168
+
169
+ wrap_function_wrapper(
170
+ hatchet_sdk,
171
+ "worker.runner.runner.Runner.handle_start_step_run",
172
+ self._wrap_handle_start_step_run,
173
+ )
174
+ wrap_function_wrapper(
175
+ hatchet_sdk,
176
+ "worker.runner.runner.Runner.handle_start_group_key_run",
177
+ self._wrap_handle_get_group_key_run,
178
+ )
179
+ wrap_function_wrapper(
180
+ hatchet_sdk,
181
+ "worker.runner.runner.Runner.handle_cancel_action",
182
+ self._wrap_handle_cancel_action,
183
+ )
184
+
185
+ wrap_function_wrapper(
186
+ hatchet_sdk,
187
+ "clients.events.EventClient.push",
188
+ self._wrap_push_event,
189
+ )
190
+
191
+ wrap_function_wrapper(
192
+ hatchet_sdk,
193
+ "clients.events.EventClient.bulk_push",
194
+ self._wrap_bulk_push_event,
195
+ )
196
+
197
+ wrap_function_wrapper(
198
+ hatchet_sdk,
199
+ "clients.admin.AdminClient.run_workflow",
200
+ self._wrap_run_workflow,
201
+ )
202
+
203
+ wrap_function_wrapper(
204
+ hatchet_sdk,
205
+ "clients.admin.AdminClientAioImpl.run_workflow",
206
+ self._wrap_async_run_workflow,
207
+ )
208
+
209
+ wrap_function_wrapper(
210
+ hatchet_sdk,
211
+ "clients.admin.AdminClient.run_workflows",
212
+ self._wrap_run_workflows,
213
+ )
214
+
215
+ wrap_function_wrapper(
216
+ hatchet_sdk,
217
+ "clients.admin.AdminClientAioImpl.run_workflows",
218
+ self._wrap_async_run_workflows,
219
+ )
220
+
221
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
222
+ async def _wrap_handle_start_step_run(
223
+ self,
224
+ wrapped: Callable[[Action], Coroutine[None, None, Exception | None]],
225
+ instance: Runner,
226
+ args: tuple[Action],
227
+ kwargs: Any,
228
+ ) -> Exception | None:
229
+ action = args[0]
230
+ traceparent = parse_carrier_from_metadata(action.additional_metadata)
231
+
232
+ with self._tracer.start_as_current_span(
233
+ "hatchet.start_step_run",
234
+ attributes=action.otel_attributes,
235
+ context=traceparent,
236
+ ) as span:
237
+ result = await wrapped(*args, **kwargs)
238
+
239
+ if isinstance(result, Exception):
240
+ span.set_status(StatusCode.ERROR, str(result))
241
+
242
+ return result
243
+
244
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
245
+ async def _wrap_handle_get_group_key_run(
246
+ self,
247
+ wrapped: Callable[[Action], Coroutine[None, None, Exception | None]],
248
+ instance: Runner,
249
+ args: tuple[Action],
250
+ kwargs: Any,
251
+ ) -> Exception | None:
252
+ action = args[0]
253
+
254
+ with self._tracer.start_as_current_span(
255
+ "hatchet.get_group_key_run",
256
+ attributes=action.otel_attributes,
257
+ ) as span:
258
+ result = await wrapped(*args, **kwargs)
259
+
260
+ if isinstance(result, Exception):
261
+ span.set_status(StatusCode.ERROR, str(result))
262
+
263
+ return result
264
+
265
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
266
+ async def _wrap_handle_cancel_action(
267
+ self,
268
+ wrapped: Callable[[str], Coroutine[None, None, Exception | None]],
269
+ instance: Runner,
270
+ args: tuple[str],
271
+ kwargs: Any,
272
+ ) -> Exception | None:
273
+ step_run_id = args[0]
274
+
275
+ with self._tracer.start_as_current_span(
276
+ "hatchet.cancel_step_run",
277
+ attributes={
278
+ "hatchet.step_run_id": step_run_id,
279
+ },
280
+ ):
281
+ return await wrapped(*args, **kwargs)
282
+
283
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
284
+ def _wrap_push_event(
285
+ self,
286
+ wrapped: Callable[[str, dict[str, Any], PushEventOptions | None], Event],
287
+ instance: EventClient,
288
+ args: tuple[
289
+ str,
290
+ dict[str, Any],
291
+ PushEventOptions | None,
292
+ ],
293
+ kwargs: dict[str, str | dict[str, Any] | PushEventOptions | None],
294
+ ) -> Event:
295
+ with self._tracer.start_as_current_span(
296
+ "hatchet.push_event",
297
+ ):
298
+ return wrapped(*args, **kwargs)
299
+
300
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
301
+ def _wrap_bulk_push_event(
302
+ self,
303
+ wrapped: Callable[
304
+ [list[BulkPushEventWithMetadata], PushEventOptions | None], list[Event]
305
+ ],
306
+ instance: EventClient,
307
+ args: tuple[
308
+ list[BulkPushEventWithMetadata],
309
+ PushEventOptions | None,
310
+ ],
311
+ kwargs: dict[str, list[BulkPushEventWithMetadata] | PushEventOptions | None],
312
+ ) -> list[Event]:
313
+ with self._tracer.start_as_current_span(
314
+ "hatchet.bulk_push_event",
315
+ ):
316
+ return wrapped(*args, **kwargs)
317
+
318
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
319
+ def _wrap_run_workflow(
320
+ self,
321
+ wrapped: Callable[[str, Any, TriggerWorkflowOptions | None], WorkflowRunRef],
322
+ instance: AdminClient,
323
+ args: tuple[str, Any, TriggerWorkflowOptions | None],
324
+ kwargs: dict[str, str | Any | TriggerWorkflowOptions | None],
325
+ ) -> WorkflowRunRef:
326
+ with self._tracer.start_as_current_span(
327
+ "hatchet.run_workflow",
328
+ ):
329
+ return wrapped(*args, **kwargs)
330
+
331
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
332
+ async def _wrap_async_run_workflow(
333
+ self,
334
+ wrapped: Callable[
335
+ [str, Any, TriggerWorkflowOptions | None],
336
+ Coroutine[None, None, WorkflowRunRef],
337
+ ],
338
+ instance: AdminClient,
339
+ args: tuple[str, Any, TriggerWorkflowOptions | None],
340
+ kwargs: dict[str, str | Any | TriggerWorkflowOptions | None],
341
+ ) -> WorkflowRunRef:
342
+ with self._tracer.start_as_current_span(
343
+ "hatchet.run_workflow",
344
+ ):
345
+ return await wrapped(*args, **kwargs)
346
+
347
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
348
+ def _wrap_run_workflows(
349
+ self,
350
+ wrapped: Callable[
351
+ [list[WorkflowRunDict], TriggerWorkflowOptions | None], list[WorkflowRunRef]
352
+ ],
353
+ instance: AdminClient,
354
+ args: tuple[
355
+ list[WorkflowRunDict],
356
+ TriggerWorkflowOptions | None,
357
+ ],
358
+ kwargs: dict[str, list[WorkflowRunDict] | TriggerWorkflowOptions | None],
359
+ ) -> list[WorkflowRunRef]:
360
+ with self._tracer.start_as_current_span(
361
+ "hatchet.run_workflows",
362
+ ):
363
+ return wrapped(*args, **kwargs)
364
+
365
+ ## IMPORTANT: Keep these types in sync with the wrapped method's signature
366
+ async def _wrap_async_run_workflows(
367
+ self,
368
+ wrapped: Callable[
369
+ [list[WorkflowRunDict], TriggerWorkflowOptions | None],
370
+ Coroutine[None, None, list[WorkflowRunRef]],
371
+ ],
372
+ instance: AdminClient,
373
+ args: tuple[
374
+ list[WorkflowRunDict],
375
+ TriggerWorkflowOptions | None,
376
+ ],
377
+ kwargs: dict[str, list[WorkflowRunDict] | TriggerWorkflowOptions | None],
378
+ ) -> list[WorkflowRunRef]:
379
+ with self._tracer.start_as_current_span(
380
+ "hatchet.run_workflows",
381
+ ):
382
+ return await wrapped(*args, **kwargs)
383
+
384
+ def _uninstrument(self, **kwargs: InstrumentKwargs) -> None:
385
+ self.tracer_provider = NoOpTracerProvider()
386
+ self.meter_provider = NoOpMeterProvider()
387
+
388
+ unwrap(hatchet_sdk, "worker.runner.runner.Runner.handle_start_step_run")
389
+ unwrap(hatchet_sdk, "worker.runner.runner.Runner.handle_start_group_key_run")
390
+ unwrap(hatchet_sdk, "worker.runner.runner.Runner.handle_cancel_action")
391
+ unwrap(hatchet_sdk, "clients.events.EventClient.push")
392
+ unwrap(hatchet_sdk, "clients.events.EventClient.bulk_push")
393
+ unwrap(hatchet_sdk, "clients.admin.AdminClient.run_workflow")
394
+ unwrap(hatchet_sdk, "clients.admin.AdminClientAioImpl.run_workflow")
395
+ unwrap(hatchet_sdk, "clients.admin.AdminClient.run_workflows")
396
+ unwrap(hatchet_sdk, "clients.admin.AdminClientAioImpl.run_workflows")
@@ -0,0 +1,126 @@
1
+ from dataclasses import dataclass
2
+ from typing import Union
3
+
4
+ from celpy import CELEvalError, Environment
5
+
6
+ from hatchet_sdk.v0.contracts.workflows_pb2 import CreateStepRateLimit
7
+
8
+
9
+ def validate_cel_expression(expr: str) -> bool:
10
+ env = Environment()
11
+ try:
12
+ env.compile(expr)
13
+ return True
14
+ except CELEvalError:
15
+ return False
16
+
17
+
18
+ class RateLimitDuration:
19
+ SECOND = "SECOND"
20
+ MINUTE = "MINUTE"
21
+ HOUR = "HOUR"
22
+ DAY = "DAY"
23
+ WEEK = "WEEK"
24
+ MONTH = "MONTH"
25
+ YEAR = "YEAR"
26
+
27
+
28
+ @dataclass
29
+ class RateLimit:
30
+ """
31
+ Represents a rate limit configuration for a step in a workflow.
32
+
33
+ This class allows for both static and dynamic rate limiting based on various parameters.
34
+ It supports both simple integer values and Common Expression Language (CEL) expressions
35
+ for dynamic evaluation.
36
+
37
+ Attributes:
38
+ static_key (str, optional): A static key for rate limiting.
39
+ dynamic_key (str, optional): A CEL expression for dynamic key evaluation.
40
+ units (int or str, default=1): The number of units or a CEL expression for dynamic unit calculation.
41
+ limit (int or str, optional): The rate limit value or a CEL expression for dynamic limit calculation.
42
+ duration (str, default=RateLimitDuration.MINUTE): The window duration of the rate limit.
43
+ key (str, optional): Deprecated. Use static_key instead.
44
+
45
+ Usage:
46
+ 1. Static rate limit:
47
+ rate_limit = RateLimit(static_key="external-api", units=100)
48
+ > NOTE: if you want to use a static key, you must first put the rate limit: hatchet.admin.put_rate_limit("external-api", 200, RateLimitDuration.SECOND)
49
+
50
+ 2. Dynamic rate limit with CEL expressions:
51
+ rate_limit = RateLimit(
52
+ dynamic_key="input.user_id",
53
+ units="input.units",
54
+ limit="input.limit * input.user_tier"
55
+ )
56
+
57
+ Note:
58
+ - Either static_key or dynamic_key must be set, but not both.
59
+ - When using dynamic_key, limit must also be set.
60
+ - CEL expressions are validated upon instantiation.
61
+
62
+ Raises:
63
+ ValueError: If invalid combinations of attributes are provided or if CEL expressions are invalid.
64
+ DeprecationWarning: If the deprecated 'key' attribute is used.
65
+ """
66
+
67
+ key: Union[str, None] = None
68
+ static_key: Union[str, None] = None
69
+ dynamic_key: Union[str, None] = None
70
+ units: Union[int, str] = 1
71
+ limit: Union[int, str, None] = None
72
+ duration: RateLimitDuration = RateLimitDuration.MINUTE
73
+
74
+ _req: CreateStepRateLimit = None
75
+
76
+ def __post_init__(self):
77
+ # juggle the key and key_expr fields
78
+ key = self.static_key
79
+ key_expression = self.dynamic_key
80
+
81
+ if self.key is not None:
82
+ DeprecationWarning(
83
+ "key is deprecated and will be removed in a future release, please use static_key instead"
84
+ )
85
+ key = self.key
86
+
87
+ if key_expression is not None:
88
+ if key is not None:
89
+ raise ValueError("Cannot have both static key and dynamic key set")
90
+
91
+ key = key_expression
92
+ if not validate_cel_expression(key_expression):
93
+ raise ValueError(f"Invalid CEL expression: {key_expression}")
94
+
95
+ # juggle the units and units_expr fields
96
+ units = None
97
+ units_expression = None
98
+ if isinstance(self.units, int):
99
+ units = self.units
100
+ else:
101
+ if not validate_cel_expression(self.units):
102
+ raise ValueError(f"Invalid CEL expression: {self.units}")
103
+ units_expression = self.units
104
+
105
+ # juggle the limit and limit_expr fields
106
+ limit_expression = None
107
+
108
+ if self.limit:
109
+ if isinstance(self.limit, int):
110
+ limit_expression = f"{self.limit}"
111
+ else:
112
+ if not validate_cel_expression(self.limit):
113
+ raise ValueError(f"Invalid CEL expression: {self.limit}")
114
+ limit_expression = self.limit
115
+
116
+ if key_expression is not None and limit_expression is None:
117
+ raise ValueError("CEL based keys requires limit to be set")
118
+
119
+ self._req = CreateStepRateLimit(
120
+ key=key,
121
+ key_expr=key_expression,
122
+ units=units,
123
+ units_expr=units_expression,
124
+ limit_values_expr=limit_expression,
125
+ duration=self.duration,
126
+ )
@@ -0,0 +1,30 @@
1
+ def bump_minor_version(version: str) -> str:
2
+ """
3
+ Bumps the minor version of a semantic version string. NOTE this doesn't follow full semver,
4
+ missing the build metadata and pre-release version.
5
+
6
+ :param version: A semantic version string in the format major.minor.patch
7
+ :return: A string with the minor version bumped and patch version reset to 0
8
+ :raises ValueError: If the input is not a valid semantic version string
9
+ """
10
+ # if it starts with a v, remove it
11
+ had_v = False
12
+ if version.startswith("v"):
13
+ version = version[1:]
14
+ had_v = True
15
+
16
+ parts = version.split(".")
17
+ if len(parts) != 3:
18
+ raise ValueError(f"Invalid semantic version: {version}")
19
+
20
+ try:
21
+ major, minor, _ = map(int, parts)
22
+ except ValueError:
23
+ raise ValueError(f"Invalid semantic version: {version}")
24
+
25
+ new_minor = minor + 1
26
+ new_version = f"{major}.{new_minor}.0"
27
+
28
+ if had_v:
29
+ new_version = "v" + new_version
30
+ return new_version
@@ -0,0 +1,27 @@
1
+ import base64
2
+ import json
3
+
4
+
5
+ def get_tenant_id_from_jwt(token: str) -> str:
6
+ claims = extract_claims_from_jwt(token)
7
+
8
+ return claims.get("sub")
9
+
10
+
11
+ def get_addresses_from_jwt(token: str) -> (str, str):
12
+ claims = extract_claims_from_jwt(token)
13
+
14
+ return claims.get("server_url"), claims.get("grpc_broadcast_address")
15
+
16
+
17
+ def extract_claims_from_jwt(token: str):
18
+ parts = token.split(".")
19
+ if len(parts) != 3:
20
+ raise ValueError("Invalid token format")
21
+
22
+ claims_part = parts[1]
23
+ claims_part += "=" * ((4 - len(claims_part) % 4) % 4) # Padding for base64 decoding
24
+ claims_data = base64.urlsafe_b64decode(claims_part)
25
+ claims = json.loads(claims_data)
26
+
27
+ return claims