@@ -1187,9 +1187,9 @@ def create_project(
11871187 settings : List [Setting ] = None ,
11881188 classes : List [AnnotationClassEntity ] = None ,
11891189 workflows : Any = None ,
1190- instructions_link : str = None ,
1191- workflow : str = None ,
1192- form : dict = None ,
1190+ instructions_link : Optional [ str ] = None ,
1191+ workflow : Optional [ str ] = None ,
1192+ form : Optional [ dict ] = None ,
11931193 ):
11941194 """Creates a new project in the team. For Multimodal projects, you must provide a valid form object,
11951195 which serves as a template determining the layout and behavior of the project's interface.
@@ -2054,15 +2054,18 @@ def update_annotation_class(
20542054 name : NotEmptyStr ,
20552055 attribute_groups : List [dict ],
20562056 ):
2057- """Updates an existing annotation class by submitting a full, updated attribute_groups payload.
2058- You can add new attribute groups, add new attribute values, rename attribute groups, rename attribute values,
2059- delete attribute groups, delete attribute values, update attribute group types, update default attributes,
2060- and update the required state.
2057+ """
2058+ Updates an existing annotation class by submitting a full, updated attribute_groups payload. You can add new attribute groups, add new attribute values, rename attribute groups, rename attribute values, delete attribute groups, delete attribute values, update attribute group types, update default attributes, and update the required state.
2059+ This function does not support Multimodal projects.
2060+
2061+ Warning:
2062+ Use update_annotation_class() With Extreme Caution
2063+ The update_annotation_class() method replaces the entire attribute group structure of the annotation class.
2064+ Any attribute group or attribute group ID not included in the payload will be permanently deleted.
2065+ Any attribute value or attribute ID not included in the payload will be permanently deleted.
2066+ Existing annotations that reference removed attribute groups or attributes will lose their associated values.
20612067
2062- .. warning::
2063- This operation replaces the entire attribute group structure of the annotation class.
2064- Any attribute groups or attribute values omitted from the payload will be permanently removed.
2065- Existing annotations that reference removed attribute groups or attributes will lose their associated values.
2068+ This action cannot be undone.
20662069
20672070 :param project: The name or ID of the project.
20682071 :type project: Union[str, int]
@@ -2090,18 +2093,69 @@ def update_annotation_class(
20902093 Request Example:
20912094 ::
20922095
2093- # Retrieve existing annotation class
2094- annotation_class = sa_client.get_annotation_classes(project="classes", annotation_class="test_class")
2095-
2096- # Rename attribute value and add a new one
2097- annotation_class["attribute_groups"][0]["attributes"][0]["name"] = "Brand Alpha"
2098- annotation_class["attribute_groups"][0]["attributes"].append({"name": "Brand Beta"})
2099-
2100- sa.update_annotation_classes(
2101- project="test_set_folder_status",
2102- name="test_class",
2103- attribute_groups=annotation_class["attribute_groups"]
2104- )
2096+ annotation_class = sa_client.get_annotation_class(project='classes', annotation_class="Example Class")
2097+ attribute_groups = annotation_class["attribute_groups"]
2098+
2099+ # Add a NEW Attribute to Existing Group
2100+ for group in attribute_groups:
2101+ if group["id"] == 5624734:
2102+ group["attributes"].append({
2103+ "name": "blue"
2104+ })
2105+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2106+
2107+ # Rename the Existing Attribute
2108+ for group in attribute_groups:
2109+ if group["id"] == 5624734:
2110+ for attr in group["attributes"]:
2111+ if attr["id"] == 11394966:
2112+ attr["name"] = "yellow"
2113+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2114+
2115+ # Rename the Attribute Group
2116+ for group in attribute_groups:
2117+ if group["id"] == 5624734:
2118+ group["name"] = "color"
2119+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2120+
2121+ # Add a Completely New Attribute Group
2122+ attribute_groups.append({
2123+ "group_type": "text",
2124+ "name": "comment",
2125+ "isRequired": False,
2126+ "attributes": []
2127+ })
2128+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2129+
2130+ # Delete the Attribute Group
2131+ attribute_groups = [group for group in attribute_groups if group["id"] != 5659666]
2132+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2133+
2134+ # Delete the Attribute
2135+ for group in attribute_groups:
2136+ if group["id"] == 5624734:
2137+ group["attributes"] = [attr for attr in group["attributes"]if attr["id"] != 11394966]
2138+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2139+
2140+ # Set Default Value
2141+ for group in attribute_groups:
2142+ if group["id"] == 5624734: # color group
2143+ for attr in group["attributes"]:
2144+ if attr["id"] == 11438900:
2145+ attr["default"] = 1
2146+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2147+
2148+ # Make Group Required
2149+ for group in attribute_groups:
2150+ if group["id"] == 5624734:
2151+ group["isRequired"] = True
2152+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
2153+ # Change Group Type (Multiple Selection (Checklist) → Single Selection (Radio))
2154+ for group in attribute_groups:
2155+ if group["id"] == 5624734:
2156+ group["group_type"] = "radio"
2157+ group["default_value"] = None # radio requires single default or None
2158+ sa_client.update_annotation_class(project='classes', name="Example Class", attribute_groups=attribute_groups)
21052159
21062160 """
21072161 project = self .controller .get_project (project )
0 commit comments