Skip to content

Index

Module to interact with Knowledge Models.

This module contains class to interact with Knowledge Models in Studio.

Typical usage example:

```python
knowledge_model = package.get_knowledge_model(
    ANALYSIS_ID
)
knowledge_model = package.create_knowledge_model(
    content
)
knowledge_model.delete()
```

KnowledgeModel ΒΆ

Bases: ContentNode

Knowledge model object to interact with knowledge model specific studio endpoints.

permissions class-attribute instance-attribute ΒΆ

permissions = Field(None, alias='permissions')

tenant_id class-attribute instance-attribute ΒΆ

tenant_id = Field(None, alias='tenantId')

id instance-attribute ΒΆ

id

Id of studio content node.

key instance-attribute ΒΆ

key

Key of studio content node.

name class-attribute instance-attribute ΒΆ

name = Field(None, alias='name')

root_node_key instance-attribute ΒΆ

root_node_key

Key of root content node.

base class-attribute instance-attribute ΒΆ

base = Field(None, alias='base')

asset_type class-attribute instance-attribute ΒΆ

asset_type = Field(None, alias='assetType')

node_type class-attribute instance-attribute ΒΆ

node_type = Field(None, alias='nodeType')

parent_node_key class-attribute instance-attribute ΒΆ

parent_node_key = Field(None, alias='parentNodeKey')

parent_node_id class-attribute instance-attribute ΒΆ

parent_node_id = Field(None, alias='parentNodeId')

invalid_content class-attribute instance-attribute ΒΆ

invalid_content = Field(None, alias='invalidContent')

serialized_content instance-attribute ΒΆ

serialized_content

Serialized content of content node.

serialization_type class-attribute instance-attribute ΒΆ

serialization_type = Field(None, alias='serializationType')

draft_id class-attribute instance-attribute ΒΆ

draft_id = Field(None, alias='draftId')

working_draft_id class-attribute instance-attribute ΒΆ

working_draft_id = Field(None, alias='workingDraftId')

activated_draft_id class-attribute instance-attribute ΒΆ

activated_draft_id = Field(None, alias='activatedDraftId')

show_in_viewer_mode class-attribute instance-attribute ΒΆ

show_in_viewer_mode = Field(None, alias='showInViewerMode')

public_available class-attribute instance-attribute ΒΆ

public_available = Field(None, alias='publicAvailable')

embeddable class-attribute instance-attribute ΒΆ

embeddable = Field(None, alias='embeddable')

root_node_id instance-attribute ΒΆ

root_node_id

Id of of root content node.

order class-attribute instance-attribute ΒΆ

order = Field(None, alias='order')

source class-attribute instance-attribute ΒΆ

source = Field(None, alias='source')

asset_metadata_transport class-attribute instance-attribute ΒΆ

asset_metadata_transport = Field(
    None, alias="assetMetadataTransport"
)

space_id instance-attribute ΒΆ

space_id

Id of space where content node is located.

change_date class-attribute instance-attribute ΒΆ

change_date = Field(None, alias='changeDate')

created_by_id class-attribute instance-attribute ΒΆ

created_by_id = Field(None, alias='createdById')

creation_date class-attribute instance-attribute ΒΆ

creation_date = Field(None, alias='creationDate')

created_by_name class-attribute instance-attribute ΒΆ

created_by_name = Field(None, alias='createdByName')

updated_by class-attribute instance-attribute ΒΆ

updated_by = Field(None, alias='updatedBy')

root class-attribute instance-attribute ΒΆ

root = Field(None, alias='root')

asset class-attribute instance-attribute ΒΆ

asset = Field(None, alias='asset')

object_id class-attribute instance-attribute ΒΆ

object_id = Field(None, alias='objectId')

root_with_key instance-attribute ΒΆ

root_with_key

identifier class-attribute instance-attribute ΒΆ

identifier = Field(None, alias='identifier')

client class-attribute instance-attribute ΒΆ

client = Field(..., exclude=True)

from_transport classmethod ΒΆ

from_transport(client, content_node_transport)

Creates high-level content node object from given ContentNodeTransport.

Parameters:

  • client (Client) –

    Client to use to make API calls for given content node.

  • content_node_transport (ContentNodeTransport) –

    ContentNodeTransport object containing properties of content node.

Returns:

  • ContentNode –

    A ContentNode object with properties from transport and given client.

sync ΒΆ

sync()

Syncs content node properties with EMS.

