Skip to content

Python Sdk Documentation

Angan Sen edited this page Dec 4, 2024 · 1 revision

Labellerr SDK Documentation

Table of Contents

  1. Introduction
  2. Installation
  3. Getting Started
  4. Key Features
  5. Error Handling
  6. Support

Introduction

The Labellerr SDK is a Python library designed to make interacting with the Labellerr platform simple and efficient. With this SDK, you can manage data annotations, projects, and exports seamlessly in your applications.

This documentation will guide you through installing the SDK, understanding its core functionalities, and handling common errors.


Installation

To install the Labellerr SDK, use the following command:

pip install https://github.com/tensormatics/SDKPython/releases/download/v1/labellerr_sdk-1.0.0.tar.gz

Getting Started

Once installed, you can start by importing and initializing the LabellerrClient. This client will handle all communication with the Labellerr platform.

Example:

from labellerr.client import LabellerrClient

# Initialize the client with your API credentials
client = LabellerrClient('your_api_key', 'your_api_secret')

Replace 'your_api_key' and 'your_api_secret' with your actual API credentials provided by Labellerr.


Key Features

Creating a New Project

A project in Labellerr organizes your datasets and their annotations. Use the following method to create a project:

Method:

def initiate_create_project(self, payload):
    """
    Initiates the creation of a new project.
    Args:
        payload (dict): Contains project configurations.
    Returns:
        dict: Contains project details.
    """

Example Usage:

project_payload = {
    'client_id': '12345',
    'dataset_name': 'Sample Dataset',
    'dataset_description': 'A sample dataset for image classification',
    'data_type': 'image',
    'created_by': 'user@example.com',
    'project_name': 'Image Classification Project',
    'annotation_guide': [
        {
            "question_number": 1,
            "question": "What is the main object in the image?",
            "required": True,
            "options": [
                {"option_name": "Car"},
                {"option_name": "Building"},
                {"option_name": "Person"}
            ],
            "option_type": "SingleSelect"
        }
    ],
    'rotation_config': {
        'annotation_rotation_count': 0,
        'review_rotation_count': 1,
        'client_review_rotation_count': 0
    },
    'autolabel': False,
    'folder_to_upload': '/path/to/image/folder'
}

try:
    result = client.initiate_create_project(project_payload)
    print(f"Project created successfully. Project ID: {result['project_id']}")
except LabellerrError as e:
    print(f"Project creation failed: {str(e)}")

Uploading Pre-annotations

Pre-annotations help predefine labels for your dataset, speeding up the annotation process.

Method:

def upload_preannotation_by_project_id(self, project_id, client_id, annotation_format, annotation_file):
    """
    Uploads pre-annotations for a project.
    Args:
        project_id (str): The ID of the project.
        client_id (str): The ID of the client.
        annotation_format (str): Format of annotations (e.g., 'coco', 'yolo').
        annotation_file (str): Path to the annotation file.
    Returns:
        dict: Response containing the upload status.
    """

Example Usage:

project_id = 'project_123'
client_id = '12345'
annotation_format = 'coco'
annotation_file = '/path/to/annotations.json'

try:
    result = client.upload_preannotation_by_project_id(project_id, client_id, annotation_format, annotation_file)
    print("Pre-annotations uploaded successfully.")
except LabellerrError as e:
    print(f"Pre-annotation upload failed: {str(e)}")

Exporting Project Data Locally

Export project data to analyze, store, or share it with others.

Method:

def create_local_export(self, project_id, client_id, export_config):
    """
    Creates a local export of project data.
    Args:
        project_id (str): The ID of the project.
        client_id (str): The ID of the client.
        export_config (dict): Configuration for the export.
    Returns:
        dict: Contains export details.
    """

Example Usage:

project_id = 'project_123'
client_id = '12345'
export_config = {
    "export_name": "Weekly Export",
    "export_description": "Export of all accepted annotations",
    "export_format": "json",
    "export_destination": "local",
    "question_ids": ["all"],
    "statuses": ["accepted"]
}

try:
    result = client.create_local_export(project_id, client_id, export_config)
    print(f"Local export created successfully. Export ID: {result['export_id']}")
except LabellerrError as e:
    print(f"Local export creation failed: {str(e)}")

Error Handling

The Labellerr SDK uses a custom exception class, LabellerrError, to indicate issues during API interactions. Always wrap your function calls in try-except blocks to gracefully handle errors.

Example:

from labellerr.exceptions import LabellerrError

try:
    # Example function call
    result = client.initiate_create_project(payload)
except LabellerrError as e:
    print(f"An error occurred: {str(e)}")

Support

If you encounter issues or have questions, feel free to contact the Labellerr support team: