Renaming a dataset using Python API

Solved!
stephanetram
Level 1
Renaming a dataset using Python API

Dear Community,

I am trying to rename a dataset from a project using the python API using the rename method from the dataikuapi.dss.dataset.DSSDataset class (https://developer.dataiku.com/latest/api-reference/python/datasets.html#dataikuapi.dss.dataset.DSSDa...) but I get an

AttributeError: 'DSSDataset' object has no attribute 'rename'

How can I rename a dataset using the python API?

Here is the code I am trying:

 

 

client = dataiku.api_client()
project = client.get_default_project()
dataset_infos = [(dataset['smartName'], dataset['type']) for dataset in project.list_datasets()]
for dataset_name, dataset_type in dataset_infos:
    name = re.sub(r'LAYER\d{1}_?', '', dataset_name)
    if name[:5]!='temp_':
        name = 'temp_'+name
    if name!=dataset_name:
        dataset = project.get_dataset(dataset_name)
        dataset.rename(name)

 

 

 

Many Thanks for your help

0 Kudos
1 Solution
Turribeach

What version of Dataiku do you have? The rename datasets API only got added in 12.5.0 which is only a week old:

https://doc.dataiku.com/dss/latest/release_notes/12.html#apis-and-coding-experience

 

View solution in original post

0 Kudos
3 Replies
Turribeach

What version of Dataiku do you have? The rename datasets API only got added in 12.5.0 which is only a week old:

https://doc.dataiku.com/dss/latest/release_notes/12.html#apis-and-coding-experience

 

0 Kudos
stephanetram
Level 1
Author

Oh that's why, it seems like my version is 12.2.3, I did not think the method was that new 🙂

Thank you so much.

 

 

0 Kudos
Turribeach

PS: Tested your code in v12.5.0 and it works fine, the dataset is indeed renamed.

0 Kudos

Labels

?
Labels (3)
A banner prompting to get Dataiku