API Resources

Overview

The Vi SDK provides a comprehensive API for interacting with the Datature Vi platform. All resources are accessed through the ViClient instance and follow a consistent, type-safe interface.

📋

Prerequisites

Get started with Vi SDK →


Core resources


Quick reference

Client initialization

import vi

client = vi.Client(
    secret_key="your-secret-key",
    organization_id="your-org-id"
)

Resource access pattern

All resources follow a consistent access pattern:

# List resources (with pagination)
for page in client.resource.list():
    for item in page.items:
        print(item.name)

# Get specific resource
resource = client.resource.get("resource-id")

# Create resource
new_resource = client.resource.create(...)

# Delete resource
client.resource.delete("resource-id")

Common patterns

Pagination

All list operations support automatic pagination:

from vi.api.types import PaginationParams

# Custom page size
pagination = PaginationParams(page_size=50)
datasets = client.datasets.list(pagination=pagination)

# Iterate all pages
for page in client.datasets.list():
    for dataset in page.items:
        process(dataset)

# Get all items across pages
all_items = list(client.datasets.list().all_items())

Error handling

Handle specific exceptions for better error management:

from vi import (
    ViError,
    ViNotFoundError,
    ViAuthenticationError,
    ViValidationError
)

try:
    dataset = client.datasets.get("dataset-id")
except ViNotFoundError as e:
    print(f"Not found: {e.message}")
except ViAuthenticationError as e:
    print(f"Auth failed: {e.message}")
except ViValidationError as e:
    print(f"Invalid params: {e.message}")
except ViError as e:
    print(f"Error {e.error_code}: {e.message}")

Progress tracking

Long-running operations support progress tracking:

# Download with progress bar
dataset = client.get_dataset(
    dataset_id="dataset-id",
    save_dir="./data",
    show_progress=True  # Shows progress bar
)

# Upload with progress tracking
result = client.assets.upload(
    dataset_id="dataset-id",
    paths="./images/",
    wait_until_done=True  # Wait for processing
)

Resource hierarchy

ViClient
├── organizations (Organization)
├── datasets (Dataset)
│   ├── assets (Asset)
│   └── annotations (Annotation)
├── runs (Run)
│   └── models (Model)
└── flows (Flow)

Type hints

All SDK methods include complete type hints for better IDE support:

from pathlib import Path
from vi.api.resources.datasets.responses import Dataset

def process_dataset(
    client: vi.Client,
    dataset_id: str,
    save_dir: Path | str
) -> Dataset:
    """Download and process a dataset."""
    result = client.get_dataset(
        dataset_id=dataset_id,
        save_dir=save_dir
    )
    return result

Related resources