Submit your innovative use case or inspiring success story to the 2023 Dataiku Frontrunner Awards! LET'S GO

is it possible to bulk delete projects in a folder in the UI?

kathyqingyuxu
is it possible to bulk delete projects in a folder in the UI?

Hey Dataiku community,

 

Hope all is well!

 

We have a use case where we save the App instances of our applications as a recipe in order to test running the application and have the most recent run saved for reference. However, we would like to now delete the old application as a recipe app instances and only keep the must recently run instance in the App Instance folder. Is it possible to bulk delete these projects or do we have to go in and delete 1 at a time? Is there any way to leverage DSS API's to auto delete these extraneous projects after lets say a month of inactivity?

 

Any suggestions are helpful, not sure if others have a similar use case, thanks!

 

Best,

Kathy

0 Kudos
3 Replies
SarinaS
Dataiker

Hi @kathyqingyuxu,

There isn't currently a way to bulk delete projects in the UI.  At the moment there is also no a way to retrieve a project's last modified date from the API. 

If you can read the directory structure for projects, you could delete from a project folder based on the last time the project was modified on the filesystem, with something like this: 

 

import os 
import dataiku
from datetime import datetime, timedelta
# to obtain your project path
datadir = os.environ['DIP_HOME']

# get project folder
client = dataiku.api_client()
root_folder = client.get_root_project_folder()

# go through all of the projects in your project folder 
for project_key in folder.list_project_keys():
    project_location = datadir + '/config/projects/' + project_key 
    # get the last modified date based on the project folder last modified date 
    last_modified = datetime.fromtimestamp(os.path.getmtime(project_location))
    # compare to 30 days ago 
    older_than_30_days = datetime.now() - timedelta(days=30)
    if last_modified < older_than_30_days:
        # get and delete the project 
        project = client.get_project(project_key)
        # goodbye 
        res = project.delete()

 

Alternatively, if your naming convention for the projects is consistent, you may be able to simply delete based on the project name (i.e. if projects are named along the lines of project v1, project v2, project v3 for example). 

I hope that helps,
Sarina 

 

SarinaS
Dataiker

Hi @kathyqingyuxu

To update: the project last modification date is available starting in DSS 9.0.2 from the get_timeline() method as well (the method is currently not yet documented).  Here is an example given the original use case: 

import os 
import json
import dataiku
from datetime import datetime, timedelta
# to obtain your project path

# get project folder
client = dataiku.api_client()
root_folder = client.get_root_project_folder()

# go through all of the projects in your project folder 
for project_key in root_folder.list_project_keys():
    # get project 
    project = client.get_project(project_key)
    last_modified = project.get_timeline()['lastModifiedOn']
    formatted = datetime.fromtimestamp(last_modified/1000)
    # compare to 30 days ago 
    older_than_30_days = datetime.now() - timedelta(days=30)
    if formatted < older_than_30_days:
        # get and delete the project 
        project = client.get_project(project_key)
        # goodbye 
        res = project.delete()

 

Thanks,
Sarina

0 Kudos
cinderUARK
Level 2

Sarina,

Should the code be run on DSS or Linux?

Thanks.

0 Kudos