The source code for the Encord SDK is public.
View Label Details
The following code shows how to view details for label rows (data units). This example only prints thelabel_hash and the date labels were created, but more details are available. To see all available label details, see the LabelRowV2 SDK Reference.
Label Basics
Key methods for working with labels in the SDK are initialise_labels() and save():initialise_labels(): Downloads the existing label information. This method must be called before performing any label operations using the SDK.save(): Saves any changes made to the labels back to the server. This method must be called after completing label operations to ensure updates are stored.
Create Object Labels
Single Image or Frame
Creating and saving object instances is essential when importing annotations into Encord. Specify the label shape, the coordinates, and which frames the shape should occur on. For modalities without frames such as single images, ensure thatframes=0.
Bounding box
Bounding box
The following code adds a bounding box for the Ontology class
person to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Rotatable bounding box
Rotatable bounding box
The following code adds a rotatable bounding box for the Ontology class
person to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Polygon
Polygon
The following example adds a polygon for the Ontology class
person to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Polyline
Polyline
The following example adds a polyline label for the Ontology class
snake to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Keypoint
Keypoint
The following example adds a bounding box for the Ontology class
star to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Bitmask
Bitmask
See our dedicated documentation to learn how to import Bitmask annotations into Encord.The following example adds a bitmask for the Ontology class
Lung to the first label row (data unit) of the specified Project. The object label is applied to the first frame.Multiple Frames
When working with videos, an object instance may appear in multiple frames. For example, when tracking a car across frames, create a single object instance and place it on each frame where it appears. If objects are unique to each frame, create a new instance for each frame.Bounding Box
Bounding Box
The following example places bounding boxes on frames 3,4 and 5 of the first label row (data unit) in a Project. Each bounding box is a
person object label.Rotatable Bounding Box
Rotatable Bounding Box
The following example places rotatable bounding boxes on frames 3,4 and 5 of the first label row (data unit) in a Project. Each rotatable bounding box is a
person object label.Polygon
Polygon
The following example places polygons on frames 3,4 and 5 of the first label row (data unit) in a Project. Each polygon is a
person object label.Polyline
Polyline
The following example places polylines on frames 3,4 and 5 of the first label row (data unit) in a Project. Each polyline is a
snake object label.Keypoint
Keypoint
The following example places keypoints on frames 3,4 and 5 of the first label row (data unit) in a Project. Each keypoint is a
star object label.Bitmask
Bitmask
The following example places bitmasks on frames 3,4 and 5 of the first label row (data unit) in a Project. Each bitmask is a
lung object label.Edit labels
Editing labels after they have been created involves the following steps: The script below shows how to update the location of an object’s bounding box, and attribute values. Ensure you substitute the following values:<private_key_path>with the full path to your private key.<project_hash>with the name of the project you want to update labels in.<file_name>with the name of the file / data unit you want to edit labels for.<object_name>with the name of the object.<attribute_name>with the name of the attribute.<option_name>with the name of the radio button option of the attribute.
View Object Instances
The following example prints all object instance for a specified label row (data unit).Create Classifications
Radio Button Classification
Radio Button Classification
Checklist Classification
Checklist Classification
The following example assumes the Ontology includes a checklist classification field named
What is visible?. In this example, the text attribute for the first label row (data unit) in the project is set to Monkey and Parrot on the first frame.Add attribute
The following scripts assume that an object label calledWhale has already been created. Each script retrieves the object instance and searches for the corresponding attribute within the Project’s Ontology. For radio buttons and checklists, the scripts also identify the relevant attribute options.
- Replace
<private_key_path>with the key to your private key for authentication. - Replace
<project_hash>with the hash of your Project. - Replace
Whalewith the name of your object. - Replace the attributes and attribute answers to suit your needs.
Nested Attributes
Radio button attributes can be nested. The following script assumes that an object label calledWhale has already been created. To learn how to create a new object instance see the section here.
Radio attributes can also be nested under classifications. See here to learn how to do this.
Nested Radio Attributes
Relation Attributes
Relation attributes work the exact same way as text attributes, except that when an attribute is marked as Relation the string#relation is appended to the attribute name.
Learn more about relation attributes in Encord here.
Relation Attributes
Dynamic Attributes
Dynamic attributes are attributes for object instances where the answer can change in each frame. You can read more about them here. The following example adds bounding boxes for the labelPerson to three frames. It then sets the dynamic attribute Position to Walking and Standing. Wherever you can set frames, you can either set a single integer, a Range, or a list of Ranges.