delete ΒΆ

delete()

Deletes content node.

copy_to ΒΆ

copy_to(
    destination_package,
    destination_team_domain,
    overwrite=False,
    delete_source=False,
    **kwargs
)

Copies a content node to the specified domain and package in the same realm (ex. eu-1).

Parameters:

  • destination_package (Package) –

    The Package object to copy the asset to.

  • destination_team_domain (str) –

    The of the destination team url: https://..celonis.cloud/

  • overwrite (bool, default: False ) –

    If true, any node with the same key will be overwritten. If false, a PyCelonisNodeAlreadyExistsError will be raised.

  • delete_source (bool, default: False ) –

    If true, deletes the node from the source. If false, keeps the source node.

  • **kwargs (Any, default: {} ) –

    Additional parameters set for ContentNodeCopyTransport

Returns:

Examples:

Copy a package:

package = space.get_package(<package_id>)
new_package = space.create_package("NEW_PACKAGE")
new_package.publish()
copied_package_transport = package.copy_to(new_package, <destination_team_domain>)

Copy a package asset:

new_package = space.create_package("NEW_PACKAGE")
copied_analysis_transport = analysis.copy_to(
    new_package, <destination_team_domain>
)

is_package staticmethod ΒΆ

is_package(content_node_transport)

Returns whether content node transport is package.

Parameters:

Returns:

  • bool –

    Boolean if transport is package.

is_folder staticmethod ΒΆ

is_folder(content_node_transport)

Returns whether content node transport is package.

Parameters:

Returns:

  • bool –

    Boolean if transport is folder.

is_analysis staticmethod ΒΆ

is_analysis(content_node_transport)

Returns whether content node transport is analysis.

Parameters:

Returns:

  • bool –

    Boolean if transport is analysis.

is_knowledge_model staticmethod ΒΆ

is_knowledge_model(content_node_transport)

Returns whether content node transport is knowledge model.

Parameters:

Returns:

  • bool –

    Boolean if transport is knowledge model.

is_action_flow staticmethod ΒΆ

is_action_flow(content_node_transport)

Returns whether content node transport is action flow.

Parameters:

Returns:

  • bool –

    Boolean if transport is action flow.

is_view staticmethod ΒΆ

is_view(content_node_transport)

Returns whether content node transport is view.

Parameters:

Returns:

  • bool –

    Boolean if transport is view.

is_simulation staticmethod ΒΆ

is_simulation(content_node_transport)

Returns whether content node transport is simulation.

Parameters:

Returns:

  • bool –

    Boolean if transport is simulation.

is_skill staticmethod ΒΆ

is_skill(content_node_transport)

Returns whether content node transport is skill.

Parameters:

Returns:

  • bool –

    Boolean if transport is skill.

update ΒΆ

update(
    with_autogenerated_data_model_data=True,
    with_variable_replacement=True,
    **kwargs
)

Pushes local changes of knowledge model serialized_content attribute to EMS.

This only pushes changes made to serialized_content. Other attributes of the knowledge model will not be updated. Therefore, any changes have to be made by adjusting serialized_content.

create_kpi ΒΆ

create_kpi(id_, display_name, pql, **kwargs)

Creates new kpi with id, display name, and pql in given knowledge model.

Parameters:

  • id_ (str) –

    Id of new kpi.

  • display_name (str) –

    Display name of new kpi.

  • pql (str) –

    PQL query of new kpi.

  • **kwargs (Any, default: {} ) –

    Additional parameters set for KpiMetadata object.

Returns:

  • Kpi –

    A Kpi object for newly created kpi.

Examples:

Create a kpi:

kpi = knowledge_model.create_kpi(
    id_="TEST_KPI",
    display_name="Test KPI",
    pql='COUNT("BSEG"."BELNR")',
)

get_kpi ΒΆ

get_kpi(id_)

Gets kpi with given id.

Parameters:

  • id_ (str) –

    Id of kpi.

Returns:

  • Kpi –

    A Kpi object for kpi with given id.

get_kpis ΒΆ

get_kpis()

Gets all kpis of knowledge model.

Returns:

create_variable ΒΆ

create_variable(id_, display_name, value, **kwargs)

Creates new variable with id, display name, and pql in given knowledge model.

Parameters:

  • id_ (str) –

    Id of new variable.

  • display_name (str) –

    Display name of new variable.

  • value (str) –

    Value of new variable.

  • **kwargs (Any, default: {} ) –

    Additional parameters set for VariableMetadata object.

