SDK Cheat Sheet
  • Print
  • Share
  • Dark
    Light

SDK Cheat Sheet

  • Print
  • Share
  • Dark
    Light

The Dataloop Python dtlpy package enables a Python connection to Dataloop's environment.

Before You Begin

Please verify you have Python installed with our dtlpy package. You can find the needed information here

Repositories & Entities
In the repositories & entities section, you will be able to explore more capabilities and examples. Follow the link here.

Projects

To understand more about Dataloop's projects go to Projects.

  1. Create a project
  2. Print projects list
  3. Open project in web
project = dl.projects.create(project_name='my-new-project')
dl.projects.list().print()
project.open_in_web()

Get

  1. Get projects list
  2. Get a project by name
  3. Get a project by ID
dl.projects.list()
project = dl.projects.get(project_name='my-project')
project = dl.projects.get(project_id='my-project-id')

More about projects SDK on Project.

Datasets

To understand more about Dataloop's Datasets go to Datasets.

  1. Create a dataset
  2. Print dataset
  3. Open dataset in the web
dataset = project.datasets.create(dataset_name='my-dataset-name')
dataset.print()
dataset.open_in_web()

Get

  1. Get a projects datasets list
  2. Get the datasets by name
  3. Get the datasets by ID
datasets = project.datasets.list()
dataset = project.datasets.get(dataset_name='my-dataset-name')
dataset = project.datasets.get(dataset_id='my-dataset-id')

More about datasets SDK on Datasets.

Items

To understand more about Dataloop's Items go to Items.

  1. Upload items
  2. Upload items to a specific folder
  3. Download items
  4. Download items from a specific folder
  5. Open item in the web
  6. Clone Items
dataset.items.upload(local_path="/path/to/image.jpg")
dataset.items.upload(local_path="/path/to/image.jpg",remote_path="/path/to/dataset/folder")
item.download(local_path="/where/to/save")
item.download(local_path="/where/to/save",remote_path="/from/where/to/download")
item.open_in_web()
# dst_dataset_id - ID of your desired destination folder to clone the item at.
# with_annotations - assign - True to clone the item with it's annotations.
# assign - False True to clone the item without it's annotations.
# with_metadata  - assign  - True to clone the item with it's metadata.
#assign - False True to clone the item without it's metadata. 
item.clone(dst_dataset_id='your-dataset-id-number', with_annotations=True, with_metadata=True, with_task_annotations_status=False)

Get

  1. Get-item-by-ID
item = dataset.items.get (item_id = 'my_item_Id')

More about Items SDK on Items section.

Metadata

To understand more about Dataloop's Metadata go to Metadata.

  1. Add-metadata
item.metadata [ 'user' ] = dict ()
item.metadata [ 'user'][ 'MyKey' ] = 'MyValue'
item.update()

More about metadata SDK on Metadata.

Recipe And Ontology

To understand more about Dataloop's Recipe And Ontology go to Recipes & Ontologies.

  1. Add a label
  2. Delete labels
  3. Copy datasets ontology to a new dataset
  4. Create a new recipe
  5. Update recipe changes
  6. Delete recipe
  7. Change annotation label to a different label
dataset.add_label(label_name='person', color=(34, 6, 231), attributes=['big', 'small'])
dataset.delete_labels(label_names=['myLabel1', 'Mylabel2'])
new_dataset = project.datasets.create(
	dataset_name='new_dataset_with_ontology',
	ontology_ids=dataset.ontology_ids)
recipe = dataset.recipes.create(recipe_name='My Recipe', labels=labels))
recipe.update()
# This command is only for DELETED datasets
dataset.recipes.get(recipe_id='my_recipe_id').delete())
annotation.label = "label2"
annotation.update()

Get

  1. Get recipe by ID
  2. Get ontology by ID
  3. Get child label
recipe = dataset.recipes.get(recipe_id='my_recipe_id')
ontology= recipe.ontologies.get(ontology_id='my_ontology_id')
childLabel = ontology.labels[x].children[y].children[z]

