hatchet-sdk 1.2.2__py3-none-any.whl → 1.2.4__py3-none-any.whl

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

Potentially problematic release.


This version of hatchet-sdk might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  import asyncio
2
2
  import json
3
3
  from datetime import datetime
4
- from typing import Union, cast
4
+ from typing import Generator, TypeVar, Union, cast
5
5
 
6
6
  import grpc
7
7
  from google.protobuf import timestamp_pb2
@@ -27,6 +27,10 @@ from hatchet_sdk.utils.proto_enums import convert_python_enum_to_proto
27
27
  from hatchet_sdk.utils.typing import JSONSerializableMapping
28
28
  from hatchet_sdk.workflow_run import WorkflowRunRef
29
29
 
30
+ T = TypeVar("T")
31
+
32
+ MAX_BULK_WORKFLOW_RUN_BATCH_SIZE = 1000
33
+
30
34
 
31
35
  class ScheduleTriggerWorkflowOptions(BaseModel):
32
36
  parent_id: str | None = None
@@ -328,9 +332,6 @@ class AdminClient:
328
332
  input: JSONSerializableMapping,
329
333
  options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
330
334
  ) -> WorkflowRunRef:
331
- ## IMPORTANT: The `pooled_workflow_listener` must be created 1) lazily, and not at `init` time, and 2) on the
332
- ## main thread. If 1) is not followed, you'll get an error about something being attached to the wrong event
333
- ## loop. If 2) is not followed, you'll get an error about the event loop not being set up.
334
335
  async with spawn_index_lock:
335
336
  request = self._create_workflow_run_request(workflow_name, input, options)
336
337
 
@@ -353,70 +354,90 @@ class AdminClient:
353
354
  config=self.config,
354
355
  )
355
356
 
357
+ def chunk(self, xs: list[T], n: int) -> Generator[list[T], None, None]:
358
+ for i in range(0, len(xs), n):
359
+ yield xs[i : i + n]
360
+
356
361
  ## IMPORTANT: Keep this method's signature in sync with the wrapper in the OTel instrumentor
357
362
  @tenacity_retry
358
363
  def run_workflows(
359
364
  self,
360
365
  workflows: list[WorkflowRunTriggerConfig],
361
366
  ) -> list[WorkflowRunRef]:
362
- bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
363
- workflows=[
364
- self._create_workflow_run_request(
365
- workflow.workflow_name, workflow.input, workflow.options
366
- )
367
- for workflow in workflows
368
- ]
369
- )
367
+ bulk_workflows = [
368
+ self._create_workflow_run_request(
369
+ workflow.workflow_name, workflow.input, workflow.options
370
+ )
371
+ for workflow in workflows
372
+ ]
370
373
 
371
- resp = cast(
372
- v0_workflow_protos.BulkTriggerWorkflowResponse,
373
- self.v0_client.BulkTriggerWorkflow(
374
- bulk_request,
375
- metadata=get_metadata(self.token),
376
- ),
377
- )
374
+ refs: list[WorkflowRunRef] = []
378
375
 
379
- return [
380
- WorkflowRunRef(
381
- workflow_run_id=workflow_run_id,
382
- config=self.config,
376
+ for chunk in self.chunk(bulk_workflows, MAX_BULK_WORKFLOW_RUN_BATCH_SIZE):
377
+ bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
378
+ workflows=chunk
383
379
  )
384
- for workflow_run_id in resp.workflow_run_ids
385
- ]
380
+
381
+ resp = cast(
382
+ v0_workflow_protos.BulkTriggerWorkflowResponse,
383
+ self.v0_client.BulkTriggerWorkflow(
384
+ bulk_request,
385
+ metadata=get_metadata(self.token),
386
+ ),
387
+ )
388
+
389
+ refs.extend(
390
+ [
391
+ WorkflowRunRef(
392
+ workflow_run_id=workflow_run_id,
393
+ config=self.config,
394
+ )
395
+ for workflow_run_id in resp.workflow_run_ids
396
+ ]
397
+ )
398
+
399
+ return refs
386
400
 
387
401
  @tenacity_retry
388
402
  async def aio_run_workflows(
389
403
  self,
390
404
  workflows: list[WorkflowRunTriggerConfig],
391
405
  ) -> list[WorkflowRunRef]:
