clerk-sdk 0.1.1__py3-none-any.whl → 0.1.3__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.3
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
@@ -11,8 +11,9 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: pydantic>2.0.0
15
- Requires-Dist: backoff>2.0.0
14
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
15
+ Requires-Dist: backoff<3.0.0,>=2.0.0
16
+ Requires-Dist: requests<3.0.0,>=2.32.3
16
17
  Dynamic: author
17
18
  Dynamic: author-email
18
19
  Dynamic: classifier
@@ -26,14 +27,14 @@ Dynamic: summary
26
27
 
27
28
  # CLERK
28
29
 
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.
30
+ `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
31
 
31
32
  ## Features
32
33
 
33
34
  - **Document Management**: Retrieve and manage documents and their associated files.
34
35
  - **API Request Handling**: Simplified GET and POST requests with automatic retries and error handling.
35
36
  - **Data Models**: Predefined Pydantic models for structured data validation and serialization.
36
- - **Task Flow Integration**: Prefect-based decorators for creating and managing task flows.
37
+ - **Task Flow Integration**: Decorator for creating and managing task flows.
37
38
  - **Extensibility**: Easily extend and customize the library to fit your specific use case.
38
39
 
39
40
  ## Installation
@@ -69,17 +70,38 @@ for file in files:
69
70
  print(file.name)
70
71
  ```
71
72
 
72
- ### Use the Prefect Task Decorator
73
+ ### Use the Task Decorator
74
+
75
+ #### PROD
73
76
 
74
77
  ```python
75
78
  from clerk.decorator import clerk_code
79
+ from clerk.decorator.models import ClerkCodePayload
76
80
 
77
81
  @clerk_code()
78
- def process_document(payload):
79
- # Your processing logic here
80
- return {"status": "processed"}
82
+ def main(payload: ClerkCodePayload) -> ClerkCodePayload:
83
+ payload.structured_data["status"] = "ok"
84
+ return payload
85
+
86
+ main()
81
87
  ```
82
88
 
89
+ #### TEST
90
+
91
+ ```python
92
+ from clerk.decorator.models import ClerkCodePayload, Document
93
+
94
+ def test_main():
95
+ test_payload = ClerkCodePayload(
96
+ document=Document(id="doc-123", message_subject="Hello"),
97
+ structured_data={}
98
+ )
99
+
100
+ result = main(test_payload) # ✅ Just pass it!
101
+ assert result.structured_data["status"] == "ok"
102
+ ```
103
+
104
+
83
105
  ## Requirements
84
106
 
85
107
  - 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.3.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
12
+ clerk_sdk-0.1.3.dist-info/METADATA,sha256=lNoj7zwtbuuWUSqI_s6Lq25Q9HGfUsmAYwidw_SCGVE,3041
13
+ clerk_sdk-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ clerk_sdk-0.1.3.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
15
+ clerk_sdk-0.1.3.dist-info/RECORD,,