Returns:

  • Variable –

    A Variable object for newly created variable.

Examples:

Create a variable:

variable = knowledge_model.create_variable(
    id_="TEST_VARIABLE",
    display_name="Test Variable",
    value="Test Value",
)

get_variable ΒΆ

get_variable(id_)

Gets variable with given id.

Parameters:

  • id_ (str) –

    Id of variable.

Returns:

  • Variable –

    A Variable object for variable with given id.

get_variables ΒΆ

get_variables()

Gets all variables of knowledge model.

Returns:

create_filter ΒΆ

create_filter(id_, display_name, pql, **kwargs)

Creates new filter with id, display name, and pql in given knowledge model.

Parameters:

  • id_ (str) –

    Id of new filter.

  • display_name (str) –

    Display name of new filter.

  • pql (str) –

    PQL query of new filter.

  • **kwargs (Any, default: {} ) –

    Additional parameters set for FilterMetadata object.

Returns:

  • Filter –

    A Filter object for newly created filter.

Examples:

Create a filter:

filter = knowledge_model.create_filter(
    id_="TEST_FILTER",
    display_name="Test FILTER",
    pql='FILTER "BSEG"."BELNR" = \'TEST\'',
)

get_filter ΒΆ

get_filter(id_)

Gets filter with given id.

Parameters:

  • id_ (str) –

    Id of filter.

Returns:

  • Filter –

    A Filter object for filter with given id.

get_filters ΒΆ

get_filters()

Gets all filters of knowledge model.

Returns:

get_content ΒΆ

get_content(
    with_variable_replacement=True,
    with_autogenerated_data_model_data=True,
    with_default_values=True,
    validate_pql=True,
    with_unknown_variables_validation=True,
)

Returns final read only content of knowledge model (including inherited properties).

Parameters:

  • with_variable_replacement (bool, default: True ) –

    Specifies if variables are replaced by their values in knowledge model.

  • with_autogenerated_data_model_data (bool, default: True ) –

    Specifies whether auto generated KPIs and records for data model should be added to content.

  • with_default_values (bool, default: True ) –

    Specifies if default values are added to content.

  • validate_pql (bool, default: True ) –

    Specifies if PQLs in knowledge model are validated.

  • with_unknown_variables_validation (bool, default: True ) –

    Specifies if unknown variables are validated.

Returns:

Examples:

Extract data based on PQLs from knowledge model:

from pycelonis.pql import (
    PQL,
    PQLColumn,
)

record = knowledge_model.get_content().records.find_by_id(
    "ACTIVITIES"
)
attribute = record.attributes.find_by_id(
    "ACTIVITY_EN"
)

query = (
    PQL()
    + attribute.get_column()
)

(
    data_query,
    query_environment,
) = knowledge_model.resolve_query(
    query
)
df = data_model.export_data_frame(
    data_query,
    query_environment,
)

resolve_query ΒΆ

resolve_query(query, draft=True, **kwargs)

Returns Data Query and Query environment for a knowledge model.

Warning

The method knowledge_model.resolve_query has been deprecated and will be removed in future versions. Please use SaolaPy from now on to export PQL queries:

import pycelonis.pql as pql
from pycelonis.pql.saola_connector import (
    KnowledgeModelSaolaConnector,
)

df = pql.DataFrame.from_pql(
    query,
    saola_connector=KnowledgeModelSaolaConnector(
        data_model,
        knowledge_model,
    ),
)
df.head()

Use this method to resolve queries that are based on Knowledge Model content. The returned DataQuery and QueryEnvironment can than be used to query data via DataModel.export_data_frame.

Parameters:

  • query (PQL) –

    PQL query to be resolved.

  • draft (bool, default: True ) –

    If true, uses draft of knowledge model, if false uses published version.

  • **kwargs (Any, default: {} ) –

    Key word arguments are passed to get_content function.

Returns:

Examples:

Extract data based on PQLs from knowledge model:

from pycelonis.pql import (
    PQL,
    PQLColumn,
)

record = knowledge_model.get_content().records.find_by_id(
    "ACTIVITIES"
)
attribute = record.attributes.find_by_id(
    "ACTIVITY_EN"
)

query = (
    PQL()
    + attribute.get_column()
)

(
    data_query,
    query_environment,
) = knowledge_model.resolve_query(
    query
)
df = data_model.export_data_frame(
    data_query,
    query_environment,
)