Tag¶
-
class Tag(meta, value=
None, sly_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Bases:
KeyObjectTag attached to image or label; meta + value. Immutable.
- Parameters:
- meta¶
TagMetaobject with tag metadata (name, value type).- value : str or int or float, optional¶
Tag value; type must match
TagMeta.value_type. Date tag values must be ISO datetime strings.- sly_id : int, optional¶
Server-side tag ID.
- labeler_login : str, optional¶
Login of user who created the tag.
- updated_at : str, optional¶
Last modification timestamp (ISO format).
- created_at : str, optional¶
Creation timestamp (ISO format).
- Raises:
ValueError – If meta is None or value is incompatible with
TagMeta.value_type.- Usage Example:
import supervisely as sly meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE) tag_dog = sly.Tag(meta_dog) meta_cat = sly.TagMeta('cat', sly.TagValueType.ANY_STRING) tag_cat = sly.Tag(meta_cat, value="Fluffy") colors = ["brown", "white", "black"] meta_coat = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=colors) tag_coat = sly.Tag(meta_coat, value="white") meta_date = sly.TagMeta('reviewed_at', sly.TagValueType.DATE) tag_date = sly.Tag(meta_date, value="2026-04-23T15:15:48")
Methods
Clone makes a copy of Tag with new fields, if fields are given, otherwise it will use original Tag fields.
Convert a json dict to Tag.
Displays information about Tag's name and value in string format.
Get header of the table with tags.
Get row with tag properties.
Get TagMeta key value.
Convert the Tag to a json dict.
Attributes
General information about Tag.
Name property.
Tag value.
- classmethod from_json(data, tag_meta_collection)[source]¶
Convert a json dict to Tag. Read more about Supervisely format.
- Parameters:
- Returns:
Tag object
- Return type:
- Usage Example:
import supervisely as sly meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) tag_metas = sly.TagMetaCollection([meta_dog]) data = { "name": "dog", "value": "Husky", "labelerLogin": "admin", "updatedAt": "2021-01-22T19:37:50.158Z", "createdAt": "2021-01-22T18:00:00.000Z" } tag_dog = sly.Tag.from_json(data, tag_metas)
- classmethod get_header_ptable()[source]¶
Get header of the table with tags.
- Returns:
List of table header values.
- Return type:
List[str]
- Usage Example:
import supervisely as sly header = sly.Tag.get_header_ptable() print(header) # Output: ['Name', 'Value type', 'Value']
-
clone(meta=
None, value=None, sly_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Clone makes a copy of Tag with new fields, if fields are given, otherwise it will use original Tag fields.
- Parameters:
- meta=
None¶ General information about Tag.
- sly_id : int, optional¶
Tag ID in Supervisely server.
- labeler_login : str, optional¶
Login of user who created
Tag.- updated_at : str, optional¶
Date and Time when Tag was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.
- created_at : str, optional¶
Date and Time when Tag was created. Date Format is the same as in “updated_at” parameter.
- meta=
- Returns:
New instance of Tag object
- Return type:
- Usage Example:
import supervisely as sly #Original Tag weather_conditions = ["Sunny", "Cloudy", "Snowy", "Foggy", "Rainy"] meta_weather = sly.TagMeta("weather", sly.TagValueType.ONEOF_STRING, possible_values=weather_conditions) tag_weather = sly.Tag(meta_weather, value="Sunny") # Let's create some more tags by cloning our original Tag # Remember that Tag class object is immutable, and we need to assign new instance of Tag to a new variable clone_weather_1 = tag_weather.clone(value="Snowy") clone_weather_2 = tag_weather.clone(value="Cloudy") clone_weather_3 = tag_weather.clone(value="Rainy")
- get_row_ptable()[source]¶
Get row with tag properties.
- Returns:
List of tag properties.
- Return type:
List[str]
- Usage Example:
import supervisely as sly weather_conditions = ["Sunny", "Cloudy", "Snowy", "Foggy", "Rainy"] meta_weather = sly.TagMeta("weather", sly.TagValueType.ONEOF_STRING, possible_values=weather_conditions) tag_weather = sly.Tag(meta_weather, value="Sunny") row = tag_weather.get_row_ptable() print(row) # Output: ['weather', 'oneof_string', 'Sunny']
- key()[source]¶
Get TagMeta key value.
- Returns:
TagMeta key value
- Return type:
- Usage Example:
import supervisely as sly weather_conditions = ["Sunny", "Cloudy", "Snowy", "Foggy", "Rainy"] meta_weather = sly.TagMeta("weather", sly.TagValueType.ONEOF_STRING, possible_values=weather_conditions) tag_weather = sly.Tag(meta_weather, value="Sunny") key = tag_weather.key() print(key) # Output: weather
- to_json()[source]¶
Convert the Tag to a json dict. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
- Usage Example:
import supervisely as sly # Tag with all fields filled in meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) tag_dog = sly.Tag( meta=meta_dog, value="Husky", sly_id=38456, labeler_login="admin", updated_at="2021-01-22T19:37:50.158Z", created_at="2021-01-22T18:00:00.000Z" ) tag_dog_json = tag_dog.to_json() print(tag_dog_json) # Notice that sly_id won't print # Output: { # "name": "dog", # "value": "Husky", # "labelerLogin": "admin", # "updatedAt": "2021-01-22T19:37:50.158Z", # "createdAt": "2021-01-22T18:00:00.000Z" # }
- property meta : supervisely.annotation.tag_meta.TagMeta¶
General information about Tag. When creating a new Tag, it’s value is automatically cross-checked against
TagValueTypeto make sure that value is valid.- Returns:
TagMeta object
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.NONE) tag_dog = sly.Tag(meta_dog) # Our TagMeta has value type 'NONE', if we try to add value to our Tag, "ValueError" error will be raised tag_dog = sly.Tag(meta_dog, value="Husky") # Output: ValueError: Tag dog can not have value Husky
- property name : str¶
Name property.
- Returns:
Name
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) tag_dog = sly.Tag(meta_dog, value="Husky") print(tag_dog.name) # Output: "dog"
- property value : str¶
Tag value. Return type depends on
TagValueType. Date tag values are returned as ISO datetime strings.- Returns:
Tag value
- Return type:
- Usage Example:
meta_dog = sly.TagMeta('dog', sly.TagValueType.ANY_STRING) tag_dog = sly.Tag(meta_dog, value="Husky") meta_age = sly.TagMeta('age', sly.TagValueType.ANY_NUMBER) tag_age = sly.Tag(meta_age, value=9) colors = ["Black", "White", "Golden", "Brown"] meta_color = sly.TagMeta('coat color', sly.TagValueType.ONEOF_STRING, possible_values=colors) tag_color = sly.Tag(meta_color, value="White") meta_date = sly.TagMeta('reviewed_at', sly.TagValueType.DATE) tag_date = sly.Tag(meta_date, value="2026-04-23T15:15:48") type(tag_dog.value) # 'str' type(tag_age.value) # 'int' type(tag_color.value) # 'str' type(tag_date.value) # 'str'