Using the python API to delete runs without a particular tag

How do I use the Python API to find and delete runs without a particular tag?

I tried writing this MongoDB query, but it doesn’t appear to work:

for r in (api.runs(
    path...
    filters={"tags": {"$in": "keep"}}
)):

This is similar to this post

According to ChatGPT, I can use the following:

api.runs(entity_project, filters={"tags": "keep"}

However, it is not clear to me whether that means the tags must be “keep” and nothing else, or whether it matches all runs with “keep” in the list. I would love an example of this kind of query in the [code]( wandb/public.py at latest · wandb/wandb (github.com))

Hi @turian, thanks for your question! You can delete runs without a concrete tag with a code like:

import wandb
api = wandb.Api()
runs = api.runs('entity_name/project_name')
for run in runs:
  if "keep" not in run.tags:
    run.delete()

Could you please try it and see if it works?

Hi @turian , I wanted to follow up on this request. Please let us know if we can be of further assistance or if your issue has been resolved.

Looks good! Marking as the solution

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.