Intro to Python SDK

Let's try Supervisely SDK for Python and create your first python script for Supervisely automation.

In this example we will show you how it is easy to communicate with your Supervisely instance (Community or your private Enterprise installation) from python code. The tutorial illustrates basic upload-download scenario:

  • create project and dataset on server

  • upload image

  • programmatically create annotation (two bounding boxes and tag) and upload it to image

  • download image and annotation

You can try this example for yourself: VSCode project config, original image, and python script for this tutorial are ready on GitHub.

Watch the video tutorial here:


Run the following command (learn more here)

pip install supervisely

Input data

Python code

Import and authentication

Import Supervisely, initialize API with your credentials and test authentication (learn the basics of authentication here). In this example, we use the server address of Community Edition. Change it if you have a private instance of Supervisely.

import json
import supervisely as sly

api = sly.Api(server_address="", token="4r47N...xaTatb")

my_teams =
print(f"I'm a member of {len(my_teams)} teams")

# get first team and workspace
team = my_teams[0]
workspace = api.workspace.get_list([0]

Create project on server

Let's create an empty project animals with one dataset cats, then one class cat of shape Rectangle and one tag scene with string value and upload them into the project. Now we can use created classes and tags for labeling.

project = api.project.create(, "animals", change_name_if_conflict=True)
dataset = api.dataset.create(, "cats", change_name_if_conflict=True)
print(f"Project {} with dataset {} are created")

cat_class = sly.ObjClass("cat", sly.Rectangle, color=[0, 255, 0])
scene_tag = sly.TagMeta("scene", sly.TagValueType.ANY_STRING)
project_meta = sly.ProjectMeta(obj_classes=[cat_class], tag_metas=[scene_tag])

api.project.update_meta(, project_meta.to_json())

Upload image

Let's upload local image images/my-cats.jpg to dataset.

image_info = api.image.upload_path(, name="my-cats.jpg", path="images/my-cats.jpg")

Create annotation and upload to image

cat1 = sly.Label(sly.Rectangle(top=875, left=127, bottom=1410, right=581), cat_class)
cat2 = sly.Label(sly.Rectangle(top=549, left=266, bottom=1500, right=1199), cat_class) 
tag = sly.Tag(scene_tag, value="indoor")

ann = sly.Annotation(img_size=[1600, 1200], labels=[cat1, cat2], img_tags=[tag])
api.annotation.upload_ann(, ann)

Download data

img = api.image.download_np(  # RGB ndarray
print("image shape (height, width, channels)", img.shape)

ann_json = api.annotation.download_json( 
print("annotaiton:\n", json.dumps(ann_json, indent=4))

You can download the whole script using this link


In less than 50 lines of code (including lots of comments) you can easily automate Supervisely using Python and integrate it with your software stack.

That’s just a taste of what you can do with the Supervisely SDK for Python. For more, take a look at the reference and Supervisely Annotation JSON format.

Last updated