Skip to content

Add workspace image deletion (DATAMAN-162)#442

Merged
digaobarbosa merged 5 commits intomainfrom
dataman-162-delete-images-workspace
Mar 3, 2026
Merged

Add workspace image deletion (DATAMAN-162)#442
digaobarbosa merged 5 commits intomainfrom
dataman-162-delete-images-workspace

Conversation

@digaobarbosa
Copy link
Contributor

@digaobarbosa digaobarbosa commented Mar 2, 2026

Description

Add Workspace.delete_images() method to delete orphan images from a workspace via the API.

Why: Users need a way to clean up unused images that are not associated with any project, reducing storage and improving workspace organization.

Implementation:

  • Added workspace_delete_images() API adapter that calls DELETE /workspace/{url}/images
  • Added Workspace.delete_images() method that accepts a list of image IDs
  • API returns deletedSources and skippedSources counts (skipped images are those still in projects)

Type of change

  • New feature

How has this change been tested?

Unit tests
Manual tests:

"""Delete all orphan images matching a workspace-level search query.

Usage:
    python tests/manual/demo_search_delete.py
"""

from roboflow import Roboflow

QUERY = "project:false"
PAGE_SIZE = 100
DELETE_BATCH_SIZE = 1000
DRY_RUN = False  # set to False to actually delete

WORKSPACE_SLUG = "rodrigo"


def main():
    rf = Roboflow()
    workspace = rf.workspace(WORKSPACE_SLUG)

    print(f"Workspace: {workspace.url}")
    print(f"Query: {QUERY}")
    print(f"Dry run: {DRY_RUN}")
    print()

    # Collect all matching image IDs.
    # When deleting (not dry run), skip continuation tokens because deleted
    # images shift the result set — always re-search from page 1.
    all_ids = []
    token = None
    while True:
        page = workspace.search(
            QUERY,
            page_size=PAGE_SIZE,
            fields=["filename"],
            continuation_token=token,
        )
        results = page.get("results", [])
        if not results:
            break
        total = page.get("total", "?")
        all_ids.extend(img["id"] for img in results)
        print(f"Found {len(all_ids)}/{total} images so far...")
        token = page.get("continuationToken")
        if not token:
            break

    print(f"\nTotal images matching '{QUERY}': {len(all_ids)}")

    if not all_ids:
        print("Nothing to delete.")
        return

    if DRY_RUN:
        print("\n[DRY RUN] Would delete the above images. Set DRY_RUN=False to proceed.")
        return

    for i in range(0, len(all_ids), DELETE_BATCH_SIZE):
        batch = all_ids[i : i + DELETE_BATCH_SIZE]
        print(f"Deleting batch {i // DELETE_BATCH_SIZE + 1} ({len(batch)} images)...")
        result = workspace.delete_images(batch)
        print(f"  deleted={result.get('deletedSources')}, skipped={result.get('skippedSources')}")

    print(f"\nDone. Deleted {len(all_ids)} images.")


if __name__ == "__main__":
    main()

Will the change affect Universe?

No - this is SDK-only functionality.

Any specific deployment considerations

N/A

Docs

  • Docs updated in docs/index.md with usage example
  • Changelog updated with feature description

@digaobarbosa digaobarbosa requested a review from a team March 2, 2026 14:42
@digaobarbosa digaobarbosa self-assigned this Mar 2, 2026
@digaobarbosa digaobarbosa merged commit dfa6d6e into main Mar 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants