View Metadata guide page for metadata schema definitions and details.

Create metadata schema

You can create custom metadata schema fields that will be accessible in your organization. The metadata schema name must be unique in your organization.
This list of customer metadata schema kinds you can create are:

  • DataRowMetadataKind.string
  • DataRowMetadataKind.number
  • DataRowMetadataKind.datetime
  • DataRowMetadataKind.embedding
  • DataRowMetadataKind.enum
from labelbox import Client
from labelbox.schema.data_row_metadata import DataRowMetadataKind
import datetime

client = Client(api_key="LABELBOX_API_KEY")
metadata_ontology = client.get_data_row_metadata_ontology()

# create a custom metadata schema (string, number, datetime, embedding)
metadata_schema = metadata_ontology.create_schema(name="metadata_name", kind=DataRowMetadataKind.string)
# You can create other metadata schema kinds, just change the kind to be one of: 
# DataRowMetadataKind.number, DataRowMetadataKind.datetime, DataRowMetadataKind.embedding

# Enum metadata schema is a bit different since it contains options.
# create an Enum metadata with options
enum_schema = metadata_ontology.create_schema(name="enum_metadata_name", kind=DataRowMetadataKind.enum,
                                       options=["option 1", "option 2"])

Get metadata schema

# you can look up a schema by name. 
metadata_schema = metadata_ontology.get_by_name("tag")
metadata_schema = metadata_ontology.get_by_name("enum_metadata_name")

# check the schema 
schema_id = metadata_schema.uid

Update metadata schema

You can update any custom metadata schema's name. However, the type cannot be modified. You also cannot modify the names of reserved fields.

# update a metadata schema's name
metadata_schema = metadata_ontology.update_schema(name="metadata_name", new_name="metadata

# update an Enum metadata schema's name, similar to other metadata schema types
enum_schema = metadata_ontology.update_schema(name="enum_metadata_name", new_name="enum_metadata_name_updated")

# In order to update an Enum metadata schema option's name, you need to call update_enum_option function.
enum_schema = metadata_ontology.update_enum_option(name="enum_metadata_name_option_updated", option="option 1",
                                            new_option="option 3")

Delete metadata schema

You can delete a metadata schema by name.

status = metadata_ontology.delete_schema(
# returns True if successfully deleted