hatchet-sdk 1.16.0__py3-none-any.whl → 1.16.1__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.

@@ -0,0 +1,93 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from typing import Any, ClassVar, Dict, List, Optional, Set
21
+
22
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
23
+ from typing_extensions import Self
24
+
25
+
26
+ class V1CELDebugErrorResponse(BaseModel):
27
+ """
28
+ V1CELDebugErrorResponse
29
+ """ # noqa: E501
30
+
31
+ status: StrictStr
32
+ error: StrictStr = Field(description="The error message if the evaluation failed")
33
+ __properties: ClassVar[List[str]] = ["status", "error"]
34
+
35
+ @field_validator("status")
36
+ def status_validate_enum(cls, value):
37
+ """Validates the enum"""
38
+ if value not in set(["ERROR"]):
39
+ raise ValueError("must be one of enum values ('ERROR')")
40
+ return value
41
+
42
+ model_config = ConfigDict(
43
+ populate_by_name=True,
44
+ validate_assignment=True,
45
+ protected_namespaces=(),
46
+ )
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
55
+ return json.dumps(self.to_dict())
56
+
57
+ @classmethod
58
+ def from_json(cls, json_str: str) -> Optional[Self]:
59
+ """Create an instance of V1CELDebugErrorResponse from a JSON string"""
60
+ return cls.from_dict(json.loads(json_str))
61
+
62
+ def to_dict(self) -> Dict[str, Any]:
63
+ """Return the dictionary representation of the model using alias.
64
+
65
+ This has the following differences from calling pydantic's
66
+ `self.model_dump(by_alias=True)`:
67
+
68
+ * `None` is only added to the output dict for nullable fields that
69
+ were set at model initialization. Other fields with value `None`
70
+ are ignored.
71
+ """
72
+ excluded_fields: Set[str] = set([])
73
+
74
+ _dict = self.model_dump(
75
+ by_alias=True,
76
+ exclude=excluded_fields,
77
+ exclude_none=True,
78
+ )
79
+ return _dict
80
+
81
+ @classmethod
82
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
83
+ """Create an instance of V1CELDebugErrorResponse from a dict"""
84
+ if obj is None:
85
+ return None
86
+
87
+ if not isinstance(obj, dict):
88
+ return cls.model_validate(obj)
89
+
90
+ _obj = cls.model_validate(
91
+ {"status": obj.get("status"), "error": obj.get("error")}
92
+ )
93
+ return _obj
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from typing import Any, ClassVar, Dict, List, Optional, Set
21
+
22
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
23
+ from typing_extensions import Self
24
+
25
+
26
+ class V1CELDebugRequest(BaseModel):
27
+ """
28
+ V1CELDebugRequest
29
+ """ # noqa: E501
30
+
31
+ expression: StrictStr = Field(description="The CEL expression to evaluate")
32
+ input: Dict[str, Any] = Field(
33
+ description="The input, which simulates the workflow run input"
34
+ )
35
+ filter_payload: Optional[Dict[str, Any]] = Field(
36
+ default=None,
37
+ description="The filter payload, which simulates a payload set on a previous-created filter",
38
+ alias="filterPayload",
39
+ )
40
+ additional_metadata: Optional[Dict[str, Any]] = Field(
41
+ default=None,
42
+ description="Additional metadata, which simulates metadata that could be sent with an event or a workflow run",
43
+ alias="additionalMetadata",
44
+ )
45
+ __properties: ClassVar[List[str]] = [
46
+ "expression",
47
+ "input",
48
+ "filterPayload",
49
+ "additionalMetadata",
50
+ ]
51
+
52
+ model_config = ConfigDict(
53
+ populate_by_name=True,
54
+ validate_assignment=True,
55
+ protected_namespaces=(),
56
+ )
57
+
58
+ def to_str(self) -> str:
59
+ """Returns the string representation of the model using alias"""
60
+ return pprint.pformat(self.model_dump(by_alias=True))
61
+
62
+ def to_json(self) -> str:
63
+ """Returns the JSON representation of the model using alias"""
64
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
65
+ return json.dumps(self.to_dict())
66
+
67
+ @classmethod
68
+ def from_json(cls, json_str: str) -> Optional[Self]:
69
+ """Create an instance of V1CELDebugRequest from a JSON string"""
70
+ return cls.from_dict(json.loads(json_str))
71
+
72
+ def to_dict(self) -> Dict[str, Any]:
73
+ """Return the dictionary representation of the model using alias.
74
+
75
+ This has the following differences from calling pydantic's
76
+ `self.model_dump(by_alias=True)`:
77
+
78
+ * `None` is only added to the output dict for nullable fields that
79
+ were set at model initialization. Other fields with value `None`
80
+ are ignored.
81
+ """
82
+ excluded_fields: Set[str] = set([])
83
+
84
+ _dict = self.model_dump(
85
+ by_alias=True,
86
+ exclude=excluded_fields,
87
+ exclude_none=True,
88
+ )
89
+ return _dict
90
+
91
+ @classmethod
92
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
93
+ """Create an instance of V1CELDebugRequest from a dict"""
94
+ if obj is None:
95
+ return None
96
+
97
+ if not isinstance(obj, dict):
98
+ return cls.model_validate(obj)
99
+
100
+ _obj = cls.model_validate(
101
+ {
102
+ "expression": obj.get("expression"),
103
+ "input": obj.get("input"),
104
+ "filterPayload": obj.get("filterPayload"),
105
+ "additionalMetadata": obj.get("additionalMetadata"),
106
+ }
107
+ )
108
+ return _obj
@@ -0,0 +1,100 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from typing import Any, ClassVar, Dict, List, Optional, Set
21
+
22
+ from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
23
+ from typing_extensions import Self
24
+
25
+ from hatchet_sdk.clients.rest.models.v1_cel_debug_response_status import (
26
+ V1CELDebugResponseStatus,
27
+ )
28
+
29
+
30
+ class V1CELDebugResponse(BaseModel):
31
+ """
32
+ V1CELDebugResponse
33
+ """ # noqa: E501
34
+
35
+ status: V1CELDebugResponseStatus
36
+ output: Optional[StrictBool] = Field(
37
+ default=None,
38
+ description="The result of the CEL expression evaluation, if successful",
39
+ )
40
+ error: Optional[StrictStr] = Field(
41
+ default=None, description="The error message if the evaluation failed"
42
+ )
43
+ __properties: ClassVar[List[str]] = ["status", "output", "error"]
44
+
45
+ model_config = ConfigDict(
46
+ populate_by_name=True,
47
+ validate_assignment=True,
48
+ protected_namespaces=(),
49
+ )
50
+
51
+ def to_str(self) -> str:
52
+ """Returns the string representation of the model using alias"""
53
+ return pprint.pformat(self.model_dump(by_alias=True))
54
+
55
+ def to_json(self) -> str:
56
+ """Returns the JSON representation of the model using alias"""
57
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
58
+ return json.dumps(self.to_dict())
59
+
60
+ @classmethod
61
+ def from_json(cls, json_str: str) -> Optional[Self]:
62
+ """Create an instance of V1CELDebugResponse from a JSON string"""
63
+ return cls.from_dict(json.loads(json_str))
64
+
65
+ def to_dict(self) -> Dict[str, Any]:
66
+ """Return the dictionary representation of the model using alias.
67
+
68
+ This has the following differences from calling pydantic's
69
+ `self.model_dump(by_alias=True)`:
70
+
71
+ * `None` is only added to the output dict for nullable fields that
72
+ were set at model initialization. Other fields with value `None`
73
+ are ignored.
74
+ """
75
+ excluded_fields: Set[str] = set([])
76
+
77
+ _dict = self.model_dump(
78
+ by_alias=True,
79
+ exclude=excluded_fields,
80
+ exclude_none=True,
81
+ )
82
+ return _dict
83
+
84
+ @classmethod
85
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
86
+ """Create an instance of V1CELDebugResponse from a dict"""
87
+ if obj is None:
88
+ return None
89
+
90
+ if not isinstance(obj, dict):
91
+ return cls.model_validate(obj)
92
+
93
+ _obj = cls.model_validate(
94
+ {
95
+ "status": obj.get("status"),
96
+ "output": obj.get("output"),
97
+ "error": obj.get("error"),
98
+ }
99
+ )
100
+ return _obj
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ from enum import Enum
19
+
20
+ from typing_extensions import Self
21
+
22
+
23
+ class V1CELDebugResponseStatus(str, Enum):
24
+ """
25
+ The status of the CEL evaluation
26
+ """
27
+
28
+ """
29
+ allowed enum values
30
+ """
31
+ SUCCESS = "SUCCESS"
32
+ ERROR = "ERROR"
33
+
34
+ @classmethod
35
+ def from_json(cls, json_str: str) -> Self:
36
+ """Create an instance of V1CELDebugResponseStatus from a JSON string"""
37
+ return cls(json.loads(json_str))
@@ -0,0 +1,102 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from typing import Any, ClassVar, Dict, List, Optional, Set
21
+
22
+ from pydantic import (
23
+ BaseModel,
24
+ ConfigDict,
25
+ Field,
26
+ StrictBool,
27
+ StrictStr,
28
+ field_validator,
29
+ )
30
+ from typing_extensions import Self
31
+
32
+
33
+ class V1CELDebugSuccessResponse(BaseModel):
34
+ """
35
+ V1CELDebugSuccessResponse
36
+ """ # noqa: E501
37
+
38
+ status: StrictStr
39
+ output: StrictBool = Field(
40
+ description="The result of the CEL expression evaluation"
41
+ )
42
+ __properties: ClassVar[List[str]] = ["status", "output"]
43
+
44
+ @field_validator("status")
45
+ def status_validate_enum(cls, value):
46
+ """Validates the enum"""
47
+ if value not in set(["SUCCESS"]):
48
+ raise ValueError("must be one of enum values ('SUCCESS')")
49
+ return value
50
+
51
+ model_config = ConfigDict(
52
+ populate_by_name=True,
53
+ validate_assignment=True,
54
+ protected_namespaces=(),
55
+ )
56
+
57
+ def to_str(self) -> str:
58
+ """Returns the string representation of the model using alias"""
59
+ return pprint.pformat(self.model_dump(by_alias=True))
60
+
61
+ def to_json(self) -> str:
62
+ """Returns the JSON representation of the model using alias"""
63
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64
+ return json.dumps(self.to_dict())
65
+
66
+ @classmethod
67
+ def from_json(cls, json_str: str) -> Optional[Self]:
68
+ """Create an instance of V1CELDebugSuccessResponse from a JSON string"""
69
+ return cls.from_dict(json.loads(json_str))
70
+
71
+ def to_dict(self) -> Dict[str, Any]:
72
+ """Return the dictionary representation of the model using alias.
73
+
74
+ This has the following differences from calling pydantic's
75
+ `self.model_dump(by_alias=True)`:
76
+
77
+ * `None` is only added to the output dict for nullable fields that
78
+ were set at model initialization. Other fields with value `None`
79
+ are ignored.
80
+ """
81
+ excluded_fields: Set[str] = set([])
82
+
83
+ _dict = self.model_dump(
84
+ by_alias=True,
85
+ exclude=excluded_fields,
86
+ exclude_none=True,
87
+ )
88
+ return _dict
89
+
90
+ @classmethod
91
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
92
+ """Create an instance of V1CELDebugSuccessResponse from a dict"""
93
+ if obj is None:
94
+ return None
95
+
96
+ if not isinstance(obj, dict):
97
+ return cls.model_validate(obj)
98
+
99
+ _obj = cls.model_validate(
100
+ {"status": obj.get("status"), "output": obj.get("output")}
101
+ )
102
+ return _obj
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hatchet API
5
+
6
+ The Hatchet API
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from typing import Any, ClassVar, Dict, List, Optional, Set
21
+
22
+ from pydantic import BaseModel, ConfigDict, Field
23
+ from typing_extensions import Annotated, Self
24
+
25
+
26
+ class V1ReplayedTasks(BaseModel):
27
+ """
28
+ V1ReplayedTasks
29
+ """ # noqa: E501
30
+
31
+ ids: Optional[
32
+ List[Annotated[str, Field(min_length=36, strict=True, max_length=36)]]
33
+ ] = Field(
34
+ default=None, description="The list of task external ids that were replayed"
35
+ )
36
+ __properties: ClassVar[List[str]] = ["ids"]
37
+
38
+ model_config = ConfigDict(
39
+ populate_by_name=True,
40
+ validate_assignment=True,
41
+ protected_namespaces=(),
42
+ )
43
+
44
+ def to_str(self) -> str:
45
+ """Returns the string representation of the model using alias"""
46
+ return pprint.pformat(self.model_dump(by_alias=True))
47
+
48
+ def to_json(self) -> str:
49
+ """Returns the JSON representation of the model using alias"""
50
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51
+ return json.dumps(self.to_dict())
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of V1ReplayedTasks from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ """
68
+ excluded_fields: Set[str] = set([])
69
+
70
+ _dict = self.model_dump(
71
+ by_alias=True,
72
+ exclude=excluded_fields,
73
+ exclude_none=True,
74
+ )
75
+ return _dict
76
+
77
+ @classmethod
78
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
79
+ """Create an instance of V1ReplayedTasks from a dict"""
80
+ if obj is None:
81
+ return None
82
+
83
+ if not isinstance(obj, dict):
84
+ return cls.model_validate(obj)
85
+
86
+ _obj = cls.model_validate({"ids": obj.get("ids")})
87
+ return _obj
@@ -0,0 +1,99 @@
1
+ import asyncio
2
+ from typing import Literal
3
+
4
+ from pydantic import BaseModel, Field
5
+
6
+ from hatchet_sdk.clients.rest.api.cel_api import CELApi
7
+ from hatchet_sdk.clients.rest.api_client import ApiClient
8
+ from hatchet_sdk.clients.rest.models.v1_cel_debug_request import V1CELDebugRequest
9
+ from hatchet_sdk.clients.rest.models.v1_cel_debug_response_status import (
10
+ V1CELDebugResponseStatus,
11
+ )
12
+ from hatchet_sdk.clients.v1.api_client import BaseRestClient, retry
13
+ from hatchet_sdk.utils.typing import JSONSerializableMapping
14
+
15
+
16
+ class CELSuccess(BaseModel):
17
+ status: Literal["success"] = "success"
18
+ output: bool
19
+
20
+
21
+ class CELFailure(BaseModel):
22
+ status: Literal["failure"] = "failure"
23
+ error: str
24
+
25
+
26
+ class CELEvaluationResult(BaseModel):
27
+ result: CELSuccess | CELFailure = Field(discriminator="status")
28
+
29
+
30
+ class CELClient(BaseRestClient):
31
+ """
32
+ The CEL client is a client for debugging CEL expressions within Hatchet
33
+ """
34
+
35
+ def _ca(self, client: ApiClient) -> CELApi:
36
+ return CELApi(client)
37
+
38
+ @retry
39
+ def debug(
40
+ self,
41
+ expression: str,
42
+ input: JSONSerializableMapping,
43
+ additional_metadata: JSONSerializableMapping | None = None,
44
+ filter_payload: JSONSerializableMapping | None = None,
45
+ ) -> CELEvaluationResult:
46
+ """
47
+ Debug a CEL expression with the provided input, filter payload, and optional metadata. Useful for testing and validating CEL expressions and debugging issues in production.
48
+
49
+ :param expression: The CEL expression to debug.
50
+ :param input: The input, which simulates the workflow run input.
51
+ :param additional_metadata: Additional metadata, which simulates metadata that could be sent with an event or a workflow run
52
+ :param filter_payload: The filter payload, which simulates a payload set on a previous-created filter
53
+
54
+ :raises ValueError: If no response is received from the CEL debug API.
55
+
56
+ :return: A V1CELDebugErrorResponse or V1CELDebugSuccessResponse containing the result of the debug operation.
57
+ """
58
+ request = V1CELDebugRequest(
59
+ expression=expression,
60
+ input=input,
61
+ additionalMetadata=additional_metadata,
62
+ filterPayload=filter_payload,
63
+ )
64
+ with self.client() as client:
65
+ result = self._ca(client).v1_cel_debug(
66
+ tenant=self.client_config.tenant_id, v1_cel_debug_request=request
67
+ )
68
+
69
+ if result.status == V1CELDebugResponseStatus.ERROR:
70
+ if result.error is None:
71
+ raise ValueError("No error message received from CEL debug API.")
72
+
73
+ return CELEvaluationResult(result=CELFailure(error=result.error))
74
+
75
+ if result.output is None:
76
+ raise ValueError("No output received from CEL debug API.")
77
+
78
+ return CELEvaluationResult(result=CELSuccess(output=result.output))
79
+
80
+ async def aio_debug(
81
+ self,
82
+ expression: str,
83
+ input: JSONSerializableMapping,
84
+ additional_metadata: JSONSerializableMapping | None = None,
85
+ filter_payload: JSONSerializableMapping | None = None,
86
+ ) -> CELEvaluationResult:
87
+ """
88
+ Debug a CEL expression with the provided input, filter payload, and optional metadata. Useful for testing and validating CEL expressions and debugging issues in production.
89
+
90
+ :param expression: The CEL expression to debug.
91
+ :param input: The input, which simulates the workflow run input.
92
+ :param additional_metadata: Additional metadata, which simulates metadata that could be sent with an event or a workflow run
93
+ :param filter_payload: The filter payload, which simulates a payload set on a previous-created filter
94
+
95
+ :return: A V1CELDebugErrorResponse or V1CELDebugSuccessResponse containing the result of the debug operation.
96
+ """
97
+ return await asyncio.to_thread(
98
+ self.debug, expression, input, additional_metadata, filter_payload
99
+ )
hatchet_sdk/hatchet.py CHANGED
@@ -12,6 +12,7 @@ from hatchet_sdk.clients.events import EventClient
12
12
  from hatchet_sdk.clients.listeners.run_event_listener import RunEventListenerClient
13
13
  from hatchet_sdk.clients.rest.models.tenant_version import TenantVersion
14
14
  from hatchet_sdk.config import ClientConfig
15
+ from hatchet_sdk.features.cel import CELClient
15
16
  from hatchet_sdk.features.cron import CronClient
16
17
  from hatchet_sdk.features.filters import FiltersClient
17
18
  from hatchet_sdk.features.logs import LogsClient
@@ -66,6 +67,13 @@ class Hatchet:
66
67
  "🚨⚠️‼️ YOU ARE USING A V0 ENGINE WITH A V1 SDK, WHICH IS NOT SUPPORTED. PLEASE UPGRADE YOUR ENGINE TO V1.🚨⚠️‼️"
67
68
  )
68
69
 
70
+ @property
71
+ def cel(self) -> CELClient:
72
+ """
73
+ The CEL client is a client for interacting with Hatchet's CEL API.
74
+ """
75
+ return self._client.cel
76
+
69
77
  @property
70
78
  def cron(self) -> CronClient:
71
79
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hatchet-sdk
3
- Version: 1.16.0
3
+ Version: 1.16.1
4
4
  Summary:
5
5
  License: MIT
6
6
  Author: Alexander Belanger