Add Metadata to Items
  • Print
  • Share
  • Dark
    Light

Add Metadata to Items

  • Print
  • Share
  • Dark
    Light

 Highlighted text require your input 

Prep

import dtlpy as dl
import numpy as np
from PIL import Image
if dl.token_expired():
    dl.login()
# Get project and dataset
project = dl.projects.get(project_name='project_name')
dataset = project.datasets.get(dataset_name='dataset_name')
❗️ Note

When you add new metadata to the same item it overwrites the old metadata.
You can overwrite it by writing in a "list" data type and adding new metadata to the list

Item


 Add metadata to Items user metadata


# upload and claim item
item = dataset.items.upload(local_path=r'C:/home/project/images/item.mimetype')
# or get item
item = dataset.items.get(item_id='write-your-id-number')
# modify metadata
item.metadata['user'] = dict()
item.metadata['user']['MyKey'] = 'MyValue'
# update and reclaim item
item = item.update()
# item in platform should have section 'user' in metadata with field 'MyKey' and value 'MyValue'


 Metadata Data Types 


String

You can add string metadata.

item.metadata['user']['MyKey'] = 'MyValue'

Number

You can add a number value metadata.

item.metadata['user']['MyKey'] = 3

Boolean

You can add boolean metadata (True/False)

item.metadata['user']['MyKey'] = True

Null

You can add metadata with no information.

item.metadata['user']['MyKey'] = None

List

You can add metadata of a list(can contain elements of different types).

item.metadata['user']['MyKey'] = ["A",2,False]

Add to list

You can add new metadata to your list without losing your old one.

item.metadata['user']['MyKey'].append(3)
item = item.update()
Was This Article Helpful?