Skip to content

space.py

Space (CelonisApiObject)

Space object to interact with Celonis Studio API.

Source code in celonis_api/studio/space.py
class Space(CelonisApiObject):
    """Space object to interact with Celonis Studio API."""

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

    @property
    def packages(self) -> 'CelonisCollection[Package]':
        """Get all Packages of the Space.

        !!! api "API"
            - `GET: /package-manager/api/nodes/tree?spaceId={self.id}`

        Returns:
            Collection of Packages.
        """
        response = self.celonis.api_request(f"{self.celonis.url}/package-manager/api/nodes/tree?spaceId={self.id}")
        return CelonisCollection(
            [Package(self, self.celonis, data) for data in response if data["nodeType"] == 'PACKAGE']
        )

    def create_package(self, name: str, key: str = None, package_type: str = "APP") -> Package:
        """Creates a new Package.

        !!! api "API"
            - `POST: /package-manager/api/nodes`
                ```json
                {
                    "key": key or name,
                    "name": name,
                    "nodeType": "PACKAGE",
                    "serializedContent": f"packageType: {package_type}\nvariables: []\ndependencies: []\n",
                    "spaceId": self.id,
                }
                ```

        Args:
            name: Name of the package.
            key: Key of the package, if left blank defaults to name of the Package.
            package_type: Package type. One of [`APP`, `LIBRARY`, `INSTRUMENT`].

        Returns:
            The newly created Package object.
        """
        if package_type.upper() not in Package.TYPES:
            raise PyCelonisTypeError(f"package_type needs to be one of {', '.join(Package.TYPES)}")

        payload = {
            "key": key or name,
            "name": name,
            "nodeType": "PACKAGE",
            "serializedContent": f"packageType: {package_type}\nvariables: []\ndependencies: []\n",
            "spaceId": self.id,
        }
        response = self.celonis.api_request(
            f"{self.celonis.url}/package-manager/api/nodes", payload, method=HttpMethod.POST
        )

        return Package(self, self.celonis, response["id"])

    def delete(self):
        """Deletes the Space and all child objects.

        !!! api "API"
            - `POST: /package-manager/api/spaces/delete/{space_id}`
                ```json
                {
                    "id": self.id,
                    "name": self.name,
                }
                ```
        """
        payload = {
            "id": self.id,
            "name": self.name,
        }
        self.celonis.api_request(f"{self.celonis.url}/package-manager/api/spaces/delete/{self.id}", payload)

packages: CelonisCollection[Package] property readonly

Get all Packages of the Space.

API

  • GET: /package-manager/api/nodes/tree?spaceId={self.id}

Returns:

Type Description
CelonisCollection[Package]

Collection of Packages.

url: str property readonly

API

  • /package-manager/api/spaces/{space_id}

create_package(self, name, key=None, package_type='APP')

Creates a new Package.

    !!! api "API"
        - `POST: /package-manager/api/nodes`
            ```json
            {
                "key": key or name,
                "name": name,
                "nodeType": "PACKAGE",
                "serializedContent": f"packageType: {package_type}

variables: [] dependencies: [] ", "spaceId": self.id, } ```

    !!! args
        name: Name of the package.
        key: Key of the package, if left blank defaults to name of the Package.
        package_type: Package type. One of [`APP`, `LIBRARY`, `INSTRUMENT`].

    !!! returns
        The newly created Package object.
Source code in celonis_api/studio/space.py
def create_package(self, name: str, key: str = None, package_type: str = "APP") -> Package:
    """Creates a new Package.

    !!! api "API"
        - `POST: /package-manager/api/nodes`
            ```json
            {
                "key": key or name,
                "name": name,
                "nodeType": "PACKAGE",
                "serializedContent": f"packageType: {package_type}\nvariables: []\ndependencies: []\n",
                "spaceId": self.id,
            }
            ```

    Args:
        name: Name of the package.
        key: Key of the package, if left blank defaults to name of the Package.
        package_type: Package type. One of [`APP`, `LIBRARY`, `INSTRUMENT`].

    Returns:
        The newly created Package object.
    """
    if package_type.upper() not in Package.TYPES:
        raise PyCelonisTypeError(f"package_type needs to be one of {', '.join(Package.TYPES)}")

    payload = {
        "key": key or name,
        "name": name,
        "nodeType": "PACKAGE",
        "serializedContent": f"packageType: {package_type}\nvariables: []\ndependencies: []\n",
        "spaceId": self.id,
    }
    response = self.celonis.api_request(
        f"{self.celonis.url}/package-manager/api/nodes", payload, method=HttpMethod.POST
    )

    return Package(self, self.celonis, response["id"])

delete(self)

Deletes the Space and all child objects.

API

  • POST: /package-manager/api/spaces/delete/{space_id}
    {
        "id": self.id,
        "name": self.name,
    }
    
Source code in celonis_api/studio/space.py
def delete(self):
    """Deletes the Space and all child objects.

    !!! api "API"
        - `POST: /package-manager/api/spaces/delete/{space_id}`
            ```json
            {
                "id": self.id,
                "name": self.name,
            }
            ```
    """
    payload = {
        "id": self.id,
        "name": self.name,
    }
    self.celonis.api_request(f"{self.celonis.url}/package-manager/api/spaces/delete/{self.id}", payload)