Skip to content

Commit 1bb0c93

Browse files
committed
Delete images from workspace
1 parent 0e985d5 commit 1bb0c93

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

docs/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ Or from the CLI:
126126
roboflow 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

131143
Attach custom key-value metadata to images during upload:

roboflow/adapters/rfapi.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
242267
def upload_image(
243268
api_key,
244269
project_url,

roboflow/core/workspace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)