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.DSSDataset.rename) 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
Best Answer
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
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
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,160 Neuron
PS: Tested your code in v12.5.0 and it works fine, the dataset is indeed renamed.
-
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.