clerk-sdk 0.1.1__py3-none-any.whl → 0.1.2__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.
@@ -1,5 +1,5 @@
1
1
  import pickle
2
- from typing import Callable
2
+ from typing import Callable, Optional
3
3
  from functools import wraps
4
4
  from .models import ClerkCodePayload
5
5
 
@@ -10,34 +10,42 @@ output_pkl: str = "/app/data/output/output.pkl"
10
10
  def clerk_code():
11
11
  def decorator(func: Callable[[ClerkCodePayload], ClerkCodePayload]):
12
12
  @wraps(func)
13
- def wrapper():
14
- # Step 1: Load and parse input
15
- try:
16
- with open(input_pkl, "rb") as f:
17
- raw_data = pickle.load(f)
18
- parsed = (
19
- ClerkCodePayload.model_validate(raw_data)
20
- if not isinstance(raw_data, ClerkCodePayload)
21
- else raw_data
22
- )
23
- except Exception as e:
24
- raise RuntimeError(f"Failed to load and parse input pickle: {e}") from e
13
+ def wrapper(payload: Optional[ClerkCodePayload] = None) -> ClerkCodePayload:
14
+ # 1. Load payload from file if not provided
15
+ if payload is None:
16
+ try:
17
+ with open(input_pkl, "rb") as f:
18
+ raw_data = pickle.load(f)
19
+ payload = (
20
+ ClerkCodePayload.model_validate(raw_data)
21
+ if not isinstance(raw_data, ClerkCodePayload)
22
+ else raw_data
23
+ )
24
+ except Exception as e:
25
+ raise RuntimeError(
26
+ f"Failed to load and parse input pickle: {e}"
27
+ ) from e
25
28
 
26
- # Step 2: Call the function and validate output
29
+ # 2. Execute function
27
30
  try:
28
- output = func(parsed)
31
+ output = func(payload)
29
32
  if not isinstance(output, ClerkCodePayload):
30
33
  raise TypeError("Function must return a ClerkCodePayload instance.")
31
34
  except Exception as e:
32
- output = e # Save exception to output file for later debugging
35
+ output = e
33
36
 
34
- # Step 3: Write output or exception to pickle
37
+ # 3. Always write to output.pkl
35
38
  try:
36
39
  with open(output_pkl, "wb") as f:
37
40
  pickle.dump(output, f)
38
41
  except Exception as e:
39
42
  raise RuntimeError(f"Failed to write output pickle: {e}") from e
40
43
 
44
+ # 4. Raise if error or return result
45
+ if isinstance(output, Exception):
46
+ raise output
47
+ return output
48
+
41
49
  return wrapper
42
50
 
43
51
  return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clerk-sdk
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Library for interacting with Clerk
5
5
  Home-page: https://github.com/F-ONE-Group/clerk_pypi
6
6
  Author: F-ONE Group
@@ -26,14 +26,14 @@ Dynamic: summary
26
26
 
27
27
  # CLERK
28
28
 
29
- `clerk-sdk` is a Python library designed to simplify interactions with the Clerk API. It provides a robust and user-friendly interface for managing documents, handling API requests, and integrating structured data models into your workflows. With built-in support for Prefect task flows and retry mechanisms, `clerk-sdk` is ideal for developers looking to streamline their integration with Clerk.
29
+ `clerk-sdk` is a Python library designed to simplify interactions with the Clerk API. It provides a robust and user-friendly interface for managing documents, handling API requests, and integrating structured data models into your workflows. `clerk-sdk` is ideal for developers looking to streamline their integration with Clerk.
30
30
 
31
31
  ## Features
32
32
 
33
33
  - **Document Management**: Retrieve and manage documents and their associated files.
34
34
  - **API Request Handling**: Simplified GET and POST requests with automatic retries and error handling.
35
35
  - **Data Models**: Predefined Pydantic models for structured data validation and serialization.
