You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Official Python SDK for the [Knowhere](https://knowhereto.ai) document parsing API.
4
6
5
7
## Installation
6
8
7
-
```bash
9
+
```sh
8
10
pip install knowhere-python-sdk
9
11
```
10
12
11
13
Or with [uv](https://docs.astral.sh/uv/):
12
14
13
-
```bash
15
+
```sh
14
16
uv add knowhere-python-sdk
15
17
```
16
18
17
-
## Quick Start
19
+
## Usage
18
20
19
21
```python
20
22
import knowhere
21
23
22
24
client = knowhere.Knowhere(api_key="sk_...")
23
25
24
-
# Parse a document from URL
25
26
result = client.parse(url="https://example.com/report.pdf")
26
27
27
-
print(result.statistics.total_chunks)# 152
28
-
print(result.full_markdown[:200])# First 200 chars of full markdown
28
+
print(result.statistics.total_chunks)
29
+
print(result.full_markdown[:200])
29
30
30
31
for chunk in result.text_chunks:
31
32
print(chunk.content[:80])
32
33
```
33
34
34
-
### Parse a Local File
35
+
While you can provide an `api_key` keyword argument, we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/) to add `KNOWHERE_API_KEY="sk_..."` to your `.env` file so that your API key is not stored in source control.
with knowhere.Knowhere(api_key="sk_...") as client:
148
-
result = client.parse(url="https://example.com/report.pdf")
164
+
Connection errors, 429 Rate Limit, and >=500 Internal errors are automatically retried with exponential backoff.
149
165
150
-
# Async — ensures httpx.AsyncClient is properly closed
151
-
asyncwith knowhere.AsyncKnowhere(api_key="sk_...") as client:
152
-
result =await client.parse(url="https://example.com/report.pdf")
166
+
```python
167
+
client = knowhere.Knowhere(
168
+
api_key="sk_...",
169
+
max_retries=3, # default is 5
170
+
)
153
171
```
154
172
155
-
##Error Handling
173
+
### Determining the installed version
156
174
157
175
```python
158
-
from knowhere import (
159
-
Knowhere,
160
-
AuthenticationError,
161
-
NotFoundError,
162
-
RateLimitError,
163
-
BadRequestError,
164
-
APIStatusError,
165
-
PollingTimeoutError,
166
-
)
167
-
168
-
try:
169
-
result = client.parse(url="https://example.com/report.pdf")
170
-
except BadRequestError as e:
171
-
print(e.status_code) # 400
172
-
print(e.code) # "INVALID_ARGUMENT"
173
-
print(e.message) # "Unsupported file format"
174
-
print(e.request_id) # "req_abc123"
175
-
except NotFoundError as e:
176
-
print(e.message) # "Job not found"
177
-
except RateLimitError as e:
178
-
print(e.retry_after) # seconds to wait
179
-
except AuthenticationError:
180
-
print("Invalid API key")
181
-
except PollingTimeoutError:
182
-
print("Job did not complete within timeout")
183
-
except APIStatusError as e:
184
-
print(f"API error {e.status_code}: {e.message}")
176
+
import knowhere
177
+
print(knowhere.__version__)
185
178
```
186
179
180
+
## Versioning
181
+
182
+
This package follows [Semantic Versioning](https://semver.org/).
183
+
184
+
We publish stable releases to [PyPI](https://pypi.org/project/knowhere-python-sdk/). To install the latest unreleased changes directly from the repository: https://github.com/Ontos-AI/knowhere-python-sdk
0 commit comments