hyperapi-sdk 0.7.1__tar.gz → 0.8.0__tar.gz
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.
- hyperapi_sdk-0.8.0/PKG-INFO +238 -0
- hyperapi_sdk-0.8.0/README.md +195 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi/__init__.py +1 -1
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi/async_client.py +96 -63
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi/client.py +131 -65
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi/exceptions.py +1 -1
- hyperapi_sdk-0.8.0/hyperapi/types/__init__.py +131 -0
- hyperapi_sdk-0.8.0/hyperapi/types/_base.py +104 -0
- hyperapi_sdk-0.8.0/hyperapi/types/_coerce.py +48 -0
- hyperapi_sdk-0.8.0/hyperapi/types/_generated.py +1364 -0
- hyperapi_sdk-0.8.0/hyperapi/types/_sdk.py +18 -0
- hyperapi_sdk-0.8.0/hyperapi_sdk.egg-info/PKG-INFO +238 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi_sdk.egg-info/SOURCES.txt +5 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi_sdk.egg-info/requires.txt +5 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/pyproject.toml +13 -1
- hyperapi_sdk-0.7.1/PKG-INFO +0 -906
- hyperapi_sdk-0.7.1/README.md +0 -867
- hyperapi_sdk-0.7.1/hyperapi_sdk.egg-info/PKG-INFO +0 -906
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/LICENSE +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/MANIFEST.in +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/NOTICE +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi/py.typed +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi_sdk.egg-info/dependency_links.txt +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/hyperapi_sdk.egg-info/top_level.txt +0 -0
- {hyperapi_sdk-0.7.1 → hyperapi_sdk-0.8.0}/setup.cfg +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyperapi-sdk
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: HyperAPI Python SDK - Document intelligence APIs (parse, extract, classify, split, redact)
|
|
5
|
+
Author-email: HyperAPI <research@hyperbots.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://apis.hyperbots.com
|
|
8
|
+
Project-URL: Documentation, https://apis.hyperbots.com/docs
|
|
9
|
+
Project-URL: Repository, https://github.com/hyprbots/hyperapi-sdk
|
|
10
|
+
Project-URL: Issues, https://github.com/hyprbots/hyperapi-sdk/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/hyprbots/hyperapi-sdk/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: ocr,document-processing,invoice,financial,api
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
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.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
License-File: NOTICE
|
|
28
|
+
Requires-Dist: httpx<1.0,>=0.28.1
|
|
29
|
+
Requires-Dist: pydantic<3,>=2.4
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
34
|
+
Requires-Dist: respx>=0.20.0; extra == "dev"
|
|
35
|
+
Requires-Dist: ruff==0.8.6; extra == "dev"
|
|
36
|
+
Requires-Dist: pre-commit>=4.0.0; extra == "dev"
|
|
37
|
+
Provides-Extra: codegen
|
|
38
|
+
Requires-Dist: datamodel-code-generator==0.92.0; extra == "codegen"
|
|
39
|
+
Requires-Dist: ruff==0.8.6; extra == "codegen"
|
|
40
|
+
Provides-Extra: socks
|
|
41
|
+
Requires-Dist: httpx[socks]<1.0,>=0.28.1; extra == "socks"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<a href="https://apis.hyperbots.com/"><img src="https://images.g2crowd.com/uploads/vendor/image/1515319/9eadfb55dd882c428f4f82ee306dabcd.png" width="115"></a>
|
|
46
|
+
<p align="center"><strong>HyperAPI</strong> Python SDK: parse, extract, classify, split and redact documents.</p>
|
|
47
|
+
</p>
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="https://pypi.org/project/hyperapi-sdk/"><img src="https://img.shields.io/pypi/v/hyperapi-sdk.svg" alt="PyPI"></a>
|
|
50
|
+
<a href="https://github.com/hyprbots/hyperapi-sdk"><img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python 3.9+"></a>
|
|
51
|
+
<a href="https://github.com/hyprbots/hyperapi-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License"></a>
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install hyperapi-sdk
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Python 3.9 or later. The package is `hyperapi-sdk` and imports as `hyperapi`.
|
|
61
|
+
|
|
62
|
+
> The `hyperapi` package on PyPI is a different project. Install `hyperapi-sdk`.
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
Create an API key in the [dashboard](https://apis.hyperbots.com/dashboard/api-keys) and
|
|
67
|
+
set it as `HYPERAPI_KEY`.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from hyperapi import HyperAPIClient
|
|
71
|
+
|
|
72
|
+
with HyperAPIClient() as client: # reads HYPERAPI_KEY
|
|
73
|
+
result = client.parse("invoice.pdf")
|
|
74
|
+
print(result.result.ocr) # the document's text
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Every call takes a file path, uploads the file and waits for the result.
|
|
78
|
+
|
|
79
|
+
## Operations
|
|
80
|
+
|
|
81
|
+
| Method | What it does | Result |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `parse(file, mode=None)` | Text and layout of every page. `mode="advanced"` adds HTML and markdown per page (Plus plan or higher). | `ParseResponse` |
|
|
84
|
+
| `extract(file, category=None, schema=None)` | Structured fields. `category="financial"` for invoices and receipts; `schema=` to define your own output shape. | `ExtractResponse` |
|
|
85
|
+
| `extract_advanced(file)` | Structured fields; detects the document type for you. | `ExtractResponse` |
|
|
86
|
+
| `classify(file, options=None)` | The document type. | `ClassifyResponse` |
|
|
87
|
+
| `split(file, options=None)` | Splits a multi-document file into its documents. | `SplitResponse` |
|
|
88
|
+
| `redact(file, mode="redact")` | Masks personal data; `mode="deidentify"` replaces it with synthetic values. | `RedactResponse` |
|
|
89
|
+
| `process(file)` | Parse and extract in one call. | `ProcessResult` |
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
fields = client.extract("invoice.pdf", category="financial")
|
|
93
|
+
print(fields.result["entities"], fields.result["line_items"])
|
|
94
|
+
|
|
95
|
+
policy = client.extract(
|
|
96
|
+
"policy.pdf",
|
|
97
|
+
schema={"policy_number": None, "active": False}, # the shape you want back
|
|
98
|
+
)
|
|
99
|
+
print(policy.result["data"])
|
|
100
|
+
|
|
101
|
+
doc_type = client.classify("doc.pdf").result["document_type"]
|
|
102
|
+
split = client.split("binder.pdf").result
|
|
103
|
+
splits = split["segmentation"]["splits"] if "segmentation" in split else [] # a single document needs no split
|
|
104
|
+
|
|
105
|
+
masked = client.redact("contract.pdf")
|
|
106
|
+
print(masked.result["summary"]) # {"PERSON_NAME": 2, "EMAIL": 1, ...}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`schema` takes a `dict`, a JSON string, or a `pathlib.Path` to a JSON file.
|
|
110
|
+
|
|
111
|
+
## Typed responses
|
|
112
|
+
|
|
113
|
+
Results are pydantic v2 models generated from the API's OpenAPI description
|
|
114
|
+
([`openapi/hyperapi-public.yaml`](https://github.com/hyprbots/hyperapi-sdk/blob/main/openapi/hyperapi-public.yaml)),
|
|
115
|
+
so editors complete field names and type checkers catch typos.
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
result.result.pages[0].text # attribute access
|
|
119
|
+
result["result"]["pages"] # dict-style access also works
|
|
120
|
+
result.to_dict() # a plain dict, e.g. for json.dumps
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- A field the API adds later stays on the model and in `to_dict()`.
|
|
124
|
+
- If a reply does not match its model, you get a `GenericResponse` with the same
|
|
125
|
+
data, and the SDK logs `response_model_mismatch` once. Use dict-style access
|
|
126
|
+
(`result["items"]`) on it; typed attributes such as `items_` are not there.
|
|
127
|
+
- A key that clashes with a method gets a trailing underscore as an attribute:
|
|
128
|
+
`batch.items_` (the key is still `batch["items"]`).
|
|
129
|
+
|
|
130
|
+
## Async client
|
|
131
|
+
|
|
132
|
+
`AsyncHyperAPIClient` has the same methods; each one is a coroutine. Close it with
|
|
133
|
+
`async with` or `await client.aclose()`.
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
import asyncio
|
|
137
|
+
from hyperapi import AsyncHyperAPIClient
|
|
138
|
+
|
|
139
|
+
async def main():
|
|
140
|
+
async with AsyncHyperAPIClient() as client:
|
|
141
|
+
results = await asyncio.gather(
|
|
142
|
+
client.parse("a.pdf"), client.parse("b.pdf"),
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
asyncio.run(main())
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`HyperAPIClient` is not thread-safe; use one client per thread.
|
|
149
|
+
`AsyncHyperAPIClient` can be shared across tasks.
|
|
150
|
+
|
|
151
|
+
## Jobs and batches
|
|
152
|
+
|
|
153
|
+
Submit without waiting, then collect the result later:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
job = client.submit_extract("big.pdf")
|
|
157
|
+
result = client.wait_for_job(job) # or client.get_job(job.job_id)
|
|
158
|
+
client.delete_job(job.job_id) # cancel
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Process many files as one batch:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
batch = client.create_batch_from_files(
|
|
165
|
+
endpoint="/v1/classify",
|
|
166
|
+
file_paths=["a.pdf", "b.pdf", "c.pdf"],
|
|
167
|
+
idempotency_key="nightly-2026-12-01", # resubmitting returns the same batch
|
|
168
|
+
)
|
|
169
|
+
status = client.wait_for_batch(batch.batch_id)
|
|
170
|
+
for item in status.items_:
|
|
171
|
+
print(item.doc_index, item.status, item.result_url)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Batches accept `/v1/parse`, `/v1/extract`, `/v1/extract-omni`, `/v1/classify`,
|
|
175
|
+
`/v1/split` and `/v1/redact`. `wait_for_batch()` returns the first 200 items; for a
|
|
176
|
+
larger batch, page with `get_batch(batch_id, offset=200)`. Each `result_url` expires;
|
|
177
|
+
call `get_batch()` again for a fresh one.
|
|
178
|
+
|
|
179
|
+
## Configuration
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
client = HyperAPIClient(
|
|
183
|
+
api_key=None, # default: HYPERAPI_KEY
|
|
184
|
+
timeout=120.0, # seconds per HTTP call
|
|
185
|
+
poll_interval=3.0, # seconds between status checks
|
|
186
|
+
poll_timeout=3600.0, # seconds to wait for a job
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
- **Limits:** `client.get_limits()` returns your account's file size and page limits
|
|
191
|
+
per operation.
|
|
192
|
+
- **Proxies and certificates:** the standard `HTTPS_PROXY`, `NO_PROXY` and
|
|
193
|
+
`SSL_CERT_FILE` variables work. For SOCKS, `pip install "hyperapi-sdk[socks]"`.
|
|
194
|
+
- **Logging:** `logging.getLogger("hyperapi").setLevel(logging.INFO)`. The SDK never
|
|
195
|
+
logs API keys or file contents.
|
|
196
|
+
- **Retries:** the SDK retries status checks, not submits, so a job is never
|
|
197
|
+
created or billed twice.
|
|
198
|
+
|
|
199
|
+
## Errors
|
|
200
|
+
|
|
201
|
+
All errors subclass `HyperAPIError` and carry `status_code`, `code` and `request_id`.
|
|
202
|
+
Include the `request_id` when you contact support.
|
|
203
|
+
|
|
204
|
+
| Error | When |
|
|
205
|
+
|---|---|
|
|
206
|
+
| `AuthenticationError` | Missing or invalid API key (401) |
|
|
207
|
+
| `RateLimitError` | Too many requests (429); see `retry_after` |
|
|
208
|
+
| `DocumentUploadError` | The upload failed, the file is too large (413) or the type is not supported (415) |
|
|
209
|
+
| `ParseError`, `ExtractError`, `ClassifyError`, `SplitError`, `RedactError` | The operation failed, or the document is over its page limit (413) |
|
|
210
|
+
| `JobTimeoutError` | `poll_timeout` passed before the job finished |
|
|
211
|
+
| `JobCancelledError` | The job was cancelled |
|
|
212
|
+
|
|
213
|
+
## Supported files
|
|
214
|
+
|
|
215
|
+
PDF; images (PNG, JPEG, GIF, WebP, TIFF, HEIC, HEIF); Office (DOCX, DOC, XLSX, XLS, PPTX,
|
|
216
|
+
PPT); text and data (CSV, TXT, MD, RTF, JSON, XML); XPS and OXPS; email (EML, MSG).
|
|
217
|
+
|
|
218
|
+
## More
|
|
219
|
+
|
|
220
|
+
- [Documentation](https://apis.hyperbots.com/docs)
|
|
221
|
+
- [Walkthrough notebook](https://github.com/hyprbots/hyperapi-sdk/blob/main/tutorial/HyperAPI_SDK_Walkthrough.ipynb)
|
|
222
|
+
- [Changelog](https://github.com/hyprbots/hyperapi-sdk/blob/main/CHANGELOG.md)
|
|
223
|
+
- [Issues](https://github.com/hyprbots/hyperapi-sdk/issues) ·
|
|
224
|
+
[Security](https://github.com/hyprbots/hyperapi-sdk/blob/main/SECURITY.md) ·
|
|
225
|
+
support: hyperapi-support@hyperbots.com
|
|
226
|
+
|
|
227
|
+
## Development
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pip install -e ".[dev]"
|
|
231
|
+
ruff check hyperapi/
|
|
232
|
+
pytest
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
Apache License 2.0. See [LICENSE](https://github.com/hyprbots/hyperapi-sdk/blob/main/LICENSE)
|
|
238
|
+
and [NOTICE](https://github.com/hyprbots/hyperapi-sdk/blob/main/NOTICE).
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://apis.hyperbots.com/"><img src="https://images.g2crowd.com/uploads/vendor/image/1515319/9eadfb55dd882c428f4f82ee306dabcd.png" width="115"></a>
|
|
3
|
+
<p align="center"><strong>HyperAPI</strong> Python SDK: parse, extract, classify, split and redact documents.</p>
|
|
4
|
+
</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://pypi.org/project/hyperapi-sdk/"><img src="https://img.shields.io/pypi/v/hyperapi-sdk.svg" alt="PyPI"></a>
|
|
7
|
+
<a href="https://github.com/hyprbots/hyperapi-sdk"><img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python 3.9+"></a>
|
|
8
|
+
<a href="https://github.com/hyprbots/hyperapi-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install hyperapi-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Python 3.9 or later. The package is `hyperapi-sdk` and imports as `hyperapi`.
|
|
18
|
+
|
|
19
|
+
> The `hyperapi` package on PyPI is a different project. Install `hyperapi-sdk`.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
Create an API key in the [dashboard](https://apis.hyperbots.com/dashboard/api-keys) and
|
|
24
|
+
set it as `HYPERAPI_KEY`.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from hyperapi import HyperAPIClient
|
|
28
|
+
|
|
29
|
+
with HyperAPIClient() as client: # reads HYPERAPI_KEY
|
|
30
|
+
result = client.parse("invoice.pdf")
|
|
31
|
+
print(result.result.ocr) # the document's text
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every call takes a file path, uploads the file and waits for the result.
|
|
35
|
+
|
|
36
|
+
## Operations
|
|
37
|
+
|
|
38
|
+
| Method | What it does | Result |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `parse(file, mode=None)` | Text and layout of every page. `mode="advanced"` adds HTML and markdown per page (Plus plan or higher). | `ParseResponse` |
|
|
41
|
+
| `extract(file, category=None, schema=None)` | Structured fields. `category="financial"` for invoices and receipts; `schema=` to define your own output shape. | `ExtractResponse` |
|
|
42
|
+
| `extract_advanced(file)` | Structured fields; detects the document type for you. | `ExtractResponse` |
|
|
43
|
+
| `classify(file, options=None)` | The document type. | `ClassifyResponse` |
|
|
44
|
+
| `split(file, options=None)` | Splits a multi-document file into its documents. | `SplitResponse` |
|
|
45
|
+
| `redact(file, mode="redact")` | Masks personal data; `mode="deidentify"` replaces it with synthetic values. | `RedactResponse` |
|
|
46
|
+
| `process(file)` | Parse and extract in one call. | `ProcessResult` |
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
fields = client.extract("invoice.pdf", category="financial")
|
|
50
|
+
print(fields.result["entities"], fields.result["line_items"])
|
|
51
|
+
|
|
52
|
+
policy = client.extract(
|
|
53
|
+
"policy.pdf",
|
|
54
|
+
schema={"policy_number": None, "active": False}, # the shape you want back
|
|
55
|
+
)
|
|
56
|
+
print(policy.result["data"])
|
|
57
|
+
|
|
58
|
+
doc_type = client.classify("doc.pdf").result["document_type"]
|
|
59
|
+
split = client.split("binder.pdf").result
|
|
60
|
+
splits = split["segmentation"]["splits"] if "segmentation" in split else [] # a single document needs no split
|
|
61
|
+
|
|
62
|
+
masked = client.redact("contract.pdf")
|
|
63
|
+
print(masked.result["summary"]) # {"PERSON_NAME": 2, "EMAIL": 1, ...}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`schema` takes a `dict`, a JSON string, or a `pathlib.Path` to a JSON file.
|
|
67
|
+
|
|
68
|
+
## Typed responses
|
|
69
|
+
|
|
70
|
+
Results are pydantic v2 models generated from the API's OpenAPI description
|
|
71
|
+
([`openapi/hyperapi-public.yaml`](https://github.com/hyprbots/hyperapi-sdk/blob/main/openapi/hyperapi-public.yaml)),
|
|
72
|
+
so editors complete field names and type checkers catch typos.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
result.result.pages[0].text # attribute access
|
|
76
|
+
result["result"]["pages"] # dict-style access also works
|
|
77
|
+
result.to_dict() # a plain dict, e.g. for json.dumps
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- A field the API adds later stays on the model and in `to_dict()`.
|
|
81
|
+
- If a reply does not match its model, you get a `GenericResponse` with the same
|
|
82
|
+
data, and the SDK logs `response_model_mismatch` once. Use dict-style access
|
|
83
|
+
(`result["items"]`) on it; typed attributes such as `items_` are not there.
|
|
84
|
+
- A key that clashes with a method gets a trailing underscore as an attribute:
|
|
85
|
+
`batch.items_` (the key is still `batch["items"]`).
|
|
86
|
+
|
|
87
|
+
## Async client
|
|
88
|
+
|
|
89
|
+
`AsyncHyperAPIClient` has the same methods; each one is a coroutine. Close it with
|
|
90
|
+
`async with` or `await client.aclose()`.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import asyncio
|
|
94
|
+
from hyperapi import AsyncHyperAPIClient
|
|
95
|
+
|
|
96
|
+
async def main():
|
|
97
|
+
async with AsyncHyperAPIClient() as client:
|
|
98
|
+
results = await asyncio.gather(
|
|
99
|
+
client.parse("a.pdf"), client.parse("b.pdf"),
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
asyncio.run(main())
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`HyperAPIClient` is not thread-safe; use one client per thread.
|
|
106
|
+
`AsyncHyperAPIClient` can be shared across tasks.
|
|
107
|
+
|
|
108
|
+
## Jobs and batches
|
|
109
|
+
|
|
110
|
+
Submit without waiting, then collect the result later:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
job = client.submit_extract("big.pdf")
|
|
114
|
+
result = client.wait_for_job(job) # or client.get_job(job.job_id)
|
|
115
|
+
client.delete_job(job.job_id) # cancel
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Process many files as one batch:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
batch = client.create_batch_from_files(
|
|
122
|
+
endpoint="/v1/classify",
|
|
123
|
+
file_paths=["a.pdf", "b.pdf", "c.pdf"],
|
|
124
|
+
idempotency_key="nightly-2026-12-01", # resubmitting returns the same batch
|
|
125
|
+
)
|
|
126
|
+
status = client.wait_for_batch(batch.batch_id)
|
|
127
|
+
for item in status.items_:
|
|
128
|
+
print(item.doc_index, item.status, item.result_url)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Batches accept `/v1/parse`, `/v1/extract`, `/v1/extract-omni`, `/v1/classify`,
|
|
132
|
+
`/v1/split` and `/v1/redact`. `wait_for_batch()` returns the first 200 items; for a
|
|
133
|
+
larger batch, page with `get_batch(batch_id, offset=200)`. Each `result_url` expires;
|
|
134
|
+
call `get_batch()` again for a fresh one.
|
|
135
|
+
|
|
136
|
+
## Configuration
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
client = HyperAPIClient(
|
|
140
|
+
api_key=None, # default: HYPERAPI_KEY
|
|
141
|
+
timeout=120.0, # seconds per HTTP call
|
|
142
|
+
poll_interval=3.0, # seconds between status checks
|
|
143
|
+
poll_timeout=3600.0, # seconds to wait for a job
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
- **Limits:** `client.get_limits()` returns your account's file size and page limits
|
|
148
|
+
per operation.
|
|
149
|
+
- **Proxies and certificates:** the standard `HTTPS_PROXY`, `NO_PROXY` and
|
|
150
|
+
`SSL_CERT_FILE` variables work. For SOCKS, `pip install "hyperapi-sdk[socks]"`.
|
|
151
|
+
- **Logging:** `logging.getLogger("hyperapi").setLevel(logging.INFO)`. The SDK never
|
|
152
|
+
logs API keys or file contents.
|
|
153
|
+
- **Retries:** the SDK retries status checks, not submits, so a job is never
|
|
154
|
+
created or billed twice.
|
|
155
|
+
|
|
156
|
+
## Errors
|
|
157
|
+
|
|
158
|
+
All errors subclass `HyperAPIError` and carry `status_code`, `code` and `request_id`.
|
|
159
|
+
Include the `request_id` when you contact support.
|
|
160
|
+
|
|
161
|
+
| Error | When |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `AuthenticationError` | Missing or invalid API key (401) |
|
|
164
|
+
| `RateLimitError` | Too many requests (429); see `retry_after` |
|
|
165
|
+
| `DocumentUploadError` | The upload failed, the file is too large (413) or the type is not supported (415) |
|
|
166
|
+
| `ParseError`, `ExtractError`, `ClassifyError`, `SplitError`, `RedactError` | The operation failed, or the document is over its page limit (413) |
|
|
167
|
+
| `JobTimeoutError` | `poll_timeout` passed before the job finished |
|
|
168
|
+
| `JobCancelledError` | The job was cancelled |
|
|
169
|
+
|
|
170
|
+
## Supported files
|
|
171
|
+
|
|
172
|
+
PDF; images (PNG, JPEG, GIF, WebP, TIFF, HEIC, HEIF); Office (DOCX, DOC, XLSX, XLS, PPTX,
|
|
173
|
+
PPT); text and data (CSV, TXT, MD, RTF, JSON, XML); XPS and OXPS; email (EML, MSG).
|
|
174
|
+
|
|
175
|
+
## More
|
|
176
|
+
|
|
177
|
+
- [Documentation](https://apis.hyperbots.com/docs)
|
|
178
|
+
- [Walkthrough notebook](https://github.com/hyprbots/hyperapi-sdk/blob/main/tutorial/HyperAPI_SDK_Walkthrough.ipynb)
|
|
179
|
+
- [Changelog](https://github.com/hyprbots/hyperapi-sdk/blob/main/CHANGELOG.md)
|
|
180
|
+
- [Issues](https://github.com/hyprbots/hyperapi-sdk/issues) ·
|
|
181
|
+
[Security](https://github.com/hyprbots/hyperapi-sdk/blob/main/SECURITY.md) ·
|
|
182
|
+
support: hyperapi-support@hyperbots.com
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pip install -e ".[dev]"
|
|
188
|
+
ruff check hyperapi/
|
|
189
|
+
pytest
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
Apache License 2.0. See [LICENSE](https://github.com/hyprbots/hyperapi-sdk/blob/main/LICENSE)
|
|
195
|
+
and [NOTICE](https://github.com/hyprbots/hyperapi-sdk/blob/main/NOTICE).
|
|
@@ -23,7 +23,7 @@ from .exceptions import (
|
|
|
23
23
|
SplitError,
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
__version__ = "0.
|
|
26
|
+
__version__ = "0.8.0"
|
|
27
27
|
|
|
28
28
|
# Library-style logger: silent unless the application configures handlers.
|
|
29
29
|
# Customers opt in with: `logging.getLogger("hyperapi").setLevel(logging.INFO)`.
|