More about Recipe SDK on Recipe.

More about Ontology SDK on Ontology.

Annotation

To understand more about Dataloop's Annotation go to Annotations.

  1. Upload annotations
  2. Update annotation changes
  3. Create annotation builder
  4. Add box annotation with label person
  5. Add point annotation with attribute
  6. Add annotations of type segmentation
  7. Add polyline annotation with label person
  8. Create a mask for semantic segmentation
  9. Upload annotations to the item
  10. Delete Annotation
annotations = item.annotations.upload(annotations=local_annotation_path)
annotation = annotation.update()
builder = item.annotations.builder()
builder.add(annotation_definition=dl.Box(top=10,left=10,bottom=100, right=100,label='person')) item.annotations.upload(builder)
builder.add(annotation_definition=dl.Point(x=80,y=80,label='label1',attributes=['attribute1']))
builder.add(annotation_definition=dl.Segmentation(geo=mask,label='label1'))
# Using the mask from previous step
builder.add(annotation_definition=dl.Polyline(geo=[[80, 40],[100, 120],[110, 130]], label='person'))
mask = np.zeros(shape=(item.height, item.width), dtype=np.uint8)
mask[50:100, 200:250] = 1
item.annotations.upload(builder)
# To upload the annotations added to the builder above
annotation = item.annotations.get(annotation_id='your-annotation-id-number')
annotation.delete()

Get

  1. Get annotations list
  2. Get-annotation by Id
annotations = item.annotations.list()
annotations = annotation = item.annotations.get(annotation_id='your-annotation-id-number')

More about Annotation SDK on the Annotations section.

Filters

To understand more about Datatloop's Filters go to Sort & Filters.

  1. Initiate Filter
  2. Filter only files
  3. Filter only annotated items
  4. Filter items name that includes 'dog'
  5. Filter items name or directory that includes 'dog'
  6. Filter specific directory
  7. Filter directory items with all subdirectories
  8. Update filtered items
  9. Delete filtered items
  10. Filter all items with the annotation type - Box
filter = dl.Filters()
filter.add(field='type', values='file')
filter.add(field='annotated', values=True)
filter.add(field='name', values='dog')
filter.add(field='filename', values='dog')
filter.add(field='dir', values='/myDirectory')
filter.add('dir', '/myDirectory', method='or')
filter.add('dir', '/myDirectory/*', method='or')
pages = dataset.items.update(filters=filter, update_values=update_values)
dataset.items.delete(filters=filter)
filters.resource = 'items'
filters.add(field='type', values='file')
filters.add_join(field='type', values='box')
list = dataset.items.list(filters=filters)

Get

  1. Get-filtered-items-list
list = dataset.items.list( filters = filter )

More about Filters SDK on Filters.

Task and Assignments

To understand more about Dataloop's tasks and assignments go to Tasks & Assignments.
Some tasks & assignments commands require datetime import

import datetime


Tasks


  1. Remove items from the task
  2. Delete a task
  3. Single status update
  4. Create a task
  5. Create QA task
  6. Add items to the task
task.remove_items( filters = filter)
task. delete()
# Mark single item as completed
item = dataset.items.get( item_id= 'my_item_id')
item.update_status( status= dl.ItemStatus.COMPLETED)
# In the same way you can update to another status
item. update_status( status= dl.ItemStatus.APPROVED)
item. update_status( status= dl.ItemStatus.DISCARDED)
task = dataset.tasks.create(
task_name= 'task_name', 
due_date = datetime.datetime(day= 1, month= 1, year= 2020).timestamp(),
assignee_ids =[ 'annotator1@dataloop.ai', 'annotator2@dataloop.ai'])
task.create_qa_task(
due_date=datetime.datetime(day= 1, month= 1, year= 2020).timestamp(),
assignee_ids=[ 'annotator1@dataloop.ai', 'annotator2@dataloop.ai']
)
filters = dl. Filters( field= 'dir', values= '/my/folder/directory')
task. add_items(
filters=filters, assignee_ids=[ 'annotator1@dataloop.ai', 'annotator2@dataloop.ai'])

