Metadata-Version: 2.4
Name: perceptra
Version: 1.1.0
Summary: Official Python SDK for the Perceptra Hub Computer Vision MLOps platform
Project-URL: Homepage, https://github.com/tannousgeagea/perceptra-hub
Project-URL: Documentation, https://github.com/tannousgeagea/perceptra-hub
Project-URL: Repository, https://github.com/tannousgeagea/perceptra-hub
Author-email: Tannous Geagea <tannous.geagea@wasteant.com>
License-Expression: MIT
License-File: LICENSE
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: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Requires-Dist: anyio<5.0,>=3.5.0
Requires-Dist: httpx<1.0,>=0.25.0
Requires-Dist: pydantic<3.0,>=2.0.0
Requires-Dist: typing-extensions>=4.7.0
Provides-Extra: dev
Requires-Dist: mypy>=1.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: respx>=0.20; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# Perceptra Python SDK

Official Python SDK for the [Perceptra Hub](https://github.com/tannousgeagea/perceptra-hub) Computer Vision MLOps platform.

## Installation

```bash
pip install perceptra
```

## Quick Start

```python
import perceptra

# Initialize with your API key
client = perceptra.Perceptra(api_key="ph_live_abc123...")

# Or set PERCEPTRA_API_KEY environment variable
client = perceptra.Perceptra()

# Create a project
project = client.projects.create(
    name="Hard Hat Detection",
    project_type_id=1,
)

# Upload images
from pathlib import Path
for path in Path("./images").glob("*.jpg"):
    client.images.upload(file=path, project_id=project.project_id)

# Add annotations
client.annotations.create(
    project_id=project.project_id,
    image_id="...",
    annotation_type="bbox",
    annotation_class_id=0,
    data=[0.1, 0.2, 0.5, 0.8],
)

# Split dataset
client.projects.split_dataset(project.project_id, 0.7, 0.2, 0.1)

# Create a dataset version
version = client.versions.create(project.project_id, "v1.0")

# Create and train a model
model = client.models.create(
    project_id=project.project_id,
    name="YOLOv8 Hard Hat",
    task="object-detection",
    framework="yolo",
)

result = client.models.train(
    model_id=model.id,
    dataset_version_id=version.id,
    config={"epochs": 100, "batch_size": 16},
)

# Stream training logs
for line in client.training.stream_logs(result.training_session_id):
    print(line, end="")
```

## Async Support

```python
import asyncio
import perceptra

async def main():
    async with perceptra.AsyncPerceptra(api_key="ph_live_abc123...") as client:
        projects = await client.projects.list()
        for p in projects:
            print(p["name"])

asyncio.run(main())
```

## Error Handling

```python
from perceptra import NotFoundError, RateLimitError, AuthenticationError

try:
    project = client.projects.retrieve("nonexistent-id")
except NotFoundError:
    print("Project not found")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
    print("Invalid API key")
```

## Available Resources

| Resource | Description |
|----------|-------------|
| `client.projects` | Project CRUD, image management, dataset splitting |
| `client.images` | Image upload, listing, bulk operations |
| `client.annotations` | Annotation CRUD, batch operations |
| `client.models` | ML model CRUD, training triggers |
| `client.training` | Training session monitoring, log streaming |
| `client.versions` | Dataset version management, export |
| `client.organizations` | Organization details, members |
| `client.jobs` | Annotation job management |
| `client.classes` | Annotation class management |
| `client.tags` | Image tag management |
| `client.api_keys` | API key management, rotation |
| `client.storage` | Storage profile management |

## Configuration

| Parameter | Default | Environment Variable |
|-----------|---------|---------------------|
| `api_key` | — | `PERCEPTRA_API_KEY` |
| `base_url` | `http://localhost:29082` | `PERCEPTRA_BASE_URL` |
| `timeout` | `30.0` | — |
| `max_retries` | `3` | — |

## License

MIT
