Ango Hub Docs
Open Ango HubContact iMerit
  • Ango Hub Documentation
  • Video Guides
  • Changelog
  • FAQs & Troubleshooting
  • All Keyboard and Mouse Shortcuts
  • Core Concepts
    • Assets
    • Attachments
    • Batches
    • Benchmarks
    • Category Schema (Ontologies)
    • Frame Interpolation
    • Geofencing
    • Idle Time Detection & Time Tracking
    • Instructions
    • Issues
      • Issue Error Codes
    • Label Validation
    • Labeler Performance
    • Labeling
    • Labeling Queue
    • Multiple Classification
    • Notifications
    • Organizations
    • Projects
    • Requeuing
    • Reviewing
    • Review Queue
    • Skipping
    • Stage History
    • Tasks
    • Usage
    • User Roles
    • Workflow
      • Complete
      • Consensus
      • Hold
      • Label
      • Logic
      • Plugin
      • Review
      • Start
      • Webhook
  • Labeling
    • Managing Users in Projects
      • Profile Page
    • Managing the Project Ontology
    • Labeling Editor Interface
      • Audio Labeling Editor
      • Image Labeling Editor
      • Video Labeling Editor
      • DICOM Labeling Editor
      • Medical Labeling Editor
        • 3D Bounding Box
        • Fill Between Slices
        • Island Tools
        • Line (Tape Measure)
        • Smoothing
      • PDF Labeling Editor
      • Text (NER) Labeling Editor
      • LLM Chat Labeling Editor
      • Markdown Labeling Editor
      • 3D Multi-Sensor Fusion Labeling Editor
    • Labeling Classes
      • Tools
        • Bounding Box
        • Brush
        • Entity
        • Message
        • Nested Classifications
        • PCT
        • PDF Tool
        • Point
        • Polygon
        • Polyline
        • Rotated Bounding Box
        • Segmentation
        • Spline
        • Voxel Brush
      • Classification
        • Checkbox
        • Multiple Dropdown
        • Radio
        • Rank
        • Single Dropdown
        • Text
        • Tree Dropdown Tools (Single and Multiple Selection)
      • Relation
        • Single Relation
        • Group Relation
    • Magnetic Lasso
    • Performance & Compatibility Considerations
  • Data
    • Data in Ango Hub
      • Embedding Private Bucket Files in MD Assets
    • Importing Assets
      • Asset Builder
      • Bundled Assets
        • Importing Multiple Images as One Multi-Page Asset
        • Importing Multiple Single-Frame DICOM Files as One Multi-Page Asset
        • Importing multiple DICOM files to be annotated and displayed at once
        • Importing Multiple Single-Frame DICOM Files as a DICOM Series
        • Importing Multiple Markdown Files as One Multi-Page Asset
      • File Explorer
      • Supported Asset File Types & Codecs
      • Importing Cloud (Remote) Assets
      • Importing From Local Machine
      • Creating and Importing LLM Chat Assets
      • Importing Data in the 3D Multi-Sensor Fusion Labeling Tool
      • Bulk Importing Markdown/HTML Assets
      • Importing Attachments during Asset Import
      • Importing Annotations during Asset Import
      • contextData: Adding Extra Data to Assets
      • Importing Reference Images as Overlay
      • Importing Reference Medical Data During Asset Import
    • Importing and Exporting Annotations
      • Importing Annotations
        • Ango Import Format
        • Importing Brush Traces
        • Importing NRRD Annotations
      • Exporting Annotations
        • Ango Export Format
          • Asset
            • Task
              • Tools
              • Classifications
              • Relations
          • Stage History
    • Adding and Managing LLMs
    • Storages
      • Set up a storage integration with Azure
      • Set up a storage integration with AWS S3
      • Set up a storage integration with MinIO and S3-compatible custom storage services
      • Set up a storage integration with GCP (Google Cloud Platform)
      • Set up CORS
      • Validating Storage Integrations
    • Purging Data from Ango Hub
  • Plugins
    • Overview of Plugins in Ango Hub
      • Installing Plugins
      • Plugin Setting Presets
      • Monitoring Plugin Progress
    • First-Party Plugins
      • Ango Export Converter Plugins
      • Asset Converter Plugins
      • Ango to Mask Converter
      • Batch Assignment
      • ChatGPT
      • Column-Agnostic Markdown Generator
      • CSV Export for Classification
      • DALL-E
      • DALL-E (Model Plugin)
      • File Explorer Plugin
      • General Object Detector
      • General Object Segmenter
      • Markdown Generator
      • One-Click Segmentation
      • Open World Object Detection
      • Optical Character Recognition
      • TPT Export
      • YOLO | Instance Segmentation
      • YOLO | Pose Estimation
      • YOLO | Object Detection
      • YOLO | Image Classification
    • Plugin Developer Documentation
      • Export Plugins
      • Batch Model Plugins
      • Model Plugins
      • File Explorer Plugins
      • Markdown Generator Plugins
      • Plugin Logger
      • [WIP] Deploying your Plugin
      • Plugin 'Host' Information
  • SDK
    • SDK Documentation
      • Project Level SDK Functions
        • add_members_to_project
        • assign_batches
        • assign_task
        • create_attachment
        • create_batch
        • create_issue
        • create_label_set
        • create_project
        • delete_issue
        • export
        • exportV3
        • get_assets
        • get_batches
        • get_issues
        • get_metrics
        • get_project
        • get_project_performance
        • get_task
        • get_tasks
        • get_task_history
        • import_labels
        • list_projects
        • requeue_tasks
        • rerun_webhook
        • update_workflow_stages
        • upload_files
        • upload_files_cloud
        • upload_files_with_asset_builder
        • upload_chat_assets
      • Organization Level SDK Functions
        • create_storage
        • delete_organization_invites
        • delete_organization_members
        • delete_storage
        • get_organization_invites
        • get_organization_members
        • get_storages
        • invite_members_to_org
        • update_organization_members_role
    • SDK - Useful Snippets
    • SDK Changelog
  • API
    • API Documentation
  • How-To
    • Add Members
      • Add multiple users to a project
    • Annotate
      • Annotate 3D Point Cloud Files on Ango Hub
      • Perform targeted OCR on images
    • Export Data
      • Automatically send Ango Hub Webhook contents to Google Sheets, Email, Slack, and more with Zapier
      • Download a JSON of your project ontology
      • Download DICOM Segmentation Masks
      • Download your annotations in the COCO, KITTI, or YOLO format
      • Download your Segmentation Masks
      • Get your export as separate JSON files for each asset
    • Manage a Project
      • Get your API Key
      • Get your Organization ID
      • Mute your notifications
      • Open an asset provided the Asset ID
      • Pre-label assets
      • Share a filtered view of the Tasks table with others
      • Transfer project ontologies between projects
      • Transfer project workflows between projects
    • Perform Model Evaluation on Ango Hub
  • Troubleshooting
    • I get a "0 Tasks Labeled" alert when trying to pre-label tasks
    • I get a 'The data couldn't be loaded properly' error when opening certain assets
    • I get a "Unknown Classification" warning when opening a task
  • Feature Availability Status for projects of the 3D Multi-Sensor Fusion type
  • Comparison between QuickServe and Ango Hub
  • Changes from Ango Hub Legacy
  • Video V2 Breaking Changes and Transition
  • Data Access, Storage, and Security
  • Two-Factor Authentication
  • Single Sign-On (SSO) Support
  • Customer Support
  • Ango Hub Status Page
