Metadata-Version: 2.4
Name: hyperapi-sdk
Version: 0.8.0
Summary: HyperAPI Python SDK - Document intelligence APIs (parse, extract, classify, split, redact)
Author-email: HyperAPI <research@hyperbots.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://apis.hyperbots.com
Project-URL: Documentation, https://apis.hyperbots.com/docs
Project-URL: Repository, https://github.com/hyprbots/hyperapi-sdk
Project-URL: Issues, https://github.com/hyprbots/hyperapi-sdk/issues
Project-URL: Changelog, https://github.com/hyprbots/hyperapi-sdk/blob/main/CHANGELOG.md
Keywords: ocr,document-processing,invoice,financial,api
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: httpx<1.0,>=0.28.1
Requires-Dist: pydantic<3,>=2.4
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
Requires-Dist: respx>=0.20.0; extra == "dev"
Requires-Dist: ruff==0.8.6; extra == "dev"
Requires-Dist: pre-commit>=4.0.0; extra == "dev"
Provides-Extra: codegen
Requires-Dist: datamodel-code-generator==0.92.0; extra == "codegen"
Requires-Dist: ruff==0.8.6; extra == "codegen"
Provides-Extra: socks
Requires-Dist: httpx[socks]<1.0,>=0.28.1; extra == "socks"
Dynamic: license-file

<p align="center">
<a href="https://apis.hyperbots.com/"><img src="https://images.g2crowd.com/uploads/vendor/image/1515319/9eadfb55dd882c428f4f82ee306dabcd.png" width="115"></a>
  <p align="center"><strong>HyperAPI</strong> Python SDK: parse, extract, classify, split and redact documents.</p>
</p>
<p align="center">
  <a href="https://pypi.org/project/hyperapi-sdk/"><img src="https://img.shields.io/pypi/v/hyperapi-sdk.svg" alt="PyPI"></a>
  <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>
  <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>
</p>

## Install

```bash
pip install hyperapi-sdk
```

Python 3.9 or later. The package is `hyperapi-sdk` and imports as `hyperapi`.

> The `hyperapi` package on PyPI is a different project. Install `hyperapi-sdk`.

## Quick start

