Metadata-Version: 2.5
Name: uprelic
Version: 0.3.0
Summary: Python client for the Uprelic API
Project-URL: Documentation, https://api.uprelic.com/v1/docs
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2
Description-Content-Type: text/markdown

# Uprelic Python SDK

```sh
pip install uprelic
```

Set `UPRELIC_API_KEY` (create a key at https://platform.uprelic.com), or pass `api_key=` to the client.

```python
from uprelic import Uprelic, Noul, Choice, Score

client = Uprelic()
response = client.system_one(
    model="strom-1.0.7",
    state="I was charged twice for my subscription. Please fix this today.",
    questions={
        "billing": Noul("Is this message about billing?"),
        "tone": Choice("What is the tone?", criteria={"angry": "Upset or hostile", "calm": "Neutral or polite"}),
        "urgency": Score("How urgent is this?", criteria=["Can wait", "This week", "Today"]),
    },
)

response.nouls["billing"].noul        # 0.98
response.choices["tone"].choice       # "angry"
response.scores["urgency"].score      # 1.8
response.usage.input_tokens
response.usage.cost                   # in response.usage.currency
response.metadata.server_processing_time_ms
```

Images go in `images=` as http(s) or `data:image/...` URLs. `client.models()` lists the available models.

## Document extraction

`client.extract()` takes one PDF (at most 8 pages) or image and a JSON Schema whose properties are the fields to
extract: strings (`format: date`), numbers (`format: amount` or `percent`), booleans or string enums.

```python
from pathlib import Path

response = client.extract(
    model="strom-1.0.7",
    document=Path("invoice.pdf"),  # or bytes, or an http(s) or data: URL
    schema={"properties": {
        "invoice_date": {"type": "string", "format": "date"},
        "total": {"type": "number", "format": "amount", "description": "The total including tax"},
    }},
)

response.fields["total"].value        # 1234.5
response.fields["total"].text         # "Total EUR 1.234,50", the line it came from
response.fields["total"].confidence   # 0.94
response.fields["total"].page, response.fields["total"].box
```

A field the document doesn't give is `None`. When the line holds more than one value of the field's type, `value` is
the whole line.

## Async

```python
from uprelic import AsyncUprelic

async with AsyncUprelic() as client:
    response = await client.system_one(model="strom-1.0.7", state="...", questions={...})
```

## Errors and retries

Failed requests raise `uprelic.APIError` subclasses: `AuthenticationError` (401), `InsufficientBalanceError` (402),
`InvalidRequestError` (400, 413, 422), `RateLimitError` (429) and `ServerError` (5xx). Each has `status_code` and `detail`.

Rate limits (429), 502/503/504 responses and connection failures are retried twice with backoff. Change this with
`Uprelic(max_retries=...)`.

API reference: https://api.uprelic.com/v1/docs
