How to : Duplicate an Ontology in Labelbox Using SDK: A Step-by-Step Script

Hello Community!

We’re excited to share a Google Colab script, utilizing the Labelbox SDK, enables the duplication of an existing ontology, creating a new version that is completely independent from the original.

Here’s the key functionality: The script ensures that the features in the new ontology are not connected to those in the original. Therefore, any modifications made to the features in the new ontology will not affect the original ontology or its features.

How This Benefits You: This functionality is key when you need a replica of an existing ontology but want to avoid linking feature changes to the original. It’s ideal for project-specific customizations, ensuring that modifications stay confined to the new ontology.

How to Use the Script:

  1. Visit the Google Colaboratory Script for Independent Ontology Duplication.
  2. Input your Labelbox API key and the ID of the ontology you wish to duplicate.
  3. Execute the script to create your new, independent ontology in Labelbox.

Here is the full script:

import labelbox as lb

# Your API key
client = lb.Client(API_KEY)

# Retrieve the ontology using its unique ID
ontology = client.get_ontology('YOUR_ONTOLOGY_ID_HERE')

# Normalize the ontology to extract its JSON structure
ontology_json = ontology.normalized

# Function to remove IDs from the old ontology JSON
def remove_ids_from_ontology(ontology_json):
    # Remove the top-level ID and name from the ontology to avoid conflicts in the new ontology
    ontology_json.pop('id', None)
    ontology_json.pop('name', None)

    # Nested function to recursively remove IDs from ontology features
    def remove_feature_ids(features):
        for feature in features:
            # Remove IDs specific to features
            feature.pop('schemaNodeId', None)
            feature.pop('featureSchemaId', None)

            # Recursively apply to nested features
            if 'classifications' in feature:
            if 'options' in feature:

    # Apply the ID removal process to all categories of features

# Apply the ID removal process to the old ontology JSON

# Create a new ontology with the modified JSON
client.create_ontology(name=f"copy_of_{}", normalized=ontology_json)

In future we might plan to solve it through UI itself.

We hope this helps in your ontology creation. Should you have any further questions, please feel free to reach out to our support team. Happy Annotating!

Sravani Mutta