Get

  1. Get task
  2. Get tasks items
  3. Get tasks list
project.tasks.get(task_id= 'my-Task-Id')
items_list= task.get_items()
task_list = project.tasks.list()


Assignments


  1. Remove items from assignments
  2. Redistribute assignments
  3. Reassign assignment
assignment. remove_items( filters= filter)
assignment. redistribute(
assignee_ids=[ 'annotator1@dataloop.ai', 'annotator2@dataloop.ai']
)
assignment.reassign(
assignee_ids['annotator1@dataloop.ai']
)

Get

  1. Get assignment
  2. Get assignment items
  3. Get the assignment list of a task
  4. Get assignments list of a project
task.assignments.get(assignment_id= 'my_assignment_Id')
items_list= assignment.get_items()
task.assignments.list()
project.assignments.list()

More about tasks and assignments SDK on the Tasks and Assignments section.

Applications

To understand more about Dataloop's Applications go to Applications.

  1. Create a modality
  2. Create a similarity
  3. Create a multiview
item1 = dataset.items.get(item_id='my_item_Id')
item2 = dataset.items.get(item_id='my_2_item_Id')
item1.modalities.create(name='my modality', modality_type=dl.ModalityTypeEnum.OVERLAY, ref=item2.id)
item1.update()
target_item = dataset.items.get(filepath='/remote/path/target_item.png')
ref_item1 = dataset.items.get(filepath='/remote/path/product1.jpeg')
ref_item2 = dataset.items.get(filepath='/remote/path/product2.jpeg')
ref_item3 = dataset.items.get(filepath='/remote/path/product3.jpeg')
similarity = dl.Similarity(name='my-product-similarity', ref=target_item.id, items=[ref_item1, ref_item2, ref_item3])
dataset.items.upload(local_path=similarity, remote_path='/products_similarities')
item = dataset.items.get(filepath='/remote/path/original_item.png')
item2 = dataset.items.get(filepath='/remote/path/second_item.png')
multiview = dl.MultiView(name='my-items-multiview', items=[item, item2])
dataset.items.upload(local_path=multiview, remote_path='/remote/path')

More about Applications SDK in the Applications section.

FaaS

To understand more about Dataloop's FaaS go to FaaS (Function as a Service).

For a guide to getting started with FaaS go to Pre-Requisites.

 Packages

To understand more about Dataloop's packages go to the package page.

  1. Delete packages
  2. Push packages
  3. Package versions
  4. Deploy package
package.delete()
# push the package again
# this action will push the new codebase and bump the version of the package
project.packages.push(src_path='/path_to_my_edited code', package_name=package.name)
# to see the versions 
	package.versions
# to see the latest version
package.version
package.deploy()

Get

  1. Get package
  2. Get packages list
  3. Open package in web
package = dl.packages.get(package_id='my_package_Id')
pack_list = dl.packages.list()
package.open_in_web()

 Services

To understand more about Dataloop's services go to the service page.

  1. Delete service
  2. Open service in web
  3. Pause and resume service
  4. Create bot
service.delete()
service.open_in_web()
# to pause the service
service.pause()
# to resume the service
service.resume()
bot = project.bots.create('bot_name')

Get

  1. Get services
  2. Get services list
service = dl.services.get(service_name="my_service_name")
dl.services.list().print()

Triggers

To understand more about Dataloop's triggers go to the trigger page.

  1. Delete triggers
  2. Trigger for Items Uploaded to Directory /Input
trigger.delete()
filters = dl.Filters(field='dir', values='/input')
trigger = service.triggers.create(function_name='run', resource=dl.TriggerResource.ITEM,
actions=dl.TriggerAction.CREATED,
name='items-created-trigger', filters=filters)

Get

  1. Get triggers
  2. Get triggers lists
service = dl.triggers.get(trigger_name="my_trigger_name")
dl.triggers.list().print()



Was This Article Helpful?