SDK – Useful Snippets

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

Environmental Variables

Snippets in this page make the assumption that you have your API key and other variables set as environmental variables.

To set environmental variables, install the python-dotenv package from pip by running

pip install python-dotenv

in your Python environment.

Then, create a file called .env in your environment's root folder. The contents of this .env file will look like this:

API_KEY=00af1132-0558-4ec7-93e3-46826a455ac0
PROJECT_ID=1233453123dsfdf012

In your Python scripts, then, import the package by using

from dotenv import load_dotenv
import os

and load the environmental variables by running load_dotenv() before using the variables in your script.

You will then be able to access your environmental variables by using os.getenv("VAR_NAME"), like so:

API_KEY = os.getenv("API_KEY")

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

from imerit_ango.sdk import SDK # Minimum version 1.3.12
from dotenv import load_dotenv
import os
load_dotenv()

# Import the API Key and Project ID from the .env file
apiKey = os.getenv('api_key')
projectId = os.getenv('project_id')

# Create an instance of the SDK, using the API Key
ango_sdk = SDK(apiKey)

# Get Existing Project Response
existing_project_response = \
    ango_sdk\
        .get_project(
            project_id=projectId
        )

# Copy the Workflow from the Existing Project
copied_workflow = \
    existing_project_response\
        .get("data")\
        .get("project")\
        .get("stages")

# Copy the Category Schema from the Existing Project
copied_categories = \
    existing_project_response\
        .get("data")\
        .get("project")\
        .get("categorySchema")

# Create new project and get the project id     
new_project_id = \
    ango_sdk\
        .create_project(
            "New Project", 
            "with copied category schema and workflows"
            )\
            .get("data")\
            .get("project")\
            .get("_id")
            
print("New Project ID: ", new_project_id)

# Import copied category schema to the new project id
copied_cat_resp = \
    ango_sdk\
        .create_label_set(
            project_id=new_project_id, 
            raw_category_schema = copied_categories
        )
        
print("Copied Category Schema Response: ", copied_cat_resp.get("status"))

# Import copied workflow to the new project id
copied_workflow_resp = \
    ango_sdk\
        .update_workflow_stages(
            project_id=new_project_id,
            stages=copied_workflow
        )
        
print("Copied Workflow Response: ", copied_workflow_resp.get("status"))

Last updated