cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

python databricks sdk get object path from id

BriGuy
New Contributor II

when using the databricks SDK to get permissions of objects we get 

inherited_from_object=['/directories/1636517342231743']

from what I can see the workspace list and get_status methods only work with the actual path.  Is there a way to look up that directory path from the ID?

Regards

3 REPLIES 3

CURIOUS_DE
Contributor III

Did you try with the GET /api/2.0/workspace/get-status endpoint
Solution 1:-
Brute Force with workspace.list() and Recursion - This can be achieved using get_Stataus() method.

Let me know if you require code snippet.

Databricks Solution Architect

BriGuy
New Contributor II

I'd appreciate a snippet if you have one.

CURIOUS_DE
Contributor III

@BriGuy  Here I have small code snippet which we have used. Hope this works well with you

from databricks.sdk import WorkspaceClient

w = WorkspaceClient()

def find_path_by_object_id(target_id, base_path="/"):
    items = w.workspace.list(path=base_path)
    for item in items:
        try:
            status = w.workspace.get_status(item.path)
            if str(status.object_id) == str(target_id):
                return item.path
            if item.object_type == "DIRECTORY":
                found = find_path_by_object_id(target_id, item.path)
                if found:
                    return found
        except Exception:
            continue
    return None

target_object_id = "<yourObejctID>"
resolved_path = find_path_by_object_id(target_object_id)

print(f"Path for ID {target_object_id} is: {resolved_path}")
Databricks Solution Architect

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now