Metadata-Version: 2.4
Name: polyembed
Version: 0.0.2
Summary: Python SDK for the PolyEmbed embeddings API
Author: Aditya Dedhia
License: MIT
Requires-Python: >=3.10
Requires-Dist: httpx
Description-Content-Type: text/markdown

# polyembed

Python SDK for the [PolyEmbed](https://polyembed.com) embeddings API by [a23one](https://github.com/a23one).

## Install

```bash
pip install polyembed
```

## Usage

```python
from polyembed import PolyEmbed

client = PolyEmbed(api_key="pe_<team>_<key>")

# Single embedding
embedding = client.embed("hello world", input_type="document")
# [0.0229, 0.0319, ...]  (1024 floats)

# Limit tokens for faster responses (512–4096, capped by team's plan)
embedding = client.embed("short query", input_type="query", max_tokens=512)

# Batch (1-100 texts)
embeddings = client.embed_batch(
    ["text one", "text two"],
    input_type="document",
    max_tokens=1024,  # optional — cap tokens per text
)

# Shielded (encrypted, non-reversible)
embedding = client.embed(
    "classified report",
    input_type="document",
    shielded=True,
)

# Full response metadata
from polyembed import EmbedResponse

response = client.embed("hello", input_type="query", raw=True)
response.embedding   # list[float]
response.model       # "base"
response.shielded    # False
response.dimensions  # 1024
response.max_tokens  # 4096 (effective limit applied)
```

## Configuration

```python
client = PolyEmbed(
    api_key="pe_...",
    base_url="https://polyembed.com",  # default
    timeout=30,                         # seconds
    max_retries=3,                      # retries on 429/5xx
)
```

## Error handling

```python
from polyembed import AuthenticationError, ValidationError, RateLimitError, ServerError

try:
    embedding = client.embed("hello", input_type="document")
except AuthenticationError:
    # 401 — invalid or expired API key
except ValidationError:
    # 400 — invalid parameters
except RateLimitError:
    # 429 — rate limit exceeded (retried automatically)
except ServerError:
    # 500/502/503/504 — server error (retried automatically)
```

## Context manager

```python
with PolyEmbed(api_key="pe_...") as client:
    embedding = client.embed("hello", input_type="document")
```
