File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,18 @@ Or from the CLI:
126126roboflow search-export " class:person" -f coco -d my-project -l ./my-export
127127```
128128
129+ ### Delete Workspace Images
130+
131+ Delete orphan images (not in any project) from your workspace:
132+
133+ ``` python
134+ workspace = rf.workspace()
135+
136+ # Delete orphan images by ID
137+ result = workspace.delete_images([" image_id_1" , " image_id_2" ])
138+ print (f " Deleted: { result[' deletedSources' ]} , Skipped: { result[' skippedSources' ]} " )
139+ ```
140+
129141### Upload with Metadata
130142
131143Attach custom key-value metadata to images during upload:
Original file line number Diff line number Diff line change @@ -239,6 +239,31 @@ def workspace_search(
239239 return response .json ()
240240
241241
242+ def workspace_delete_images (
243+ api_key : str ,
244+ workspace_url : str ,
245+ image_ids : List [str ],
246+ ) -> dict :
247+ """Delete orphan images from a workspace.
248+
249+ Args:
250+ api_key: Roboflow API key.
251+ workspace_url: Workspace slug/url.
252+ image_ids: List of image IDs to delete.
253+
254+ Returns:
255+ Parsed JSON response with deletion counts.
256+
257+ Raises:
258+ RoboflowError: On non-200 response status codes.
259+ """
260+ url = f"{ API_URL } /{ workspace_url } /images?api_key={ api_key } "
261+ response = requests .delete (url , json = {"images" : image_ids })
262+ if response .status_code != 200 :
263+ raise RoboflowError (response .text )
264+ return response .json ()
265+
266+
242267def upload_image (
243268 api_key ,
244269 project_url ,
Original file line number Diff line number Diff line change @@ -707,6 +707,29 @@ def search(
707707 continuation_token = continuation_token ,
708708 )
709709
710+ def delete_images (self , image_ids : List [str ]) -> dict :
711+ """Delete orphan images from the workspace.
712+
713+ Only deletes images not associated with any project.
714+ Images still in projects are skipped.
715+
716+ Args:
717+ image_ids: List of image IDs to delete.
718+
719+ Returns:
720+ Dict with ``deletedSources`` and ``skippedSources`` counts.
721+
722+ Example:
723+ >>> ws = rf.workspace()
724+ >>> result = ws.delete_images(["img_id_1", "img_id_2"])
725+ >>> print(result["deletedSources"])
726+ """
727+ return rfapi .workspace_delete_images (
728+ api_key = self .__api_key ,
729+ workspace_url = self .url ,
730+ image_ids = image_ids ,
731+ )
732+
710733 def search_all (
711734 self ,
712735 query : str ,
You can’t perform that action at this time.
0 commit comments