Palantir Foundry - File and Folder names list

785 Views Asked by At

I am looking for a code to get list of files and folder names in palantir foundry directory on pyspark. So if i provide a foundry path location i need the list of file and folder names using pyspark code.

Can someone help me regarding this..?

1

There are 1 best solutions below

0
nicornk On

This function is something we use internally to query the child objects of a folder. Note, client side pagination is not implemented:

def get_child_objects_of_folder(self, folder_rid: str, foundry_hostname: str, auth_token: str) -> list:
    """
    Returns the child objects of a compass folder.
    Args:
        folder_rid: Compass folder rid,
        e.g. ri.compass.main.folder.f549ae09-9534-44c7-967a-6c86b2339231

    Returns: (list of dict's) information about child objects

    """
    response = requests.get(
        f"https://{foundry_hostname}/compass/api/folders/{folder_rid}/children",
        headers={
            "content-type": "application/json",
            "authorization": f"Bearer {auth_token}",
        },
    )
    response.raise_for_status()
    response_as_json = response.json()
    if (
        "nextPageToken" in response_as_json
        and response_as_json["nextPageToken"] is not None
    ):
        raise ValueError(
            f"{folder_rid} has too many children "
            f"({len(response_as_json['values'])}), "
            f"paging currently not implemented."
        )
    return response.json()["values"]