Introduction¶
In this tutorial, you will dive deeper into objects of the Celonis Data Integration service. More specifically, you will learn how to use PyCelonis to interact with data pools, data models, and data jobs. These three objects serve as places to organize other Celonis objects, such as tables and tasks, and are thus a good starting point when working on a new PyCelonis project.
Prerequisites¶
To follow this tutorial, you should have set up an app inside the ML Workbench and should have PyCelonis installed. Further, you should know how to establish a connection to the Celonis API and how to perform basic interactions with Celonis objects, such as create, get, update, sync, and delete. If you don't know how to do this, please complete the Celonis Basics tutorial first.
Tutorial¶
1. Import PyCelonis and connect to Celonis API¶
from pycelonis import get_celonis
celonis = get_celonis(permissions=False)
[2023-06-26 13:09:49,426] INFO: No `base_url` given. Using environment variable 'CELONIS_URL' [2023-06-26 13:09:49,427] INFO: No `api_token` given. Using environment variable 'CELONIS_API_TOKEN'
[2023-06-26 13:09:49,513] WARNING: KeyType is not set. Defaulted to 'APP_KEY'.
[2023-06-26 13:09:49,515] INFO: Initial connect successful! PyCelonis Version: 2.3.0
2. Create a data pool¶
When we work on a new PyCelonis project and don't have any Data Integration objects inside our EMS, the first step will be to create a new data pool. Data pools are the main structural element of the Data Integration service and are used to organize other Celonis objects, such as data models, tables, data jobs, and tasks. It is required to have a data pool in place in order to create other Data Integration objects.
data_pool = celonis.data_integration.create_data_pool("PyCelonis Tutorial Pool")
data_pool
[2023-06-26 13:09:49,528] INFO: Successfully created data pool with id '6c178afe-21e2-4f77-b862-e37653ae0b2e'
DataPool(id='6c178afe-21e2-4f77-b862-e37653ae0b2e', name='PyCelonis Tutorial Pool')
3. Add Data Integration objects (data model and job) into the data pool¶
Once we have a data pool in place, we can start adding other Data Integration objects to it. For now, we will create a new (empty) data model and a new (empty) data job into the data pool. These two objects will be populated with tasks and tables in subsequent tutorials.
data_model = data_pool.create_data_model("PyCelonis Tutorial Model")
data_model
[2023-06-26 13:09:49,543] INFO: Successfully created data model with id '0caea823-104c-4555-9b58-678a727c62b2'
DataModel(id='0caea823-104c-4555-9b58-678a727c62b2', name='PyCelonis Tutorial Model', pool_id='6c178afe-21e2-4f77-b862-e37653ae0b2e')
data_job = data_pool.create_job("PyCelonis Tutorial Job")
data_job
[2023-06-26 13:09:49,558] INFO: Successfully created job with id 'cde6d25f-337a-4320-8565-acdbba93a99b'
Job(id='cde6d25f-337a-4320-8565-acdbba93a99b', name='PyCelonis Tutorial Job', data_pool_id='6c178afe-21e2-4f77-b862-e37653ae0b2e')
We can always verify which objects are currently in our data pool by calling the get_<object>s()
method:
data_pool.get_data_models()
[ DataModel(id='0caea823-104c-4555-9b58-678a727c62b2', name='PyCelonis Tutorial Model', pool_id='6c178afe-21e2-4f77-b862-e37653ae0b2e') ]
data_pool.get_jobs()
[ Job(id='cde6d25f-337a-4320-8565-acdbba93a99b', name='PyCelonis Tutorial Job', data_pool_id='6c178afe-21e2-4f77-b862-e37653ae0b2e') ]
4. Change Data Integration objects¶
As known from the Celonis Basics tutorial, we can always update, sync, and delete objects inside Data Integration. For now, we will stick to updating the names of the different objects and pushing the changes into the Celonis EMS:
data_pool.name = "PyCelonis Tutorial Data Pool"
data_pool.update()
data_model.name = "PyCelonis Tutorial Data Model"
data_model.update()
data_job.name = "PyCelonis Tutorial Data Job"
data_job.update()
[2023-06-26 13:09:49,596] INFO: Successfully updated data pool with id '6c178afe-21e2-4f77-b862-e37653ae0b2e' [2023-06-26 13:09:49,601] INFO: Successfully updated data model with id '0caea823-104c-4555-9b58-678a727c62b2' [2023-06-26 13:09:49,605] INFO: Successfully updated job with id 'cde6d25f-337a-4320-8565-acdbba93a99b'
5. Access Data Model with only use permissions¶
In general, accessing a data model through the data pool requires admin permissions for the pool. To access a data model with only use permissions for that data model it can directly be instantiated:
from pycelonis.ems.data_integration.data_model import DataModel
data_model = DataModel(client=celonis.client, id=data_model.id, pool_id=data_pool.id)
data_model.sync()
Conclusion¶
Congratulations! You have learned how to use PyCelonis to create data pools, data models, and data jobs inside Data Integration. These objects will serve as places to organize your other Data Integration objects throughout the subsequent tutorials. In the next tutorial Data Upload, you will learn how to populate two of these objects, namely data pools and data models, by creating tables and uploading data from your local Python project into the EMS.