Powered by GitBook
On this page
  • End-to-end project preparation via SDK
  • Clone an Existing Project’s Category Schema and Workflow
  1. SDK

SDK - Useful Snippets

On this page are some ready-made snippets that you may use in their entirety or as a starting point in using the Ango SDK.

End-to-end project preparation via SDK

This code snippet provides a step-by-step guide to programmatically preparing a new project using our SDK. It covers everything from project initialization to configuring settings, managing assets, and integrating workflows. Following the outlined procedures, users can create a fully functional project from scratch, enabling efficient setup and streamlined development processes.

import os
import json
import random
from dotenv import load_dotenv
from imerit_ango.sdk import SDK
from imerit_ango.models.invite import Invitation, ProjectAssignment
from imerit_ango.models.enums import OrganizationRoles, ProjectRoles
from imerit_ango.models.label_category import LabelOption, ClassificationCategory, Classification

# Organization Configurations
load_dotenv('variables.env')
api_key = os.getenv('API_KEY')

# Project Configurations
project_name = "Sample Text Classification Project"
project_description = "Created by end-to-end project preparation script"

labeler_email_list = ["user_1@sample.mail", "user_2@sample.mail"]
reviewer_email_list = ["user_3@sample.mail"]

# Initialize SDK
ango_sdk = SDK(api_key)
print("SDK initialized with API key.")

# Create Project
response = ango_sdk.create_project(name=project_name, description=project_description)
organization_id = response.get("data", {}).get("project", {}).get("organization")
project_id = response.get("data", {}).get("project", {}).get("_id")

print(f"Project '{project_name}' created successfully.")
print(f"Project ID: {project_id}, Organization ID: {organization_id}")

# Add Members to the Project
# Add Labelers
labeler_project_assignments = [ProjectAssignment(project_id=project_id, project_role=ProjectRoles.Labeler)]
labeler_invitation = Invitation(to=labeler_email_list, organization_role=OrganizationRoles.Member, project_assignments=labeler_project_assignments)
labeler_invite_response = ango_sdk.invite_members_to_org(organization_id=organization_id, invite_data=labeler_invitation)