392
- ## IMPORTANT: The `pooled_workflow_listener` must be created 1) lazily, and not at `init` time, and 2) on the
393
- ## main thread. If 1) is not followed, you'll get an error about something being attached to the wrong event
394
- ## loop. If 2) is not followed, you'll get an error about the event loop not being set up.
395
- async with spawn_index_lock:
396
- bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
397
- workflows=[
406
+ chunks = self.chunk(workflows, MAX_BULK_WORKFLOW_RUN_BATCH_SIZE)
407
+ refs: list[WorkflowRunRef] = []
408
+
409
+ for chunk in chunks:
410
+ async with spawn_index_lock:
411
+ bulk_workflows = [
398
412
  self._create_workflow_run_request(
399
413
  workflow.workflow_name, workflow.input, workflow.options
400
414
  )
401
- for workflow in workflows
415
+ for workflow in chunk
402
416
  ]
417
+
418
+ bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
419
+ workflows=bulk_workflows
403
420
  )
404
421
 
405
- resp = cast(
406
- v0_workflow_protos.BulkTriggerWorkflowResponse,
407
- self.v0_client.BulkTriggerWorkflow(
408
- bulk_request,
409
- metadata=get_metadata(self.token),
410
- ),
411
- )
422
+ resp = cast(
423
+ v0_workflow_protos.BulkTriggerWorkflowResponse,
424
+ self.v0_client.BulkTriggerWorkflow(
425
+ bulk_request,
426
+ metadata=get_metadata(self.token),
427
+ ),
428
+ )
412
429
 
