Python : Celonis - How to get the all project IDs

Hello Team,

I am trying to connect to Celonis via Python and would like to perform reload from cache for data models from python script.
How can i read all project ids and load the corresponding data models using “reload from cache”?

Thanks,
Parimala N

Hi Parimala,

similar to this question you can use the following code to iterate through the projects and reload all datamodels:

projects = Project.load_all()
for p in projects:
	print(p.id)
	for dm in p.folder.get_available_datamodels():
		print('       '+ dm.name)
		dm.reload(from_cache=True)

This will reload all datamodels you have. You probably want to add an if-condition to the loop to restrict the datamodels to be loaded based on the project ID.

Best,
David

Thanks David for giving an idea to proceed.

I am trying to load for one project and its data model from cache for testing , if it works fine i would like to proceed to load for all projects and its respective datamodels.

Currently i am getting “RuntimeError: cannot schedule new futures after shutdown”

Code :

        p = Project("<project_id>")
        for dm in p.folder.get_available_datamodels():
	    print('       '+ dm.name) /* Till here its working*/
	    dm.reload(from_cache=True) / error occurring here/

Thanks,
Parimala

Hello,

I just tried the code, and couldn’t reproduce. Which Celonis Version are you using?

Also, you could try adding .result() to the last line, so

dm.reload(from_cache=True).result()

Maybe this helps?

Best,
David

Hello,

I am using Celonis 4.5 version.
Tried using the result(), still issue exists.
Attached the code file and error.Import_Cache_Code.docx (12.1 KB)

Thanks,
Parimala

But loading just a single Datamodel works, right?
Can you try to add time.sleep(0.5) after the dm.reload(from_cache=True).result() line:

        p = Project("<project_id>")
        for dm in p.folder.get_available_datamodels():
	    print('       '+ dm.name)
	    dm.reload(from_cache=True).result()
	    time.sleep(0.5)

You might need to import time before.
If that doesn’t fix the problem, can you please write a ticket to the celonis service desk?

Thanks and BR,
David

Hello David,

Loading single model is not working from cache.
I tried to import time and added sleep time still facing same issue as “RuntimeError: cannot schedule new futures after shutdown”. Any other way to figure out to proceed for test case.

Thanks,
Parimala

Hello Parimala,

could you please install a new version of the celonis-tools by executing

pip install --extra-index-url https://pypi.celonis.cloud -U --pre celonis-tools

you will need to remove the .result() part to make it work. You can also remove the time.sleep().

Please let me know if this works!

Thanks,
David