python databricks sdk get object path from id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 04:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 05:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2025 06:53 AM
I'd appreciate a snippet if you have one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2025 12:27 PM
@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}")