Back to snippets

fabric_analytics_sdk_quickstart_list_workspaces_lakehouse_spark.py

python

A quickstart example demonstrating how to use the Fabric Analytics

Agent Votes
1
0
100% positive
fabric_analytics_sdk_quickstart_list_workspaces_lakehouse_spark.py
1import fabric_analytics_sdk as fabric
2
3# Initialize the Fabric client
4# Note: When running inside a Fabric Spark notebook, authentication is handled automatically.
5client = fabric.FabricClient()
6
7# 1. List all available workspaces
8workspaces = client.list_workspaces()
9for ws in workspaces:
10    print(f"Workspace Name: {ws.display_name}, ID: {ws.id}")
11
12# 2. Access a specific Lakehouse
13# Replace 'your_workspace_id' and 'your_lakehouse_id' with actual IDs
14workspace_id = "your_workspace_id"
15lakehouse_id = "your_lakehouse_id"
16
17lakehouse = client.get_lakehouse(workspace_id=workspace_id, lakehouse_id=lakehouse_id)
18print(f"Lakehouse Name: {lakehouse.display_name}")
19
20# 3. Load a table from the Lakehouse into a Spark DataFrame
21# This assumes the table 'sales_data' exists in the Lakehouse
22table_name = "sales_data"
23df = lakehouse.get_table(table_name).to_spark()
24
25# Show the first few rows
26df.show()