chunkr-ai 0.1.0__py3-none-any.whl → 0.1.0a2__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.
- chunkr_ai/__init__.py +89 -2
- chunkr_ai/_base_client.py +1995 -0
- chunkr_ai/_client.py +403 -0
- chunkr_ai/_compat.py +219 -0
- chunkr_ai/_constants.py +14 -0
- chunkr_ai/_exceptions.py +108 -0
- chunkr_ai/_files.py +123 -0
- chunkr_ai/_models.py +829 -0
- chunkr_ai/_qs.py +150 -0
- chunkr_ai/_resource.py +43 -0
- chunkr_ai/_response.py +830 -0
- chunkr_ai/_streaming.py +333 -0
- chunkr_ai/_types.py +219 -0
- chunkr_ai/_utils/__init__.py +57 -0
- chunkr_ai/_utils/_logs.py +25 -0
- chunkr_ai/_utils/_proxy.py +65 -0
- chunkr_ai/_utils/_reflection.py +42 -0
- chunkr_ai/_utils/_resources_proxy.py +24 -0
- chunkr_ai/_utils/_streams.py +12 -0
- chunkr_ai/_utils/_sync.py +86 -0
- chunkr_ai/_utils/_transform.py +447 -0
- chunkr_ai/_utils/_typing.py +151 -0
- chunkr_ai/_utils/_utils.py +422 -0
- chunkr_ai/_version.py +4 -0
- chunkr_ai/lib/.keep +4 -0
- chunkr_ai/pagination.py +71 -0
- chunkr_ai/resources/__init__.py +33 -0
- chunkr_ai/resources/health.py +136 -0
- chunkr_ai/resources/task/__init__.py +33 -0
- chunkr_ai/resources/task/parse.py +616 -0
- chunkr_ai/resources/task/task.py +664 -0
- chunkr_ai/types/__init__.py +8 -0
- chunkr_ai/types/health_check_response.py +7 -0
- chunkr_ai/types/task/__init__.py +7 -0
- chunkr_ai/types/task/parse_create_params.py +806 -0
- chunkr_ai/types/task/parse_update_params.py +806 -0
- chunkr_ai/types/task/task.py +1186 -0
- chunkr_ai/types/task_get_params.py +18 -0
- chunkr_ai/types/task_list_params.py +37 -0
- chunkr_ai-0.1.0a2.dist-info/METADATA +504 -0
- chunkr_ai-0.1.0a2.dist-info/RECORD +44 -0
- {chunkr_ai-0.1.0.dist-info → chunkr_ai-0.1.0a2.dist-info}/WHEEL +1 -2
- chunkr_ai-0.1.0a2.dist-info/licenses/LICENSE +201 -0
- chunkr_ai/api/auth.py +0 -13
- chunkr_ai/api/chunkr.py +0 -103
- chunkr_ai/api/chunkr_base.py +0 -185
- chunkr_ai/api/configuration.py +0 -313
- chunkr_ai/api/decorators.py +0 -101
- chunkr_ai/api/misc.py +0 -139
- chunkr_ai/api/protocol.py +0 -14
- chunkr_ai/api/task_response.py +0 -208
- chunkr_ai/models.py +0 -55
- chunkr_ai-0.1.0.dist-info/METADATA +0 -268
- chunkr_ai-0.1.0.dist-info/RECORD +0 -16
- chunkr_ai-0.1.0.dist-info/licenses/LICENSE +0 -21
- chunkr_ai-0.1.0.dist-info/top_level.txt +0 -1
- /chunkr_ai/{api/__init__.py → py.typed} +0 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from typing_extensions import TypedDict
|
6
|
+
|
7
|
+
__all__ = ["TaskGetParams"]
|
8
|
+
|
9
|
+
|
10
|
+
class TaskGetParams(TypedDict, total=False):
|
11
|
+
base64_urls: bool
|
12
|
+
"""Whether to return base64 encoded URLs.
|
13
|
+
|
14
|
+
If false, the URLs will be returned as presigned URLs.
|
15
|
+
"""
|
16
|
+
|
17
|
+
include_chunks: bool
|
18
|
+
"""Whether to include chunks in the output response"""
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from typing import Union
|
6
|
+
from datetime import datetime
|
7
|
+
from typing_extensions import Literal, Annotated, TypedDict
|
8
|
+
|
9
|
+
from .._utils import PropertyInfo
|
10
|
+
|
11
|
+
__all__ = ["TaskListParams"]
|
12
|
+
|
13
|
+
|
14
|
+
class TaskListParams(TypedDict, total=False):
|
15
|
+
base64_urls: bool
|
16
|
+
"""Whether to return base64 encoded URLs.
|
17
|
+
|
18
|
+
If false, the URLs will be returned as presigned URLs.
|
19
|
+
"""
|
20
|
+
|
21
|
+
cursor: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
|
22
|
+
"""Cursor for pagination (timestamp)"""
|
23
|
+
|
24
|
+
end: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
|
25
|
+
"""End date"""
|
26
|
+
|
27
|
+
include_chunks: bool
|
28
|
+
"""Whether to include chunks in the output response"""
|
29
|
+
|
30
|
+
limit: int
|
31
|
+
"""Number of tasks per page"""
|
32
|
+
|
33
|
+
sort: Literal["asc", "desc"]
|
34
|
+
"""Sort order: 'asc' for ascending, 'desc' for descending (default)"""
|
35
|
+
|
36
|
+
start: Annotated[Union[str, datetime], PropertyInfo(format="iso8601")]
|
37
|
+
"""Start date"""
|
@@ -0,0 +1,504 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: chunkr-ai
|
3
|
+
Version: 0.1.0a2
|
4
|
+
Summary: The official Python library for the chunkr API
|
5
|
+
Project-URL: Homepage, https://github.com/lumina-ai-inc/chunkr-python
|
6
|
+
Project-URL: Repository, https://github.com/lumina-ai-inc/chunkr-python
|
7
|
+
Author-email: Chunkr <akhilesh@chunkr.ai>
|
8
|
+
License: Apache-2.0
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
11
|
+
Classifier: Operating System :: MacOS
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Classifier: Operating System :: POSIX
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
23
|
+
Classifier: Typing :: Typed
|
24
|
+
Requires-Python: >=3.8
|
25
|
+
Requires-Dist: anyio<5,>=3.5.0
|
26
|
+
Requires-Dist: distro<2,>=1.7.0
|
27
|
+
Requires-Dist: httpx<1,>=0.23.0
|
28
|
+
Requires-Dist: pydantic<3,>=1.9.0
|
29
|
+
Requires-Dist: sniffio
|
30
|
+
Requires-Dist: typing-extensions<5,>=4.10
|
31
|
+
Provides-Extra: aiohttp
|
32
|
+
Requires-Dist: aiohttp; extra == 'aiohttp'
|
33
|
+
Requires-Dist: httpx-aiohttp>=0.1.8; extra == 'aiohttp'
|
34
|
+
Description-Content-Type: text/markdown
|
35
|
+
|
36
|
+
# Chunkr Python API library
|
37
|
+
|
38
|
+
<!-- prettier-ignore -->
|
39
|
+
[)](https://pypi.org/project/chunkr-ai/)
|
40
|
+
|
41
|
+
The Chunkr Python library provides convenient access to the Chunkr REST API from any Python 3.8+
|
42
|
+
application. The library includes type definitions for all request params and response fields,
|
43
|
+
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
|
44
|
+
|
45
|
+
It is generated with [Stainless](https://www.stainless.com/).
|
46
|
+
|
47
|
+
## Documentation
|
48
|
+
|
49
|
+
The REST API documentation can be found on [docs.chunkr.ai](https://docs.chunkr.ai). The full API of this library can be found in [api.md](https://github.com/lumina-ai-inc/chunkr-python/tree/main/api.md).
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
|
53
|
+
```sh
|
54
|
+
# install from the production repo
|
55
|
+
pip install git+ssh://git@github.com/lumina-ai-inc/chunkr-python.git
|
56
|
+
```
|
57
|
+
|
58
|
+
> [!NOTE]
|
59
|
+
> Once this package is [published to PyPI](https://www.stainless.com/docs/guides/publish), this will become: `pip install --pre chunkr-ai`
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
The full API of this library can be found in [api.md](https://github.com/lumina-ai-inc/chunkr-python/tree/main/api.md).
|
64
|
+
|
65
|
+
```python
|
66
|
+
import os
|
67
|
+
from chunkr_ai import Chunkr
|
68
|
+
|
69
|
+
client = Chunkr(
|
70
|
+
api_key=os.environ.get("CHUNKR_API_KEY"), # This is the default and can be omitted
|
71
|
+
)
|
72
|
+
|
73
|
+
task = client.task.parse.create(
|
74
|
+
file="string",
|
75
|
+
)
|
76
|
+
print(task.task_id)
|
77
|
+
```
|
78
|
+
|
79
|
+
While you can provide an `api_key` keyword argument,
|
80
|
+
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
|
81
|
+
to add `CHUNKR_API_KEY="My API Key"` to your `.env` file
|
82
|
+
so that your API Key is not stored in source control.
|
83
|
+
|
84
|
+
## Async usage
|
85
|
+
|
86
|
+
Simply import `AsyncChunkr` instead of `Chunkr` and use `await` with each API call:
|
87
|
+
|
88
|
+
```python
|
89
|
+
import os
|
90
|
+
import asyncio
|
91
|
+
from chunkr_ai import AsyncChunkr
|
92
|
+
|
93
|
+
client = AsyncChunkr(
|
94
|
+
api_key=os.environ.get("CHUNKR_API_KEY"), # This is the default and can be omitted
|
95
|
+
)
|
96
|
+
|
97
|
+
|
98
|
+
async def main() -> None:
|
99
|
+
task = await client.task.parse.create(
|
100
|
+
file="string",
|
101
|
+
)
|
102
|
+
print(task.task_id)
|
103
|
+
|
104
|
+
|
105
|
+
asyncio.run(main())
|
106
|
+
```
|
107
|
+
|
108
|
+
Functionality between the synchronous and asynchronous clients is otherwise identical.
|
109
|
+
|
110
|
+
### With aiohttp
|
111
|
+
|
112
|
+
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
|
113
|
+
|
114
|
+
You can enable this by installing `aiohttp`:
|
115
|
+
|
116
|
+
```sh
|
117
|
+
# install from the production repo
|
118
|
+
pip install 'chunkr-ai[aiohttp] @ git+ssh://git@github.com/lumina-ai-inc/chunkr-python.git'
|
119
|
+
```
|
120
|
+
|
121
|
+
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
|
122
|
+
|
123
|
+
```python
|
124
|
+
import asyncio
|
125
|
+
from chunkr_ai import DefaultAioHttpClient
|
126
|
+
from chunkr_ai import AsyncChunkr
|
127
|
+
|
128
|
+
|
129
|
+
async def main() -> None:
|
130
|
+
async with AsyncChunkr(
|
131
|
+
api_key="My API Key",
|
132
|
+
http_client=DefaultAioHttpClient(),
|
133
|
+
) as client:
|
134
|
+
task = await client.task.parse.create(
|
135
|
+
file="string",
|
136
|
+
)
|
137
|
+
print(task.task_id)
|
138
|
+
|
139
|
+
|
140
|
+
asyncio.run(main())
|
141
|
+
```
|
142
|
+
|
143
|
+
## Using types
|
144
|
+
|
145
|
+
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
|
146
|
+
|
147
|
+
- Serializing back into JSON, `model.to_json()`
|
148
|
+
- Converting to a dictionary, `model.to_dict()`
|
149
|
+
|
150
|
+
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
|
151
|
+
|
152
|
+
## Pagination
|
153
|
+
|
154
|
+
List methods in the Chunkr API are paginated.
|
155
|
+
|
156
|
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
|
157
|
+
|
158
|
+
```python
|
159
|
+
from chunkr_ai import Chunkr
|
160
|
+
|
161
|
+
client = Chunkr()
|
162
|
+
|
163
|
+
all_tasks = []
|
164
|
+
# Automatically fetches more pages as needed.
|
165
|
+
for task in client.task.list(
|
166
|
+
limit=100,
|
167
|
+
):
|
168
|
+
# Do something with task here
|
169
|
+
all_tasks.append(task)
|
170
|
+
print(all_tasks)
|
171
|
+
```
|
172
|
+
|
173
|
+
Or, asynchronously:
|
174
|
+
|
175
|
+
```python
|
176
|
+
import asyncio
|
177
|
+
from chunkr_ai import AsyncChunkr
|
178
|
+
|
179
|
+
client = AsyncChunkr()
|
180
|
+
|
181
|
+
|
182
|
+
async def main() -> None:
|
183
|
+
all_tasks = []
|
184
|
+
# Iterate through items across all pages, issuing requests as needed.
|
185
|
+
async for task in client.task.list(
|
186
|
+
limit=100,
|
187
|
+
):
|
188
|
+
all_tasks.append(task)
|
189
|
+
print(all_tasks)
|
190
|
+
|
191
|
+
|
192
|
+
asyncio.run(main())
|
193
|
+
```
|
194
|
+
|
195
|
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
|
196
|
+
|
197
|
+
```python
|
198
|
+
first_page = await client.task.list(
|
199
|
+
limit=100,
|
200
|
+
)
|
201
|
+
if first_page.has_next_page():
|
202
|
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
|
203
|
+
next_page = await first_page.get_next_page()
|
204
|
+
print(f"number of items we just fetched: {len(next_page.tasks)}")
|
205
|
+
|
206
|
+
# Remove `await` for non-async usage.
|
207
|
+
```
|
208
|
+
|
209
|
+
Or just work directly with the returned data:
|
210
|
+
|
211
|
+
```python
|
212
|
+
first_page = await client.task.list(
|
213
|
+
limit=100,
|
214
|
+
)
|
215
|
+
|
216
|
+
print(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."
|
217
|
+
for task in first_page.tasks:
|
218
|
+
print(task.task_id)
|
219
|
+
|
220
|
+
# Remove `await` for non-async usage.
|
221
|
+
```
|
222
|
+
|
223
|
+
## Nested params
|
224
|
+
|
225
|
+
Nested parameters are dictionaries, typed using `TypedDict`, for example:
|
226
|
+
|
227
|
+
```python
|
228
|
+
from chunkr_ai import Chunkr
|
229
|
+
|
230
|
+
client = Chunkr()
|
231
|
+
|
232
|
+
task = client.task.parse.create(
|
233
|
+
file="file",
|
234
|
+
chunk_processing={},
|
235
|
+
)
|
236
|
+
print(task.chunk_processing)
|
237
|
+
```
|
238
|
+
|
239
|
+
## Handling errors
|
240
|
+
|
241
|
+
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `chunkr_ai.APIConnectionError` is raised.
|
242
|
+
|
243
|
+
When the API returns a non-success status code (that is, 4xx or 5xx
|
244
|
+
response), a subclass of `chunkr_ai.APIStatusError` is raised, containing `status_code` and `response` properties.
|
245
|
+
|
246
|
+
All errors inherit from `chunkr_ai.APIError`.
|
247
|
+
|
248
|
+
```python
|
249
|
+
import chunkr_ai
|
250
|
+
from chunkr_ai import Chunkr
|
251
|
+
|
252
|
+
client = Chunkr()
|
253
|
+
|
254
|
+
try:
|
255
|
+
client.task.parse.create(
|
256
|
+
file="base64 or url",
|
257
|
+
)
|
258
|
+
except chunkr_ai.APIConnectionError as e:
|
259
|
+
print("The server could not be reached")
|
260
|
+
print(e.__cause__) # an underlying Exception, likely raised within httpx.
|
261
|
+
except chunkr_ai.RateLimitError as e:
|
262
|
+
print("A 429 status code was received; we should back off a bit.")
|
263
|
+
except chunkr_ai.APIStatusError as e:
|
264
|
+
print("Another non-200-range status code was received")
|
265
|
+
print(e.status_code)
|
266
|
+
print(e.response)
|
267
|
+
```
|
268
|
+
|
269
|
+
Error codes are as follows:
|
270
|
+
|
271
|
+
| Status Code | Error Type |
|
272
|
+
| ----------- | -------------------------- |
|
273
|
+
| 400 | `BadRequestError` |
|
274
|
+
| 401 | `AuthenticationError` |
|
275
|
+
| 403 | `PermissionDeniedError` |
|
276
|
+
| 404 | `NotFoundError` |
|
277
|
+
| 422 | `UnprocessableEntityError` |
|
278
|
+
| 429 | `RateLimitError` |
|
279
|
+
| >=500 | `InternalServerError` |
|
280
|
+
| N/A | `APIConnectionError` |
|
281
|
+
|
282
|
+
### Retries
|
283
|
+
|
284
|
+
Certain errors are automatically retried 2 times by default, with a short exponential backoff.
|
285
|
+
Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
|
286
|
+
429 Rate Limit, and >=500 Internal errors are all retried by default.
|
287
|
+
|
288
|
+
You can use the `max_retries` option to configure or disable retry settings:
|
289
|
+
|
290
|
+
```python
|
291
|
+
from chunkr_ai import Chunkr
|
292
|
+
|
293
|
+
# Configure the default for all requests:
|
294
|
+
client = Chunkr(
|
295
|
+
# default is 2
|
296
|
+
max_retries=0,
|
297
|
+
)
|
298
|
+
|
299
|
+
# Or, configure per-request:
|
300
|
+
client.with_options(max_retries=5).task.parse.create(
|
301
|
+
file="base64 or url",
|
302
|
+
)
|
303
|
+
```
|
304
|
+
|
305
|
+
### Timeouts
|
306
|
+
|
307
|
+
By default requests time out after 1 minute. You can configure this with a `timeout` option,
|
308
|
+
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
|
309
|
+
|
310
|
+
```python
|
311
|
+
from chunkr_ai import Chunkr
|
312
|
+
|
313
|
+
# Configure the default for all requests:
|
314
|
+
client = Chunkr(
|
315
|
+
# 20 seconds (default is 1 minute)
|
316
|
+
timeout=20.0,
|
317
|
+
)
|
318
|
+
|
319
|
+
# More granular control:
|
320
|
+
client = Chunkr(
|
321
|
+
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
|
322
|
+
)
|
323
|
+
|
324
|
+
# Override per-request:
|
325
|
+
client.with_options(timeout=5.0).task.parse.create(
|
326
|
+
file="base64 or url",
|
327
|
+
)
|
328
|
+
```
|
329
|
+
|
330
|
+
On timeout, an `APITimeoutError` is thrown.
|
331
|
+
|
332
|
+
Note that requests that time out are [retried twice by default](https://github.com/lumina-ai-inc/chunkr-python/tree/main/#retries).
|
333
|
+
|
334
|
+
## Advanced
|
335
|
+
|
336
|
+
### Logging
|
337
|
+
|
338
|
+
We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
|
339
|
+
|
340
|
+
You can enable logging by setting the environment variable `CHUNKR_LOG` to `info`.
|
341
|
+
|
342
|
+
```shell
|
343
|
+
$ export CHUNKR_LOG=info
|
344
|
+
```
|
345
|
+
|
346
|
+
Or to `debug` for more verbose logging.
|
347
|
+
|
348
|
+
### How to tell whether `None` means `null` or missing
|
349
|
+
|
350
|
+
In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
|
351
|
+
|
352
|
+
```py
|
353
|
+
if response.my_field is None:
|
354
|
+
if 'my_field' not in response.model_fields_set:
|
355
|
+
print('Got json like {}, without a "my_field" key present at all.')
|
356
|
+
else:
|
357
|
+
print('Got json like {"my_field": null}.')
|
358
|
+
```
|
359
|
+
|
360
|
+
### Accessing raw response data (e.g. headers)
|
361
|
+
|
362
|
+
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
|
363
|
+
|
364
|
+
```py
|
365
|
+
from chunkr_ai import Chunkr
|
366
|
+
|
367
|
+
client = Chunkr()
|
368
|
+
response = client.task.parse.with_raw_response.create(
|
369
|
+
file="base64 or url",
|
370
|
+
)
|
371
|
+
print(response.headers.get('X-My-Header'))
|
372
|
+
|
373
|
+
parse = response.parse() # get the object that `task.parse.create()` would have returned
|
374
|
+
print(parse.task_id)
|
375
|
+
```
|
376
|
+
|
377
|
+
These methods return an [`APIResponse`](https://github.com/lumina-ai-inc/chunkr-python/tree/main/src/chunkr_ai/_response.py) object.
|
378
|
+
|
379
|
+
The async client returns an [`AsyncAPIResponse`](https://github.com/lumina-ai-inc/chunkr-python/tree/main/src/chunkr_ai/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
|
380
|
+
|
381
|
+
#### `.with_streaming_response`
|
382
|
+
|
383
|
+
The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
|
384
|
+
|
385
|
+
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
|
386
|
+
|
387
|
+
```python
|
388
|
+
with client.task.parse.with_streaming_response.create(
|
389
|
+
file="base64 or url",
|
390
|
+
) as response:
|
391
|
+
print(response.headers.get("X-My-Header"))
|
392
|
+
|
393
|
+
for line in response.iter_lines():
|
394
|
+
print(line)
|
395
|
+
```
|
396
|
+
|
397
|
+
The context manager is required so that the response will reliably be closed.
|
398
|
+
|
399
|
+
### Making custom/undocumented requests
|
400
|
+
|
401
|
+
This library is typed for convenient access to the documented API.
|
402
|
+
|
403
|
+
If you need to access undocumented endpoints, params, or response properties, the library can still be used.
|
404
|
+
|
405
|
+
#### Undocumented endpoints
|
406
|
+
|
407
|
+
To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
|
408
|
+
http verbs. Options on the client will be respected (such as retries) when making this request.
|
409
|
+
|
410
|
+
```py
|
411
|
+
import httpx
|
412
|
+
|
413
|
+
response = client.post(
|
414
|
+
"/foo",
|
415
|
+
cast_to=httpx.Response,
|
416
|
+
body={"my_param": True},
|
417
|
+
)
|
418
|
+
|
419
|
+
print(response.headers.get("x-foo"))
|
420
|
+
```
|
421
|
+
|
422
|
+
#### Undocumented request params
|
423
|
+
|
424
|
+
If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
|
425
|
+
options.
|
426
|
+
|
427
|
+
#### Undocumented response properties
|
428
|
+
|
429
|
+
To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
|
430
|
+
can also get all the extra fields on the Pydantic model as a dict with
|
431
|
+
[`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
|
432
|
+
|
433
|
+
### Configuring the HTTP client
|
434
|
+
|
435
|
+
You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
|
436
|
+
|
437
|
+
- Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
|
438
|
+
- Custom [transports](https://www.python-httpx.org/advanced/transports/)
|
439
|
+
- Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
|
440
|
+
|
441
|
+
```python
|
442
|
+
import httpx
|
443
|
+
from chunkr_ai import Chunkr, DefaultHttpxClient
|
444
|
+
|
445
|
+
client = Chunkr(
|
446
|
+
# Or use the `CHUNKR_BASE_URL` env var
|
447
|
+
base_url="http://my.test.server.example.com:8083",
|
448
|
+
http_client=DefaultHttpxClient(
|
449
|
+
proxy="http://my.test.proxy.example.com",
|
450
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
451
|
+
),
|
452
|
+
)
|
453
|
+
```
|
454
|
+
|
455
|
+
You can also customize the client on a per-request basis by using `with_options()`:
|
456
|
+
|
457
|
+
```python
|
458
|
+
client.with_options(http_client=DefaultHttpxClient(...))
|
459
|
+
```
|
460
|
+
|
461
|
+
### Managing HTTP resources
|
462
|
+
|
463
|
+
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
|
464
|
+
|
465
|
+
```py
|
466
|
+
from chunkr_ai import Chunkr
|
467
|
+
|
468
|
+
with Chunkr() as client:
|
469
|
+
# make requests here
|
470
|
+
...
|
471
|
+
|
472
|
+
# HTTP client is now closed
|
473
|
+
```
|
474
|
+
|
475
|
+
## Versioning
|
476
|
+
|
477
|
+
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
|
478
|
+
|
479
|
+
1. Changes that only affect static types, without breaking runtime behavior.
|
480
|
+
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
|
481
|
+
3. Changes that we do not expect to impact the vast majority of users in practice.
|
482
|
+
|
483
|
+
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
|
484
|
+
|
485
|
+
We are keen for your feedback; please open an [issue](https://www.github.com/lumina-ai-inc/chunkr-python/issues) with questions, bugs, or suggestions.
|
486
|
+
|
487
|
+
### Determining the installed version
|
488
|
+
|
489
|
+
If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
|
490
|
+
|
491
|
+
You can determine the version that is being used at runtime with:
|
492
|
+
|
493
|
+
```py
|
494
|
+
import chunkr_ai
|
495
|
+
print(chunkr_ai.__version__)
|
496
|
+
```
|
497
|
+
|
498
|
+
## Requirements
|
499
|
+
|
500
|
+
Python 3.8 or higher.
|
501
|
+
|
502
|
+
## Contributing
|
503
|
+
|
504
|
+
See [the contributing documentation](https://github.com/lumina-ai-inc/chunkr-python/tree/main/./CONTRIBUTING.md).
|
@@ -0,0 +1,44 @@
|
|
1
|
+
chunkr_ai/__init__.py,sha256=scS30uHiCpLbaalKTAJSCFSTqnu_b9R5JCkTu2hmbzU,2587
|
2
|
+
chunkr_ai/_base_client.py,sha256=Nv5b_rmVdmmPbF42mlOfymbSC6lxcYsrsvBhKSBDXWQ,67038
|
3
|
+
chunkr_ai/_client.py,sha256=6Dmn7QJXjRXrP9TbOZUhTylnN9adREdxLmobyHrhnbo,15362
|
4
|
+
chunkr_ai/_compat.py,sha256=VWemUKbj6DDkQ-O4baSpHVLJafotzeXmCQGJugfVTIw,6580
|
5
|
+
chunkr_ai/_constants.py,sha256=S14PFzyN9-I31wiV7SmIlL5Ga0MLHxdvegInGdXH7tM,462
|
6
|
+
chunkr_ai/_exceptions.py,sha256=ClgXUcwf4qhBTXnK4LzUPQCFdFldRxAlcYdOFFgpTxA,3220
|
7
|
+
chunkr_ai/_files.py,sha256=KnEzGi_O756MvKyJ4fOCW_u3JhOeWPQ4RsmDvqihDQU,3545
|
8
|
+
chunkr_ai/_models.py,sha256=KvjsMfb88XZlFUKVoOxr8OyDj47MhoH2OKqWNEbBhk4,30010
|
9
|
+
chunkr_ai/_qs.py,sha256=AOkSz4rHtK4YI3ZU_kzea-zpwBUgEY8WniGmTPyEimc,4846
|
10
|
+
chunkr_ai/_resource.py,sha256=f5tiwjxcKdbeMor8idoHtMFTUhqD9yc2xXtq5rqeLLk,1100
|
11
|
+
chunkr_ai/_response.py,sha256=xXNpF53hiYARmAW7npKuxQ5UHAEjgAzm7ME_L3eIstY,28800
|
12
|
+
chunkr_ai/_streaming.py,sha256=ZmyrVWk7-AWkLAATR55WgNxnyFzYmaqJt2LthA_PTqQ,10100
|
13
|
+
chunkr_ai/_types.py,sha256=dnzU2Q2tLcuk29QFEcnPC1wp0-4XB4Cpef_3AnRhV5Y,6200
|
14
|
+
chunkr_ai/_version.py,sha256=aZMksQV_irE9ZNKGRmM5QMcr3SxXmViodBDpjr3crag,169
|
15
|
+
chunkr_ai/pagination.py,sha256=mKx7wg1MEeJT-stWQ60VUHotL6Y3QdDmTr1fjG9scP4,1924
|
16
|
+
chunkr_ai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
17
|
+
chunkr_ai/_utils/__init__.py,sha256=PNZ_QJuzZEgyYXqkO1HVhGkj5IU9bglVUcw7H-Knjzw,2062
|
18
|
+
chunkr_ai/_utils/_logs.py,sha256=ylZvP2JTPNlFCbxYajpsnWkA253kDFgnFYDWWuvgf_Q,780
|
19
|
+
chunkr_ai/_utils/_proxy.py,sha256=aglnj2yBTDyGX9Akk2crZHrl10oqRmceUy2Zp008XEs,1975
|
20
|
+
chunkr_ai/_utils/_reflection.py,sha256=ZmGkIgT_PuwedyNBrrKGbxoWtkpytJNU1uU4QHnmEMU,1364
|
21
|
+
chunkr_ai/_utils/_resources_proxy.py,sha256=3KbSCApjaz7x_frFAxJe9ltY-dIJBQUVnIhR2GvVRY8,604
|
22
|
+
chunkr_ai/_utils/_streams.py,sha256=SMC90diFFecpEg_zgDRVbdR3hSEIgVVij4taD-noMLM,289
|
23
|
+
chunkr_ai/_utils/_sync.py,sha256=TpGLrrhRNWTJtODNE6Fup3_k7zrWm1j2RlirzBwre-0,2862
|
24
|
+
chunkr_ai/_utils/_transform.py,sha256=n7kskEWz6o__aoNvhFoGVyDoalNe6mJwp-g7BWkdj88,15617
|
25
|
+
chunkr_ai/_utils/_typing.py,sha256=D0DbbNu8GnYQTSICnTSHDGsYXj8TcAKyhejb0XcnjtY,4602
|
26
|
+
chunkr_ai/_utils/_utils.py,sha256=ts4CiiuNpFiGB6YMdkQRh2SZvYvsl7mAF-JWHCcLDf4,12312
|
27
|
+
chunkr_ai/lib/.keep,sha256=wuNrz-5SXo3jJaJOJgz4vFHM41YH_g20F5cRQo0vLes,224
|
28
|
+
chunkr_ai/resources/__init__.py,sha256=zhuIEAnBOs0bLyNTeWngJbEFhlevoTx0NzTZMlX_cs8,976
|
29
|
+
chunkr_ai/resources/health.py,sha256=XTvUtRs5hEK-uccb_40mcIex85eEUo1a171nQUjpSOs,4965
|
30
|
+
chunkr_ai/resources/task/__init__.py,sha256=TrjBrfPuVqlcYULga_NosiVxZETfe8dKdUJHjIDJ5zE,963
|
31
|
+
chunkr_ai/resources/task/parse.py,sha256=Sv4aIP6LEOPg_4lTEZBKpSxQrhRSN0daBKubLMg1dV0,28057
|
32
|
+
chunkr_ai/resources/task/task.py,sha256=Rn2zfndPYOtFa5LacvGcNURJkEa7TCjgOtavKWmHO04,24172
|
33
|
+
chunkr_ai/types/__init__.py,sha256=uDFPzVZGkt8tLxw7DID6EVKQQnemw_j4qZnzpK7WZng,355
|
34
|
+
chunkr_ai/types/health_check_response.py,sha256=6Zn5YYHCQf2RgMjDlf39mtiTPqfaBfC9Vv599U_rKCI,200
|
35
|
+
chunkr_ai/types/task_get_params.py,sha256=Nx2luhebcoaiuRln4KP4FarWvBPd1OYi__efi56zHPM,460
|
36
|
+
chunkr_ai/types/task_list_params.py,sha256=fCku42QW6QUsLmZgKJBaxisGvUcmcQ5fa6LgHHRIwiQ,1043
|
37
|
+
chunkr_ai/types/task/__init__.py,sha256=dglHZXlnA7NvA-Bz5O2aLS7Ug4NP6KuQDeYlQuEx5S8,298
|
38
|
+
chunkr_ai/types/task/parse_create_params.py,sha256=YT4_p3k5eamPOud_e8BP3EailaDrTuGrG17gwVyHvr8,31794
|
39
|
+
chunkr_ai/types/task/parse_update_params.py,sha256=GpIpT74YY44J_RoLksyAAWmSG39MlTxq2YR3WrdHrOc,31749
|
40
|
+
chunkr_ai/types/task/task.py,sha256=p8HWN1usu35R-KS1sk24BZlS2pwsR7HBZWUkGUAEoXg,44340
|
41
|
+
chunkr_ai-0.1.0a2.dist-info/METADATA,sha256=M88Syly-5DGBErrj2n0By9XYLY6wb6q4QtN2ff1IAC8,15854
|
42
|
+
chunkr_ai-0.1.0a2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
43
|
+
chunkr_ai-0.1.0a2.dist-info/licenses/LICENSE,sha256=3FDRL-L-DFkrFy8yJpb1Nxhuztm0PB2kawcCgK5utFg,11336
|
44
|
+
chunkr_ai-0.1.0a2.dist-info/RECORD,,
|