# Add Reviewers
reviewer_project_assignments = [ProjectAssignment(project_id=project_id, project_role=ProjectRoles.Reviewer)]
reviewer_invitation = Invitation(to=reviewer_email_list, organization_role=OrganizationRoles.Member, project_assignments=reviewer_project_assignments)
reviewer_invite_response = ango_sdk.invite_members_to_org(organization_id=organization_id, invite_data=reviewer_invitation)

# The add_members_to_project function can also be used if the members are already part of the organization:
# ango_sdk.add_members_to_project(project_id=project_id, members=labeler_email_list, role=ProjectRoles.Labeler)
# ango_sdk.add_members_to_project(project_id=project_id, members=reviewer_email_list, role=ProjectRoles.Reviewer)

print(f"Added {len(labeler_email_list)} labelers to the project.")
print(f"Added {len(reviewer_email_list)} reviewers to the project.")

# Update Workflow Stages
start_stage = {"id": "Start",
               "type": "Start",
               "name": "Start",
               "next": ["Label"],
               "autoForward": False,
               "position": {"x": 0, "y": 0}}

label_stage = {"id": "Label",
               "type": "Label",
               "name": "Label",
               "next": ["Review"],
               "assignedTo": [],
               "position": {"x": 400, "y": 0}}

review_stage = {"id": "Review",
                "type": "Review",
                "name": "Review",
                "next": ["Complete", "Label"],
                "assignedTo": [],
                "position": {"x": 800, "y": 0}}

complete_stage = {"id": "Complete",
                  "type": "Complete",
                  "name": "Complete",
                  "next": [],
                  "position": {"x": 1200, "y": 0},
                  "preventRequeue": False}

stages = [start_stage, label_stage, review_stage, complete_stage]
sdk_response = ango_sdk.update_workflow_stages(project_id, stages)
print("Workflow stages updated successfully.")

# Create Category Schema
schema_id = "123456"
category = ClassificationCategory(classification=Classification.Single_dropdown,
                                  title="Choice",
                                  options=[LabelOption("First"), LabelOption("Second"), LabelOption("Third")],
                                  schemaId=schema_id,
                                  shortcutKey="1")

response = ango_sdk.create_label_set(project_id=project_id, classifications=[category])
print("Label set with classification category created successfully.")

# Create Batches
for index in range(3):
    batch_name = "Batch-" + str(index+1)
    ango_sdk.create_batch(project_id=project_id, batch_name=batch_name)
print("Batches created successfully.")

# Prepare Files for Upload
file_paths = []
external_id_list = []
for asset_index in range(30):
    external_id = str(asset_index + 1).zfill(5) + ".txt"
    content = "The quick brown fox jumps over the lazy dog."
    batch_name = "Batch-" + str(1 + asset_index // 10)

    external_id_list.append(external_id)
    file_paths.append({"data": content, "externalId": external_id, "batches": [batch_name]})

# Upload Files
ango_sdk.upload_files_cloud(project_id, file_paths)
print("Files uploaded successfully to the cloud.")

# Prepare Pre-labels
annotations = []
options = ["First", "Second", "Third"]
for external_id in external_id_list:
    answer = random.choice(options)
    annotation = {"externalId": external_id, "classifications": [{"schemaId": schema_id, "answer": answer}]}
    annotations.append(annotation)

# Import Pre-labels
ango_sdk.import_labels(project_id, annotations)
print("Pre-labels imported successfully.")

# Export Project
export_response = ango_sdk.exportV3(project_id=project_id)

# Save the export as a JSON file
with open('project_export.json', 'w') as file:
    json.dump(export_response, file, indent=4)
print("Export saved successfully.")

Clone an Existing Project’s Category Schema and Workflow

This code snippet allows you to copy an existing project's category schema and workflow using the SDK. This functionality provides users to create a new project that retains the configuration and structure of a previously established project, facilitating consistency and saving time.

import os
from dotenv import load_dotenv
from imerit_ango.sdk import SDK

load_dotenv('variables.env')

api_key = os.getenv('API_KEY')
project_id = os.getenv('PROJECT_ID')

ango_sdk = SDK(api_key)

# Get existing project's workflow and category schema
project_response = ango_sdk.get_project(project_id=project_id)

existing_project = project_response.get("data", {}).get("project", {})
copied_workflow = existing_project.get("stages", [])
copied_category_schema = existing_project.get("categorySchema", [])

# Create a new project and get its project ID
new_project_response = ango_sdk.create_project(name="New Project Name", description="New Project Description")
new_project_id = new_project_response.get("data", {}).get("project", {}).get("_id")

print("New Project ID:", new_project_id)

# Import copied category schema and workflow to the new project id
copied_category_response = ango_sdk.create_label_set(project_id=new_project_id, raw_category_schema=copied_category_schema)
copied_workflow_response = ango_sdk.update_workflow_stages(project_id=new_project_id, stages=copied_workflow)

print("Copied Category Schema Response:", copied_category_response.get("status"))
print("Copied Workflow Response:", copied_workflow_response.get("status"))
Previousupdate_organization_members_roleNextSDK Changelog

Last updated 2 months ago