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.

Create a new project with the category schema and workflow of an existing one

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"))

Last updated