chunkr-ai 0.0.35__py3-none-any.whl → 0.0.36__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.
@@ -103,6 +103,29 @@ class TaskResponse(BaseModel, Generic[T]):
103
103
  r.raise_for_status()
104
104
  return await self.poll()
105
105
 
106
+ def _write_to_file(self, content: str | dict, output_file: str, is_json: bool = False) -> None:
107
+ """Helper method to write content to a file
108
+
109
+ Args:
110
+ content: Content to write (string or dict for JSON)
111
+ output_file: Path to save the content
112
+ is_json: Whether the content should be written as JSON
113
+ """
114
+ class DateTimeEncoder(json.JSONEncoder):
115
+ def default(self, obj):
116
+ if isinstance(obj, datetime):
117
+ return obj.isoformat()
118
+ return super().default(obj)
119
+ if output_file:
120
+ directory = os.path.dirname(output_file)
121
+ if directory:
122
+ os.makedirs(directory, exist_ok=True)
123
+ with open(output_file, "w", encoding="utf-8") as f:
124
+ if is_json:
125
+ json.dump(content, f, cls=DateTimeEncoder, indent=2)
126
+ else:
127
+ f.write(content)
128
+
106
129
  def html(self, output_file: str = None) -> str:
107
130
  """Get the full HTML of the task
108
131
 
@@ -110,10 +133,7 @@ class TaskResponse(BaseModel, Generic[T]):
110
133
  output_file (str, optional): Path to save the HTML content. Defaults to None.
111
134
  """
112
135
  content = self._get_content("html")
113
- if output_file:
114
- os.makedirs(os.path.dirname(output_file), exist_ok=True)
115
- with open(output_file, "w", encoding="utf-8") as f:
116
- f.write(content)
136
+ self._write_to_file(content, output_file)
117
137
  return content
118
138
 
119
139
  def markdown(self, output_file: str = None) -> str:
@@ -123,10 +143,7 @@ class TaskResponse(BaseModel, Generic[T]):
123
143
  output_file (str, optional): Path to save the markdown content. Defaults to None.
124
144
  """
125
145
  content = self._get_content("markdown")
126
- if output_file:
127
- os.makedirs(os.path.dirname(output_file), exist_ok=True)
128
- with open(output_file, "w", encoding="utf-8") as f:
129
- f.write(content)
146
+ self._write_to_file(content, output_file)
130
147
  return content
131
148
 
132
149
  def content(self, output_file: str = None) -> str:
@@ -136,10 +153,7 @@ class TaskResponse(BaseModel, Generic[T]):
136
153
  output_file (str, optional): Path to save the content. Defaults to None.
137
154
  """
138
155
  content = self._get_content("content")
139
- if output_file:
140
- os.makedirs(os.path.dirname(output_file), exist_ok=True)
141
- with open(output_file, "w", encoding="utf-8") as f:
142
- f.write(content)
156
+ self._write_to_file(content, output_file)
143
157
  return content
144
158
 
145
159
  def json(self, output_file: str = None) -> dict:
@@ -148,17 +162,8 @@ class TaskResponse(BaseModel, Generic[T]):
148
162
  Args:
149
163
  output_file (str, optional): Path to save the task data as JSON. Defaults to None.
150
164
  """
151
- class DateTimeEncoder(json.JSONEncoder):
152
- def default(self, obj):
153
- if isinstance(obj, datetime):
154
- return obj.isoformat()
155
- return super().default(obj)
156
-
157
165
  data = self.model_dump()
158
- if output_file:
159
- os.makedirs(os.path.dirname(output_file), exist_ok=True)
160
- with open(output_file, "w", encoding="utf-8") as f:
161
- json.dump(data, f, cls=DateTimeEncoder, indent=2)
166
+ self._write_to_file(data, output_file, is_json=True)
162
167
  return data
163
168
 
164
169
  def _get_content(self, t: str) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: chunkr-ai
3
- Version: 0.0.35
3
+ Version: 0.0.36
4
4
  Summary: Python client for Chunkr: open source document intelligence
5
5
  Author-email: Ishaan Kapoor <ishaan@lumina.sh>
6
6
  License: MIT License
@@ -8,9 +8,9 @@ chunkr_ai/api/configuration.py,sha256=2Bfw_c8eQVijb0EvsexiuRbF1pZUspYFBMuZ-ErJHv
8
8
  chunkr_ai/api/decorators.py,sha256=VJX4qGBIL00K2zY8bh5KAMWv7SltJ38TvPJH06FnFss,4415
9
9
  chunkr_ai/api/misc.py,sha256=gTL8UG_R6bunQdKSXwm_SpyIyTmLprzdX3re_X-mMto,5730
10
10
  chunkr_ai/api/protocol.py,sha256=LjPrYSq52m1afIlAo0yVGXlGZxPRh8J6g7S4PAit3Zo,388
11
- chunkr_ai/api/task_response.py,sha256=uvM5uNIImDnivsgujjOh2kxRYuUoqKDhLE1nOH2dJjo,6091
12
- chunkr_ai-0.0.35.dist-info/LICENSE,sha256=w3R12yNDyZpMiy2lxy_hvNbsldC75ww79sF0u11rkho,1069
13
- chunkr_ai-0.0.35.dist-info/METADATA,sha256=bGAuvl7FH2yWdVvykEDTIQ6Ca-43vGDSke8SWX7IyB0,7031
14
- chunkr_ai-0.0.35.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
15
- chunkr_ai-0.0.35.dist-info/top_level.txt,sha256=0IZY7PZIiS8bw5r4NUQRUQ-ATi-L_3vLQVq3ZLouOW8,10
16
- chunkr_ai-0.0.35.dist-info/RECORD,,
11
+ chunkr_ai/api/task_response.py,sha256=FC4OQUv4fltUij5OtFRlWRE9LxzRJGgBhh0olfHJBBg,6258
12
+ chunkr_ai-0.0.36.dist-info/LICENSE,sha256=w3R12yNDyZpMiy2lxy_hvNbsldC75ww79sF0u11rkho,1069
13
+ chunkr_ai-0.0.36.dist-info/METADATA,sha256=1hamwWrDvj0DirX84MAAbZs_yqSxmzGVR7mK7521HK0,7031
14
+ chunkr_ai-0.0.36.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
15
+ chunkr_ai-0.0.36.dist-info/top_level.txt,sha256=0IZY7PZIiS8bw5r4NUQRUQ-ATi-L_3vLQVq3ZLouOW8,10
16
+ chunkr_ai-0.0.36.dist-info/RECORD,,