36
- - **Task Flow Integration**: Prefect-based decorators for creating and managing task flows.
36
+ - **Task Flow Integration**: Decorator for creating and managing task flows.
37
37
  - **Extensibility**: Easily extend and customize the library to fit your specific use case.
38
38
 
39
39
  ## Installation
@@ -69,17 +69,38 @@ for file in files:
69
69
  print(file.name)
70
70
  ```
71
71
 
72
- ### Use the Prefect Task Decorator
72
+ ### Use the Task Decorator
73
+
74
+ #### PROD
73
75
 
74
76
  ```python
75
77
  from clerk.decorator import clerk_code
78
+ from clerk.decorator.models import ClerkCodePayload
76
79
 
77
80
  @clerk_code()
78
- def process_document(payload):
79
- # Your processing logic here
80
- return {"status": "processed"}
81
+ def main(payload: ClerkCodePayload) -> ClerkCodePayload:
82
+ payload.structured_data["status"] = "ok"
83
+ return payload
84
+
85
+ main()
81
86
  ```
82
87
 
88
+ #### TEST
89
+
90
+ ```python
91
+ from clerk.decorator.models import ClerkCodePayload, Document
92
+
93
+ def test_main():
94
+ test_payload = ClerkCodePayload(
95
+ document=Document(id="doc-123", message_subject="Hello"),
96
+ structured_data={}
97
+ )
98
+
99
+ result = main(test_payload) # ✅ Just pass it!
100
+ assert result.structured_data["status"] == "ok"
101
+ ```
102
+
103
+
83
104
  ## Requirements
84
105
 
85
106
  - Python 3.10+
@@ -2,14 +2,14 @@ clerk/__init__.py,sha256=LWpbImG7352mUJYC1tRm_zsn5rnt4sFl5ldoq5f0dlo,26
2
2
  clerk/client.py,sha256=UEbs5AhnBs6JWstLzT-TPHZ-yxyBwTFDLemv-yh25K4,3386
3
3
  clerk/decorator/__init__.py,sha256=4VCGOFNq7pA7iJS410V_R9eWfjxP7mwxwa4thwaUTf8,39
4
4
  clerk/decorator/models.py,sha256=FKs7oCq50hmvbzYWuscvqlL7boPYzMKv0Vg3tznmwao,361
5
- clerk/decorator/task_decorator.py,sha256=nLKpPG4kRvNuviO5OLeBzHQppNG2RTHFclGOSARajdM,1536
5
+ clerk/decorator/task_decorator.py,sha256=CW8Fhu-4DanJWB8OaDSZtdeWhDeJQOIq4PofEDf8sqg,1799
6
6
  clerk/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  clerk/models/document.py,sha256=Bbt3YSvGcOrJJjJBYjbDGXpZIaQAYdq_-uIr2urwy5s,525
8
8
  clerk/models/document_statuses.py,sha256=ytTQhgACs2m22qz51_7Ti0IxzbVyl-fl7uF7CnDEyLA,279
9
9
  clerk/models/file.py,sha256=7n6bV6ukRA-uh7MFxUx_TEMNpVAdNe5O0nKIeneCQhg,459
10
10
  clerk/models/response_model.py,sha256=R62daUN1YVOwgnrh_epvFRsQcOwT7R4u97l73egvm-c,232
11
- clerk_sdk-0.1.1.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
12
- clerk_sdk-0.1.1.dist-info/METADATA,sha256=LYguUv0vCO8dpZOkwO5TSuD6VpQeTzq4DcgbRMIasmI,2634
13
- clerk_sdk-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- clerk_sdk-0.1.1.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
15
- clerk_sdk-0.1.1.dist-info/RECORD,,
11
+ clerk_sdk-0.1.2.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
12
+ clerk_sdk-0.1.2.dist-info/METADATA,sha256=Xn9ZXuobFoZilR4nKj3VuKTgyFBrnJodRJK_Nt6Ksko,2986
13
+ clerk_sdk-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ clerk_sdk-0.1.2.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
15
+ clerk_sdk-0.1.2.dist-info/RECORD,,