clerk-sdk 0.1.0__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.
clerk/decorator/models.py CHANGED
@@ -1,8 +1,19 @@
1
- from typing import Dict
1
+ from typing import Dict, List, Optional
2
2
  from pydantic import BaseModel
3
3
 
4
4
 
5
+ class File(BaseModel):
6
+ name: str
7
+ url: str
8
+
9
+
10
+ class Document(BaseModel):
11
+ id: str
12
+ message_subject: Optional[str] = None
13
+ message_content: Optional[str] = None
14
+ files: List[File] = []
15
+
16
+
5
17
  class ClerkCodePayload(BaseModel):
6
- document_id: str
7
- instance_id: str
8
- data: Dict
18
+ document: Document
19
+ structured_data: Dict
@@ -1,23 +1,51 @@
1
- import json
2
- from typing import Dict
3
- from prefect import flow
1
+ import pickle
2
+ from typing import Callable, Optional
4
3
  from functools import wraps
5
- from prefect.states import Completed
6
- from pydantic import BaseModel
7
4
  from .models import ClerkCodePayload
8
5
 
6
+ input_pkl: str = "/app/data/input/input.pkl"
7
+ output_pkl: str = "/app/data/output/output.pkl"
8
+
9
9
 
10
10
  def clerk_code():
11
- def wrapper(func):
11
+ def decorator(func: Callable[[ClerkCodePayload], ClerkCodePayload]):
12
12
  @wraps(func)
13
- @flow(persist_result=False, log_prints=True, result_serializer="json")
14
- def wrapped_flow(payload: Dict):
15
- payload = ClerkCodePayload(**payload)
16
- result = func(payload)
17
- if isinstance(result, BaseModel):
18
- result = result.model_dump()
19
- return Completed(message=json.dumps(result), data=result)
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
28
+
29
+ # 2. Execute function
30
+ try:
31
+ output = func(payload)
32
+ if not isinstance(output, ClerkCodePayload):
33
+ raise TypeError("Function must return a ClerkCodePayload instance.")
34
+ except Exception as e:
35
+ output = e
36
+
37
+ # 3. Always write to output.pkl
38
+ try:
39
+ with open(output_pkl, "wb") as f:
40
+ pickle.dump(output, f)
41
+ except Exception as e:
42
+ raise RuntimeError(f"Failed to write output pickle: {e}") from e
43
+
44
+ # 4. Raise if error or return result
45
+ if isinstance(output, Exception):
46
+ raise output
47
+ return output
20
48
 
21
- return wrapped_flow
49
+ return wrapper
22
50
 
23
- return wrapper
51
+ return decorator
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clerk-sdk
3
- Version: 0.1.0
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
@@ -11,7 +11,6 @@ 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: prefect==3.4.1
15
14
  Requires-Dist: pydantic>2.0.0
16
15
  Requires-Dist: backoff>2.0.0
17
16
  Dynamic: author
@@ -27,14 +26,14 @@ Dynamic: summary
27
26
 
28
27
  # CLERK
29
28
 
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. 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.
31
30
 
32
31
  ## Features
33
32
 
34
33
  - **Document Management**: Retrieve and manage documents and their associated files.
35
34
  - **API Request Handling**: Simplified GET and POST requests with automatic retries and error handling.
36
35
  - **Data Models**: Predefined Pydantic models for structured data validation and serialization.
37
- - **Task Flow Integration**: Prefect-based decorators for creating and managing task flows.
36
+ - **Task Flow Integration**: Decorator for creating and managing task flows.
38
37
  - **Extensibility**: Easily extend and customize the library to fit your specific use case.
39
38
 
40
39
  ## Installation
@@ -70,22 +69,42 @@ for file in files:
70
69
  print(file.name)
71
70
  ```
72
71
 
73
- ### Use the Prefect Task Decorator
72
+ ### Use the Task Decorator
73
+
74
+ #### PROD
74
75
 
75
76
  ```python
76
77
  from clerk.decorator import clerk_code
78
+ from clerk.decorator.models import ClerkCodePayload
77
79
 
78
80
  @clerk_code()
79
- def process_document(payload):
80
- # Your processing logic here
81
- return {"status": "processed"}
81
+ def main(payload: ClerkCodePayload) -> ClerkCodePayload:
82
+ payload.structured_data["status"] = "ok"
83
+ return payload
84
+
85
+ main()
82
86
  ```
83
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
+
84
104
  ## Requirements
85
105
 
86
106
  - Python 3.10+
87
107
  - Dependencies listed in `requirements.txt`:
88
- - `prefect>=3.4.1`
89
108
  - `pydantic>2.0.0`
90
109
  - `backoff>2.0.0`
91
110
 
@@ -1,15 +1,15 @@
1
1
  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
- clerk/decorator/models.py,sha256=K0vFIh0tzklNxVzntllDDSWuzLf5Sn1pnbJ9Ke7dcrs,149
5
- clerk/decorator/task_decorator.py,sha256=DnsosG6GA3CLktO88bT32Q_3X0YriRUCD7d2xyePmSE,673
4
+ clerk/decorator/models.py,sha256=FKs7oCq50hmvbzYWuscvqlL7boPYzMKv0Vg3tznmwao,361
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.0.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
12
- clerk_sdk-0.1.0.dist-info/METADATA,sha256=Z-raplIGs2ITxdmC2HF9iflHKtVodWZehdKWragyW9U,2685
13
- clerk_sdk-0.1.0.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
14
- clerk_sdk-0.1.0.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
15
- clerk_sdk-0.1.0.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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.7.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5