Metadata-Version: 2.4
Name: datatoolpack
Version: 0.2.0
Summary: Official Python SDK for the AutoData ML data preparation pipeline API
Home-page: https://autodata.datatoolpack.com
Author: AutoData Team
Author-email: support@datatoolpack.com
Project-URL: Documentation, https://autodata.datatoolpack.com/docs
Project-URL: Bug Tracker, https://github.com/datatoolpack/autodata-client/issues
Keywords: autodata machine-learning data-preparation synthetic-data ml-pipeline
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
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
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.25.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# AutoData Python Client

Official Python SDK for the [AutoData](https://autodata.datatoolpack.com) ML data preparation pipeline API.

## Installation

```bash
pip install autodata-client
```

Or install from source:

```bash
git clone https://github.com/datatoolpack/autodata-client
cd autodata-client
pip install .
```

## Quick Start

```python
from autodata import AutoDataClient

client = AutoDataClient(
    api_key="dtpk_YOUR_API_KEY",
    base_url="https://autodata.datatoolpack.com",
)

result = client.process(
    file_path="data.csv",
    target_columns=["price"],
    output_rows=20000,
)
print(result["files"])
# [{'name': 'dsg.csv', 'url': '/download/...', 'size': 1048576, 'description': '...'}]
```

Get your API key from the [AutoData dashboard](https://autodata.datatoolpack.com/dashboard) → API Keys tab.

---

## Reference

### `AutoDataClient(api_key, base_url, timeout)`

| Parameter  | Type  | Default                              | Description                        |
|------------|-------|--------------------------------------|------------------------------------|
| `api_key`  | `str` | required                             | API key starting with `dtpk_`      |
| `base_url` | `str` | `"https://autodata.datatoolpack.com"` | Server URL (no trailing slash)     |
| `timeout`  | `int` | `120`                                | Request timeout in seconds         |

---

### `client.process(...)` — Upload & run pipeline

```python
result = client.process(
    file_path="data.csv",           # Path to input CSV
    target_columns=["price"],       # y-column(s) for ML
    output_rows=20000,              # Target row count in output
    tools={                         # Toggle pipeline steps (all optional)
        "anomaly": False,           # Anomaly detection (off by default)
        "dtc": True,                # Data Type Conversion
        "mdh": True,                # Missing Data Handler
        "cds": True,                # Column Scaling
        "dsm": True,                # Data Split Manager
        "dsg": True,                # Synthetic Data Generator
    },
    advanced_params={               # Fine-grained parameters (all optional)
        "excluded_columns": ["id"], # Columns to drop before processing
        "text_mode": 0,             # 0=none, 1=neural, 2=tfidf
        "text_cleaning": True,      # Clean text before encoding
        "zscore_limit": 3.0,        # Z-score outlier threshold
        "dsg_mode": "copula",       # "copula" or "gan"
        "similarity_p": 95,         # Similarity percentile for DSG
    },
    wait=True,                      # Block until complete (default True)
    poll_interval=2,                # Status poll interval in seconds
    download_path="./outputs/",     # Where to save files (default auto)
    output_preferences=["dsg.csv"], # Which files to download (default all)
    compressed=True,                # Download as ZIP (default True)
)
```

**Returns** a dict:

```python
{
    "session_id": "abc123...",
    "status": "completed",
    "files": [
        {"name": "dsg.csv", "url": "/download/.../dsg.csv", "size": 2097152, "description": "Synthetic data"},
        {"name": "dsm_train.csv", ...},
        ...
    ],
    "row_count": 20000,
    "duration_seconds": 42.1,
}
```

Set `wait=False` to get back immediately with just `session_id` and `status`:

```python
result = client.process(file_path="data.csv", target_columns="price", wait=False)
session_id = result["session_id"]
```

---

### `client.get_status(session_id)` — Poll progress

```python
status = client.get_status(session_id)
# {
#   "status": "running",           # queued | running | completed | error | cancelled
#   "message": "Running MDH...",
#   "current_step": 3,
#   "total_steps": 6,
#   "progress_percent": 50,
#   "duration_seconds": 15.3,
# }
```

---

### `client.get_result(session_id)` — Fetch completed results

```python
result = client.get_result(session_id)
# {"status": "completed", "files": [...], "row_count": ..., "duration_seconds": ...}
```

---

### `client.wait_for_completion(session_id, poll_interval)` — Block until done

```python
result = client.wait_for_completion(session_id, poll_interval=3)
```

Prints live progress to stdout. Raises `AutoDataError` if processing fails.

---

### `client.cancel(session_id)` — Cancel a running job

```python
cancelled = client.cancel(session_id)  # True if acknowledged
```

---

### `client.download_results(session_id, ...)` — Download output files

```python
path = client.download_results(
    session_id,
    download_path="./my_outputs/",      # Directory to save into
    output_preferences=["dsg.csv"],     # Specific files only (None = all)
    compressed=True,                    # ZIP download (default) or individual files
)
print(f"Saved to {path}")
```

---

### `client.download_file(url, output_path)` — Download a single file

```python
client.download_file("/download/abc123.../dsg.csv", "dsg.csv")
```

---

### `client.list_keys()` — List API keys

```python
keys = client.list_keys()
# [{"id": "...", "name": "My Key", "prefix": "dtpk_abc123", "created_at": "..."}]
```

---

### `client.get_usage()` — Usage statistics

```python
usage = client.get_usage()
# {
#   "daily_credits_used": 500,
#   "daily_credit_limit": 10000,
#   "daily_remaining": 9500,
#   "lifetime_credits_used": 12340,
#   "lifetime_credit_limit": 1000000,
#   "lifetime_remaining": 987660,
#   "daily_request_count": 3,
#   "last_used_at": "2026-04-12T10:30:00Z",
# }
```

---

## Error Handling

All API errors raise `AutoDataError`:

```python
from autodata import AutoDataClient, AutoDataError

client = AutoDataClient(api_key="dtpk_...")

try:
    result = client.process("data.csv", target_columns="price")
except AutoDataError as e:
    print(f"API error {e.status_code}: {e}")
except FileNotFoundError as e:
    print(f"File not found: {e}")
```

`AutoDataError` attributes:
- `str(e)` — human-readable error message from the server
- `e.status_code` — HTTP status code (e.g. `401`, `429`, `500`), or `None` for non-HTTP errors

---

## Advanced Example: Non-blocking with manual polling

```python
import time
from autodata import AutoDataClient, AutoDataError

client = AutoDataClient(api_key="dtpk_...")

# Start job without blocking
job = client.process("large_dataset.csv", target_columns=["churn"], wait=False)
session_id = job["session_id"]
print(f"Job started: {session_id}")

# Poll manually
while True:
    status = client.get_status(session_id)
    print(f"  {status['progress_percent']}% — {status['message']}")
    if status["status"] == "completed":
        break
    elif status["status"] in ("error", "cancelled"):
        raise AutoDataError(f"Job {status['status']}: {status['message']}")
    time.sleep(5)

# Download results
path = client.download_results(session_id, download_path="./outputs/")
print(f"Results saved to {path}")
```

---

## Requirements

- Python ≥ 3.8
- `requests` ≥ 2.25.0

## License

MIT
