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

Hi david,

Its working after installing new version of celonis tools.
How can i know whether data model loaded successfully from cache or source if i want to read it from python. is there any predefined function for this to get the load status?
I have tried with datamodel.status, which is not working.Would be great if you provide specifically if any.
Thanks in advance.

Thanks,
Parimala

Hi,

Great!

Yes, you can call dm.status to get the status of the datamodel. Included there is an error flag which marks if the load was successful and also includes other infos like the error message, if there is any.

Best,
David

Hi,

After running dm.status , in JSON result output i see " ‘errorMessage’: None," , But load is failed. How can I read the error Message.

I am trying to read status as in below code:

a=dm.reload(from_cache=True)
print(a)

if( not a[‘error’] and a[‘tablesLoaded’]):
print("model " + dm.name + “loaded sucessfully from Cache”)

But for few data models , condition is not working , is there anything I am missing to do valid check on data model status. Please assist on this.

Regards,
Parimala