Metadata-Version: 2.4
Name: extract-design
Version: 0.1.0
Summary: Official Python SDK for the extract.design API
Project-URL: Homepage, https://extract.design
Project-URL: Documentation, https://extract.design/docs
Project-URL: Repository, https://github.com/pixelgenesis/extract-design-python
Project-URL: Issues, https://github.com/pixelgenesis/extract-design-python/issues
Author-email: Pixel Genesis LLC <support@extract.design>
License-Expression: MIT
License-File: LICENSE
Keywords: ai,api,background-removal,design,extract.design,pod,print-on-demand,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.25.0
Provides-Extra: dev
Requires-Dist: pyright>=1.1.0; extra == 'dev'
Requires-Dist: pytest-httpx>=0.30.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# extract-design

Official Python SDK for the [extract.design](https://extract.design) API - AI-powered design extraction for print-on-demand sellers.

## Installation

```bash
pip install extract-design
```

## Quick Start

```python
from extract_design import ExtractDesign

# Initialize the client
client = ExtractDesign(api_key="sk_live_...")

# Extract a design and wait for completion
result = client.extract_and_wait(
    image_url="https://example.com/product.jpg"
)

print(result.extraction_url)
```

## Usage

### Submit an Extraction

```python
from extract_design import ExtractDesign

client = ExtractDesign(api_key="sk_live_...")

# Submit and get extraction ID
response = client.extract(
    image_url="https://example.com/product.jpg"
)

print(f"Extraction ID: {response.extraction_id}")
print(f"Status: {response.status}")
print(f"Estimated time: {response.estimated_time_seconds}s")
```

### Check Extraction Status

```python
result = client.get_extraction(extraction_id)

if result.status == "completed":
    print(f"Design URL: {result.extraction_url}")
elif result.status == "failed":
    print(f"Error: {result.error}")
```

### Wait for Completion

```python
# Simple wait
result = client.wait_for_completion(extraction_id)

# With progress callback
result = client.wait_for_completion(
    extraction_id,
    on_progress=lambda r: print(f"Status: {r.status}"),
)

# Custom timeout and interval
result = client.wait_for_completion(
    extraction_id,
    timeout=120,  # 2 minutes
    interval=3,   # Check every 3 seconds
)
```

### Extract with Options

```python
# With upscaling
result = client.extract_and_wait(
    image_url="https://example.com/product.jpg",
    scale=4,
)

# With remix prompt
result = client.extract_and_wait(
    image_url="https://example.com/product.jpg",
    remix_prompt="Make it a watermelon",
)

# With webhook notification (Pro+ plans)
response = client.extract(
    image_url="https://example.com/product.jpg",
    webhook_url="https://your-api.com/webhook",
    metadata={"order_id": "12345"},
)
```

### Check Usage

```python
usage = client.get_usage()

print(f"Plan: {usage.plan}")
print(f"Credits remaining: {usage.credits.total}")
print(f"Credits used: {usage.credits.used}")
```

### Verify API Key

```python
try:
    client.verify_api_key()
    print("API key is valid")
except AuthenticationError:
    print("Invalid API key")
```

## Error Handling

```python
from extract_design import (
    ExtractDesign,
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
    ValidationError,
    TimeoutError,
    ExtractionFailedError,
)

client = ExtractDesign(api_key="sk_live_...")

try:
    result = client.extract_and_wait(
        image_url="https://example.com/product.jpg"
    )
except AuthenticationError:
    print("Invalid API key")
except InsufficientCreditsError:
    print("Not enough credits")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after} seconds")
except ValidationError as e:
    print(f"Invalid request: {e.error_message}")
except TimeoutError as e:
    print(f"Extraction {e.extraction_id} timed out")
except ExtractionFailedError as e:
    print(f"Extraction failed: {e.reason}")
```

## Context Manager

The client can be used as a context manager to ensure proper cleanup:

```python
with ExtractDesign(api_key="sk_live_...") as client:
    result = client.extract_and_wait(
        image_url="https://example.com/product.jpg"
    )
    print(result.extraction_url)
```

## Configuration

```python
client = ExtractDesign(
    api_key="sk_live_...",
    base_url="https://extract.design",  # Custom base URL
    timeout=60.0,  # Request timeout in seconds
)
```

## Requirements

- Python 3.10+
- httpx

## License

MIT License - see [LICENSE](LICENSE) for details.