Create an API key in the [dashboard](https://apis.hyperbots.com/dashboard/api-keys) and
set it as `HYPERAPI_KEY`.

```python
from hyperapi import HyperAPIClient

with HyperAPIClient() as client:                 # reads HYPERAPI_KEY
    result = client.parse("invoice.pdf")
    print(result.result.ocr)                     # the document's text
```

Every call takes a file path, uploads the file and waits for the result.

## Operations

| Method | What it does | Result |
|---|---|---|
| `parse(file, mode=None)` | Text and layout of every page. `mode="advanced"` adds HTML and markdown per page (Plus plan or higher). | `ParseResponse` |
| `extract(file, category=None, schema=None)` | Structured fields. `category="financial"` for invoices and receipts; `schema=` to define your own output shape. | `ExtractResponse` |
| `extract_advanced(file)` | Structured fields; detects the document type for you. | `ExtractResponse` |
| `classify(file, options=None)` | The document type. | `ClassifyResponse` |
| `split(file, options=None)` | Splits a multi-document file into its documents. | `SplitResponse` |
| `redact(file, mode="redact")` | Masks personal data; `mode="deidentify"` replaces it with synthetic values. | `RedactResponse` |
| `process(file)` | Parse and extract in one call. | `ProcessResult` |

```python
fields = client.extract("invoice.pdf", category="financial")
print(fields.result["entities"], fields.result["line_items"])

policy = client.extract(
    "policy.pdf",
    schema={"policy_number": None, "active": False},   # the shape you want back
)
print(policy.result["data"])

doc_type = client.classify("doc.pdf").result["document_type"]
split = client.split("binder.pdf").result
splits = split["segmentation"]["splits"] if "segmentation" in split else []   # a single document needs no split

masked = client.redact("contract.pdf")
print(masked.result["summary"])                 # {"PERSON_NAME": 2, "EMAIL": 1, ...}
```

`schema` takes a `dict`, a JSON string, or a `pathlib.Path` to a JSON file.

## Typed responses

Results are pydantic v2 models generated from the API's OpenAPI description
([`openapi/hyperapi-public.yaml`](https://github.com/hyprbots/hyperapi-sdk/blob/main/openapi/hyperapi-public.yaml)),
so editors complete field names and type checkers catch typos.

```python
result.result.pages[0].text        # attribute access
result["result"]["pages"]          # dict-style access also works
result.to_dict()                   # a plain dict, e.g. for json.dumps
```

- A field the API adds later stays on the model and in `to_dict()`.
- If a reply does not match its model, you get a `GenericResponse` with the same
  data, and the SDK logs `response_model_mismatch` once. Use dict-style access
  (`result["items"]`) on it; typed attributes such as `items_` are not there.
- A key that clashes with a method gets a trailing underscore as an attribute:
  `batch.items_` (the key is still `batch["items"]`).

## Async client

`AsyncHyperAPIClient` has the same methods; each one is a coroutine. Close it with
`async with` or `await client.aclose()`.

```python
import asyncio
from hyperapi import AsyncHyperAPIClient

async def main():
    async with AsyncHyperAPIClient() as client:
        results = await asyncio.gather(
            client.parse("a.pdf"), client.parse("b.pdf"),
        )

asyncio.run(main())
```

`HyperAPIClient` is not thread-safe; use one client per thread.
`AsyncHyperAPIClient` can be shared across tasks.

## Jobs and batches

Submit without waiting, then collect the result later:

```python
job = client.submit_extract("big.pdf")
result = client.wait_for_job(job)          # or client.get_job(job.job_id)
client.delete_job(job.job_id)              # cancel
```

Process many files as one batch:

```python
batch = client.create_batch_from_files(
    endpoint="/v1/classify",
    file_paths=["a.pdf", "b.pdf", "c.pdf"],
    idempotency_key="nightly-2026-12-01",   # resubmitting returns the same batch
)
status = client.wait_for_batch(batch.batch_id)
for item in status.items_:
    print(item.doc_index, item.status, item.result_url)
```

Batches accept `/v1/parse`, `/v1/extract`, `/v1/extract-omni`, `/v1/classify`,
`/v1/split` and `/v1/redact`. `wait_for_batch()` returns the first 200 items; for a
larger batch, page with `get_batch(batch_id, offset=200)`. Each `result_url` expires;
call `get_batch()` again for a fresh one.

## Configuration

```python
client = HyperAPIClient(
    api_key=None,          # default: HYPERAPI_KEY
    timeout=120.0,         # seconds per HTTP call
    poll_interval=3.0,     # seconds between status checks
    poll_timeout=3600.0,   # seconds to wait for a job
)
```

- **Limits:** `client.get_limits()` returns your account's file size and page limits
  per operation.
- **Proxies and certificates:** the standard `HTTPS_PROXY`, `NO_PROXY` and
  `SSL_CERT_FILE` variables work. For SOCKS, `pip install "hyperapi-sdk[socks]"`.
- **Logging:** `logging.getLogger("hyperapi").setLevel(logging.INFO)`. The SDK never
  logs API keys or file contents.
- **Retries:** the SDK retries status checks, not submits, so a job is never
  created or billed twice.

## Errors

All errors subclass `HyperAPIError` and carry `status_code`, `code` and `request_id`.
Include the `request_id` when you contact support.

| Error | When |
|---|---|
| `AuthenticationError` | Missing or invalid API key (401) |
| `RateLimitError` | Too many requests (429); see `retry_after` |
| `DocumentUploadError` | The upload failed, the file is too large (413) or the type is not supported (415) |
| `ParseError`, `ExtractError`, `ClassifyError`, `SplitError`, `RedactError` | The operation failed, or the document is over its page limit (413) |
| `JobTimeoutError` | `poll_timeout` passed before the job finished |
| `JobCancelledError` | The job was cancelled |

## Supported files

PDF; images (PNG, JPEG, GIF, WebP, TIFF, HEIC, HEIF); Office (DOCX, DOC, XLSX, XLS, PPTX,
PPT); text and data (CSV, TXT, MD, RTF, JSON, XML); XPS and OXPS; email (EML, MSG).

## More

- [Documentation](https://apis.hyperbots.com/docs)
- [Walkthrough notebook](https://github.com/hyprbots/hyperapi-sdk/blob/main/tutorial/HyperAPI_SDK_Walkthrough.ipynb)
- [Changelog](https://github.com/hyprbots/hyperapi-sdk/blob/main/CHANGELOG.md)
- [Issues](https://github.com/hyprbots/hyperapi-sdk/issues) ·
  [Security](https://github.com/hyprbots/hyperapi-sdk/blob/main/SECURITY.md) ·
  support: hyperapi-support@hyperbots.com

## Development

```bash
pip install -e ".[dev]"
ruff check hyperapi/
pytest
```

## License

Apache License 2.0. See [LICENSE](https://github.com/hyprbots/hyperapi-sdk/blob/main/LICENSE)
and [NOTICE](https://github.com/hyprbots/hyperapi-sdk/blob/main/NOTICE).