413
- return [
414
- WorkflowRunRef(
415
- workflow_run_id=workflow_run_id,
416
- config=self.config,
430
+ refs.extend(
431
+ [
432
+ WorkflowRunRef(
433
+ workflow_run_id=workflow_run_id,
434
+ config=self.config,
435
+ )
436
+ for workflow_run_id in resp.workflow_run_ids
437
+ ]
417
438
  )
418
- for workflow_run_id in resp.workflow_run_ids
419
- ]
439
+
440
+ return refs
420
441
 
421
442
  def get_workflow_run(self, workflow_run_id: str) -> WorkflowRunRef:
422
443
  return WorkflowRunRef(
hatchet_sdk/config.py CHANGED
@@ -78,12 +78,17 @@ class ClientConfig(BaseSettings):
78
78
 
79
79
  @model_validator(mode="after")
80
80
  def validate_addresses(self) -> "ClientConfig":
81
- if self.host_port == DEFAULT_HOST_PORT:
82
- server_url, grpc_broadcast_address = get_addresses_from_jwt(self.token)
83
- self.host_port = grpc_broadcast_address
84
- self.server_url = server_url
85
- else:
86
- self.server_url = self.host_port
81
+ ## If nothing is set, read from the token
82
+ ## If either is set, override what's in the JWT
83
+ server_url_from_jwt, grpc_broadcast_address_from_jwt = get_addresses_from_jwt(
84
+ self.token
85
+ )
86
+
87
+ if "host_port" not in self.model_fields_set:
88
+ self.host_port = grpc_broadcast_address_from_jwt
89
+
90
+ if "server_url" not in self.model_fields_set:
91
+ self.server_url = server_url_from_jwt
87
92
 
88
93
  if not self.tls_config.server_name:
89
94
  self.tls_config.server_name = self.host_port.split(":")[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hatchet-sdk
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary:
5
5
  Author: Alexander Belanger
6
6
  Author-email: alexander@hatchet.run
@@ -61,26 +61,7 @@ poetry add hatchet-sdk
61
61
 
62
62
  ## Quick Start
63
63
 
64
- Here's a simple example of how to use the Hatchet Python SDK:
65
-
66
- ```python
67
- from hatchet_sdk import Context, EmptyModel, Hatchet
68
-
69
- hatchet = Hatchet(debug=True)
70
-
71
-
72
- @hatchet.task(name="SimpleWorkflow")
73
- def step1(input: EmptyModel, ctx: Context) -> None:
74
- print("executed step1")
75
-
76
-
77
- def main() -> None:
78
- worker = hatchet.worker("test-worker", slots=1, workflows=[step1])
79
- worker.start()
80
-
81
- if __name__ == "__main__":
82
- main()
83
- ```
64
+ For examples of how to use the Hatchet Python SDK, including worker setup and task execution, please see our [official documentation](https://docs.hatchet.run/home/setup).
84
65
 
85
66
  ## Features
86
67
 
@@ -1,6 +1,6 @@
1
1
  hatchet_sdk/__init__.py,sha256=o_06wLLKCKRq4uQuCF62yDRb8hTQYYcqPC3FIDNHxuQ,10002
2
2
  hatchet_sdk/client.py,sha256=lApcV1-qlvIdiHyGrQJAIlT9qzP96I0mQ2STZ1ZV_2g,1940
3
- hatchet_sdk/clients/admin.py,sha256=cc-TyZL6uLz3MGpdVKYziiZlmi29twP8MUJ66CboLtU,15160
3
+ hatchet_sdk/clients/admin.py,sha256=1pY3RlJmVjFAfxX6kwVMd7jO_JHxkei6jrz8XUJUaKI,15333
4
4
  hatchet_sdk/clients/dispatcher/action_listener.py,sha256=FogjHd6vhj4HeQs--Z-99kPwCfaETo1-EcotjdIkrig,16266
5
5
  hatchet_sdk/clients/dispatcher/dispatcher.py,sha256=7tHEoCvL2MKklxbT43oRsQdx9JuLIVCJvFuIUqTHjis,7794
6
6
  hatchet_sdk/clients/durable_event_listener.py,sha256=J5Tg8niikms-tEfB8wps_wgsPF7Fx-pYhYExd0lJo7Y,11791
@@ -217,7 +217,7 @@ hatchet_sdk/clients/rest/tenacity_utils.py,sha256=n6QvwuGwinLQpiWNU5GxrDNhFBE8_w
217
217
  hatchet_sdk/clients/run_event_listener.py,sha256=rIjBLRF7d7FBoEq7RKbmbOA84lX_hHSU26trwnthqV8,10230
218
218
  hatchet_sdk/clients/v1/api_client.py,sha256=L5dbAvIJMnoe9oiUuwLJx8Atn_NTpCctGJ_cXxE-KFs,1247
219
219
  hatchet_sdk/clients/workflow_listener.py,sha256=x6FQ8d786MiubARPG0B92L3Jbs4Ve0CQJFx_udJIB3s,10522
220
- hatchet_sdk/config.py,sha256=piNrTA4EuYNNl0FpsFWceOuIOps-6R95PWZomQWOMBA,3426
220
+ hatchet_sdk/config.py,sha256=jJA76BOvVdfOQHy6TKclAvr2qyblcM-Pz5J-hVAdpQ4,3588
221
221
  hatchet_sdk/connection.py,sha256=B5gT5NL9BBB5-l9U_cN6pMlraQk880rEYMnqaK_dgL0,2590
222
222
  hatchet_sdk/context/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
223
223
  hatchet_sdk/context/context.py,sha256=jxT4HHrocY9dftiXxob-f06JRIYENRLrSgXE-t8hgxY,9347
@@ -506,7 +506,7 @@ hatchet_sdk/worker/runner/runner.py,sha256=ZocvR7dDgEvSxcHAWDDaoTasSz3Wio70TbEbB
506
506
  hatchet_sdk/worker/runner/utils/capture_logs.py,sha256=nHRPSiDBqzhObM7i2X7t03OupVFnE7kQBdR2Ckgg-2w,2709
507
507
  hatchet_sdk/worker/worker.py,sha256=qyHs64H-grF9HR1CgH7MlnoDmTQ8mm4d8basx-ZDyWc,14490
508
508
  hatchet_sdk/workflow_run.py,sha256=Q1nTpnWNsFfjWWpx49xXYUHsVbqTnHL6JWnSKoFM3_I,1029
509
- hatchet_sdk-1.2.2.dist-info/METADATA,sha256=EZhNtPSM0wpGH9Wy6CumXidREsozI01ht921I1d8xgU,3830
510
- hatchet_sdk-1.2.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
511
- hatchet_sdk-1.2.2.dist-info/entry_points.txt,sha256=5mTp_AsCWK5raiVxP_MU9eBCgkRGl4OsN6chpHcvm7o,1235
512
- hatchet_sdk-1.2.2.dist-info/RECORD,,
509
+ hatchet_sdk-1.2.4.dist-info/METADATA,sha256=U6Iloh69aCy5R-Y5V47P61n_TNYHmiQPNLNKyBpmNdg,3571
510
+ hatchet_sdk-1.2.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
511
+ hatchet_sdk-1.2.4.dist-info/entry_points.txt,sha256=5mTp_AsCWK5raiVxP_MU9eBCgkRGl4OsN6chpHcvm7o,1235
512
+ hatchet_sdk-1.2.4.dist-info/RECORD,,