Metadata-Version: 2.4
Name: datacoder
Version: 0.2.1
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 DataCoder

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

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

# Query a knowledge base
result = sdk.query(
    folder_id="your-folder-uuid",
    query="Quels sont les risques de crédit dans Bâle III ?",
)

print(result.answer)    # Combined text from all matching chunks
print(result.sources)   # List of source document names
print(result.count)     # Number of results

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

## API Reference

### `DataCoder(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 |

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

Query a RAG knowledge base.

| 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.count` | `int` | Number of results |
| `result.results` | `list[dict]` | Raw results with `content`, `source`, `page`, `score` |
| `result.query` | `str` | Original query |
| `result.folder_id` | `str` | Folder queried |

### `sdk.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 |
| `quota.chat_used_today` | `int` | Chat messages used today |
| `quota.chat_limit` | `int` | Daily chat limit |
| `quota.chat_rate_limit` | `int` | Chat rate limit per minute |

### `sdk.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 DataCoder
from datacoder.client import (
    AuthenticationError,
    QuotaExceededError,
    ForbiddenError,
    NotFoundError,
    DataCoderError,
)

sdk = DataCoder(api_key="dc_sk_...", base_url="https://...")

try:
    result = sdk.query(folder_id="...", query="...")
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})")
```

## 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
sdk = DataCoder(
    api_key="dc_sk_...",
    base_url="https://datacoder.your-company.com",
)
```

## License

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