We recommend using the Encord platform to create Ontologies. The platform allows you to visualize how different elements of the Ontology are related to each other.

Ontologies are used to label your data and define how concepts are related to each other.

The following script creates an Ontology called “My test Ontology” containing an object called Cute Cat, a radio button attribute for colour, and a checklist attribute for features. Examples for bounding boxes, rotatable bounding boxes, polygons, and bitmasks are provided.

The script outputs the hash of the Ontology. The hash is used for the creation of a Project in step 3.

Ensure you replace:

  • <file-path-to-ssh-private-key> with the pull path to your private key.
  • My test Ontology with the name of your Ontology.
  • Cute Cat with the name of your Ontology class.
  • As well as any other options relevant to your Ontology.
from encord import EncordUserClient
from encord.objects import Shape, Object, Option, OntologyStructure
from encord.ontology import Ontology
from encord.objects.attributes import RadioAttribute, ChecklistAttribute



user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path='<file-path-to-ssh-private-key>'
    )

ontology_structure = OntologyStructure()

# Adding bounding box annotation
ontology_structure.add_object("Cute Cat", shape=Shape.BOUNDING_BOX)


# Adding a Classification of type radio button
classification = ontology_structure.add_classification()
cat_colour = classification.add_attribute(RadioAttribute, "colour", required=True)
cat_colour.add_option("white")
cat_colour.add_option("black")

# Adding a Classification of type check box
classification = ontology_structure.add_classification()
cat_features = classification.add_attribute(ChecklistAttribute, "features")
cat_features.add_option("soft")
cat_features.add_option("fluffy")
cat_features.add_option("friendly")

cat_ontology = user_client.create_ontology(title="My test Ontology", structure=ontology_structure)

# Prints the ontology hash
print (cat_ontology.ontology_hash)