Skip to content

node.py

BaseNode (CelonisApiObject)

Base Node object to interact with Celonis Studio API.

Source code in celonis_api/studio/node.py
class BaseNode(CelonisApiObject):
    """Base Node object to interact with Celonis Studio API."""

    @property
    def url(self) -> str:
        """
        !!! api "API"
            - `/package-manager/api/nodes/{node_id}`
        """
        return f"{self.celonis.url}/package-manager/api/nodes/{self.id}"

    @property
    def attachment_url(self) -> str:
        """
        !!! api "API"
            - `/package-manager/api/attachments`
        """
        return f"{self.celonis.url}/package-manager/api/attachments"

    @property
    def viewer_attachments(self) -> 'CelonisCollection[Attachment]':
        """Get all Attachments of the Node with mode `VIEWER`.

        Returns:
            A Collection of Attachments.
        """
        return self._get_attachments(mode="VIEWER")

    @property
    def creator_attachments(self) -> 'CelonisCollection[Attachment]':
        """Get all Attachments of the Node with mode `CREATOR`.

        Returns:
            A Collection of Attachments.
        """
        return self._get_attachments(mode="CREATOR")

    @property
    def attachments(self) -> 'CelonisCollection[Attachment]':
        """Get all Attachments of the Node.

        Returns:
            A Collection of Attachments.
        """
        return self.viewer_attachments + self.creator_attachments

    def create_attachment(
        self, name: str, configuration: str, shareable: bool = True, mode: str = "CREATOR"
    ) -> 'Attachment':
        """Creates a new Attachment in the Node.

        Args:
            name: Name of attachment
            configuration: Dictionary with content of attachment
            shareable: Whether attachment is shareable or not
            mode: Attachment mode. One of [`VIEWER`, `CREATOR`]

        Returns:
            The newly created Attachment.
        """
        from pycelonis.celonis_api.studio.attachment import Attachment

        Attachment.verify_mode(mode)

        if not isinstance(configuration, str):
            configuration = json.dumps(configuration)

        payload = {
            "name": name,
            "objectId": self.id,
            "configuration": configuration,
            "shareable": shareable,
            "mode": mode,
        }
        response = self.celonis.api_request(self.attachment_url, payload)
        return Attachment(self, response)

    def _get_attachments(self, mode: str = "VIEWER") -> CelonisCollection:
        from pycelonis.celonis_api.studio.attachment import Attachment

        Attachment.verify_mode(mode)

        params = {"objectId": self.id, "mode": mode, "shareable": True}

        # Shareable and non-shareable attachments need to be fetched separately
        r_shareable = self.celonis.api_request(self.attachment_url, params=params)

        params["shareable"] = False
        r_non_shareable = self.celonis.api_request(self.attachment_url, params=params)

        return CelonisCollection([Attachment(self, data) for data in r_shareable + r_non_shareable])

attachment_url: str property readonly

API

  • /package-manager/api/attachments

attachments: CelonisCollection[Attachment] property readonly

Get all Attachments of the Node.

Returns:

Type Description
CelonisCollection[Attachment]

A Collection of Attachments.

creator_attachments: CelonisCollection[Attachment] property readonly

Get all Attachments of the Node with mode CREATOR.

Returns:

Type Description
CelonisCollection[Attachment]

A Collection of Attachments.

url: str property readonly

API

  • /package-manager/api/nodes/{node_id}

viewer_attachments: CelonisCollection[Attachment] property readonly

Get all Attachments of the Node with mode VIEWER.

Returns:

Type Description
CelonisCollection[Attachment]

A Collection of Attachments.

create_attachment(self, name, configuration, shareable=True, mode='CREATOR')

Creates a new Attachment in the Node.

Parameters:

Name Type Description Default
name str

Name of attachment

required
configuration str

Dictionary with content of attachment

required
shareable bool

Whether attachment is shareable or not

True
mode str

Attachment mode. One of [VIEWER, CREATOR]

'CREATOR'

Returns:

Type Description
Attachment

The newly created Attachment.

Source code in celonis_api/studio/node.py
def create_attachment(
    self, name: str, configuration: str, shareable: bool = True, mode: str = "CREATOR"
) -> 'Attachment':
    """Creates a new Attachment in the Node.

    Args:
        name: Name of attachment
        configuration: Dictionary with content of attachment
        shareable: Whether attachment is shareable or not
        mode: Attachment mode. One of [`VIEWER`, `CREATOR`]

    Returns:
        The newly created Attachment.
    """
    from pycelonis.celonis_api.studio.attachment import Attachment

    Attachment.verify_mode(mode)

    if not isinstance(configuration, str):
        configuration = json.dumps(configuration)

    payload = {
        "name": name,
        "objectId": self.id,
        "configuration": configuration,
        "shareable": shareable,
        "mode": mode,
    }
    response = self.celonis.api_request(self.attachment_url, payload)
    return Attachment(self, response)

Node (BaseNode, CelonisApiObjectChild)

Node object to interact with Celonis Studio API.

Source code in celonis_api/studio/node.py
class Node(BaseNode, CelonisApiObjectChild):
    """Node object to interact with Celonis Studio API."""

    def __init__(self, parent: CelonisApiObject, celonis: 'Celonis', id_or_data: typing.Union[str, typing.Dict]):
        self._logger = celonis._logger
        BaseNode.__init__(self, celonis, id_or_data)
        CelonisApiObjectChild.__init__(self, parent, id_or_data, celonis)

    @property
    def _parent_class(self):
        return BaseNode