Metadata-Version: 2.4
Name: datacoder
Version: 0.3.0
Summary: Python SDK for DataCoder — AI Data Analyst Platform (RAG API)
Author-email: Clouditia <contact@clouditia.com>
License: MIT
Project-URL: Homepage, https://datacoder.clouditia.com
Project-URL: Documentation, https://datacoder.clouditia.com/docs
Project-URL: Repository, https://github.com/clouditia/datacoder
Keywords: datacoder,rag,sdk,ai,data-analyst
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
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: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28

# DataCoder SDK

Python SDK for [DataCoder](https://datacoder.clouditia.com) — AI Data Analyst Platform.

Query your RAG knowledge bases programmatically.

## Installation

```bash
pip install datacoder
```

## Quick Start

```python
from datacoder import DataCoderClient

# Initialize with your SDK key and server URL
client = DataCoderClient(
    api_key="dc_sk_your_key_here",
    base_url="https://datacoder.clouditia.com",
)

# Test connectivity
if client.ping():
    print("Connected!")

# Search a knowledge base
results = client.search("Quels sont les risques de credit ?")
for r in results:
    print(r.content, r.source, r.score)

# Search in a specific folder
results = client.search(
    "Clause de resiliation",
    folder_id="your-folder-uuid",
)

# Full query with RAGResult
result = client.query(
    folder_id="your-folder-uuid",
    query="Quels sont les risques de credit dans Bale III ?",
)
print(result.answer)    # Combined text from all matching chunks
print(result.sources)   # List of source document names

# Check your quota
quota = client.quota()
print(f"Plan: {quota.plan}")
print(f"SDK remaining today: {quota.sdk_remaining}")

# List accessible folders
folders = client.folders()
for f in folders:
    print(f["name"], f["id"])
```

## API Reference

### `DataCoderClient(api_key, base_url, timeout=30)`

Initialize the SDK client.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `api_key` | `str` | — | Your SDK key (starts with `dc_sk_`) |
| `base_url` | `str` | `https://datacoder.clouditia.com` | DataCoder server URL |
| `timeout` | `int` | `30` | Request timeout in seconds |

### `client.search(query, folder_id=None, top_k=10) → list[SearchResult]`

Search a RAG knowledge base. Returns a list of results.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `query` | `str` | — | Natural language question |
| `folder_id` | `str` | `None` | UUID of the knowledge folder (None = all folders) |
| `top_k` | `int` | `10` | Max results (1-20) |

**Returns:** `list[SearchResult]`

| Property | Type | Description |
|----------|------|-------------|
| `r.content` | `str` | Matching text chunk |
| `r.source` | `str` | Source document name |
| `r.score` | `float` | Similarity score (0-1) |
| `r.page` | `int \| None` | Page number in source document |

### `client.query(folder_id, query, top_k=10) → RAGResult`

Full RAG query with aggregated results.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `folder_id` | `str` | — | UUID of the knowledge folder |
| `query` | `str` | — | Natural language question |
| `top_k` | `int` | `10` | Max results (1-20) |

**Returns:** `RAGResult`

| Property | Type | Description |
|----------|------|-------------|
| `result.answer` | `str` | Concatenated content from all matching chunks |
| `result.sources` | `list[str]` | Source document names |
| `result.items` | `list[SearchResult]` | Results as SearchResult objects |
| `result.count` | `int` | Number of results |

### `client.folders() → list[dict]`

List knowledge folders accessible by this API key.

### `client.quota() → QuotaInfo`

Check current usage and limits.

| Property | Type | Description |
|----------|------|-------------|
| `quota.plan` | `str` | Current plan (`free`, `pro`, `enterprise`) |
| `quota.sdk_used_today` | `int` | SDK requests used today |
| `quota.sdk_limit` | `int` | Daily SDK limit (-1 = unlimited) |
| `quota.sdk_remaining` | `int` | Remaining SDK requests (-1 = unlimited) |
| `quota.sdk_rate_limit` | `int` | Max requests per minute |

### `client.ping() → bool`

Test if the API is reachable and the key is valid. Returns `True` or `False`.

## Plans & Quotas

| | Free | Pro (29€/mo) | Enterprise (99€/mo) |
|--|------|-------------|---------------------|
| SDK requests/day | 10 | 1,000 | 100,000 |
| SDK rate limit | 5/min | 100/min | 1,000/min |
| Chat messages/day | 20 | 200 | 50,000 |

## Error Handling

```python
from datacoder import DataCoderClient
from datacoder.client import (
    AuthenticationError,
    QuotaExceededError,
    ForbiddenError,
    NotFoundError,
    DataCoderError,
)

client = DataCoderClient(api_key="dc_sk_...", base_url="https://...")

try:
    results = client.search("Ma question", folder_id="...")
except AuthenticationError:
    print("Invalid or expired API key")
except QuotaExceededError as e:
    print(f"Quota exceeded. Retry after {e.retry_after}s")
except ForbiddenError:
    print("No access to this folder with this SDK key")
except NotFoundError:
    print("Folder not found or not owned by this user")
except DataCoderError as e:
    print(f"API error: {e} (HTTP {e.status_code})")
```

## Migration from 0.2.x

The class `DataCoder` has been renamed to `DataCoderClient` in 0.3.0.
The old name still works as an alias for backward compatibility.

```python
# Old (still works)
from datacoder import DataCoder
sdk = DataCoder(api_key="...")

# New (recommended)
from datacoder import DataCoderClient
client = DataCoderClient(api_key="...")
```

New in 0.3.0: `client.search()` returns a flat list of `SearchResult` objects — simpler for most use cases.

## Get your SDK Key

1. Log in to [DataCoder](https://datacoder.clouditia.com)
2. Go to **Settings → SDK**
3. Enter a name and click **Generate**
4. Copy your key (shown only once)

## On-Premise

DataCoder can be deployed on your own infrastructure. Point `base_url` to your self-hosted instance:

```python
client = DataCoderClient(
    api_key="dc_sk_...",
    base_url="https://datacoder.your-company.com",
)
```

## License

MIT — [Clouditia](https://clouditia.com)
