2424 get_annotation_classes_id_to_name , get_annotation_classes_name_to_id ,
2525 search_annotation_classes
2626)
27- from .project_api import get_project_and_folder_metadata
27+ from .project_api import get_project_and_folder_metadata , get_project_metadata_bare
2828
2929logger = logging .getLogger ("superannotate-python-sdk" )
3030
3131_api = API .get_instance ()
3232
3333
34+ def _get_project_root_folder_id (project ):
35+ """Get root folder ID
36+ Returns
37+ -------
38+ int
39+ Root folder ID
40+ """
41+ params = {'team_id' : project ['team_id' ]}
42+ response = _api .send_request (
43+ req_type = 'GET' , path = f'/project/{ project ["id" ]} ' , params = params
44+ )
45+ if not response .ok :
46+ raise SABaseException (response .status_code , response .text )
47+
48+ response = response .json ()
49+
50+ return response ['folder_id' ]
51+
52+
3453def search_images (
3554 project ,
3655 image_name_prefix = None ,
@@ -63,7 +82,7 @@ def search_images(
6382 if project_folder is not None :
6483 project_folder_id = project_folder ["id" ]
6584 else :
66- project_folder_id = None
85+ project_folder_id = _get_project_root_folder_id ( project )
6786
6887 result_list = []
6988 params = {
@@ -79,7 +98,7 @@ def search_images(
7998 total_images = 0
8099 while True :
81100 response = _api .send_request (
82- req_type = 'GET' , path = '/images' , params = params
101+ req_type = 'GET' , path = '/images-folders ' , params = params
83102 )
84103 if not response .ok :
85104 raise SABaseException (
@@ -115,6 +134,83 @@ def process_result(x):
115134 return result_list
116135
117136
137+ def search_images_all_folders (
138+ project ,
139+ image_name_prefix = None ,
140+ annotation_status = None ,
141+ return_metadata = False
142+ ):
143+ """Search images by name_prefix (case-insensitive) and annotation status in
144+ project and all of its folders
145+
146+ :param project: project name
147+ :type project: str
148+ :param image_name_prefix: image name prefix for search
149+ :type image_name_prefix: str
150+ :param annotation_status: if not None, annotation statuses of images to filter,
151+ should be one of NotStarted InProgress QualityCheck Returned Completed Skipped
152+ :type annotation_status: str
153+
154+ :param return_metadata: return metadata of images instead of names
155+ :type return_metadata: bool
156+
157+ :return: metadata of found images or image names
158+ :rtype: list of dicts or strs
159+ """
160+ project = get_project_metadata_bare (project )
161+ team_id , project_id = project ["team_id" ], project ["id" ]
162+ if annotation_status is not None :
163+ annotation_status = common .annotation_status_str_to_int (
164+ annotation_status
165+ )
166+
167+ project_folder_id = _get_project_root_folder_id (project )
168+
169+ result_list = []
170+ params = {
171+ 'team_id' : team_id ,
172+ 'project_id' : project_id ,
173+ 'annotation_status' : annotation_status ,
174+ 'offset' : 0 ,
175+ 'folder_id' : project_folder_id
176+ }
177+ if image_name_prefix is not None :
178+ params ['name' ] = image_name_prefix
179+ total_images = 0
180+ while True :
181+ response = _api .send_request (
182+ req_type = 'GET' , path = '/images' , params = params
183+ )
184+ if not response .ok :
185+ raise SABaseException (
186+ response .status_code , "Couldn't search images " + response .text
187+ )
188+ response = response .json ()
189+ results_images = response ["data" ]
190+ for r in results_images :
191+ if return_metadata :
192+ result_list .append (r )
193+ else :
194+ result_list .append (r ["name" ])
195+
196+ total_images += len (results_images )
197+ if response ["count" ] <= total_images :
198+ break
199+ params ["offset" ] = total_images
200+
201+ if return_metadata :
202+
203+ def process_result (x ):
204+ x ["annotation_status" ] = common .annotation_status_int_to_str (
205+ x ["annotation_status" ]
206+ )
207+ return x
208+
209+ return list (map (process_result , result_list ))
210+ else :
211+ return result_list
212+
213+
118214def get_image_metadata (project , image_names , return_dict_on_single_output = True ):
119215 """Returns image metadata
120216
0 commit comments