Tenant Administration¶
The Tenant API provides access to tenant-wide settings and administrative operations in Microsoft Fabric.
Required Permissions
Tenant operations require Fabric Administrator permissions. Some operations may require PIM (Privileged Identity Management) elevation.
Getting the Tenant¶
There's only one tenant per authentication context:
Tenant Settings¶
List All Settings¶
tenant = fabric.tenant
# Get all settings
for setting in tenant.settings():
print(f"{setting.title} ({setting.tenant_setting_group})")
print(f" Enabled: {setting.enabled}")
print(f" Can scope to groups: {setting.can_specify_security_groups}")
Get a Specific Setting¶
tenant = fabric.tenant
# Get by setting name (identifier)
setting = tenant.setting("AdminApisIncludeDetailedMetadata")
if setting:
print(f"Title: {setting.title}")
print(f"Enabled: {setting.enabled}")
print(f"Group: {setting.tenant_setting_group}")
Filter Settings by Group¶
tenant = fabric.tenant
all_settings = tenant.settings()
# Filter by category
export_settings = [
s for s in all_settings
if s.tenant_setting_group == "ExportAndSharing"
]
for setting in export_settings:
print(f"{setting.title}: {setting.enabled}")
Update a Setting¶
tenant = fabric.tenant
# Enable a setting
tenant.updateSetting(
"DatamartTenant",
enabled=True
)
# Enable for specific security groups only
tenant.updateSetting(
"DatamartTenant",
enabled=True,
enabled_security_groups=["group-guid-1", "group-guid-2"]
)
# Exclude specific security groups
tenant.updateSetting(
"DatamartTenant",
enabled=True,
enabled_security_groups=["group-guid-1"],
excluded_security_groups=["group-guid-3"]
)
Privileged Operation
Updating tenant settings is a privileged operation that may require PIM elevation even with Fabric Administrator permissions.
Setting Properties¶
The TenantSetting class exposes the following properties:
| Property | Type | Description |
|---|---|---|
setting_name |
str | Unique setting identifier |
title |
str | Display name |
enabled |
bool | Whether setting is enabled |
tenant_setting_group |
str | Category/group name |
can_specify_security_groups |
bool | Whether setting can be scoped |
enabled_security_groups |
list | Groups with setting enabled |
excluded_security_groups |
list | Groups excluded from setting |
properties |
list | Additional setting properties |
Activity Events¶
Track user activities across the Fabric tenant using the activity events API.
Get Activity Events¶
from datetime import datetime, timedelta
tenant = fabric.tenant
# Get events from last 24 hours
end = datetime.now()
start = end - timedelta(days=1)
events = tenant.activityEvents(
start=start,
end=end
)
for event in events:
print(f"{event.creation_time}: {event.operation}")
print(f" User: {event.user_id}")
print(f" Workspace: {event.workspace_name}")
print(f" Item: {event.item_name} ({event.item_kind})")
Filter Activity Events¶
tenant = fabric.tenant
# Use OData filter syntax
events = tenant.activityEvents(
start="2024-06-01T00:00:00",
end="2024-06-01T23:59:59",
filter="Activity eq 'ShareReport'"
)
for event in events:
print(f"Report shared: {event.item_name} by {event.user_id}")
Activity Event Properties¶
The ActivityEvent class exposes:
| Property | Type | Description |
|---|---|---|
id |
str | Event unique identifier |
creation_time |
str | Event timestamp (ISO 8601) |
record_type |
int | Event record type |
operation |
str | Operation name |
activity |
str | Activity description |
user_id |
str | User who performed the action |
workspace_id |
str | Workspace GUID |
workspace_name |
str | Workspace display name |
item_id |
str | Item GUID (artifact ID) |
item_name |
str | Item display name |
item_kind |
str | Item type |
_data |
dict | Raw event data (all fields) |
Permissions Required
Activity events require Tenant.Read.All or Tenant.ReadWrite.All permission and the Power BI service principal scope https://analysis.windows.net/powerbi/api/.default.
Example: Audit Report¶
import fabias
from datetime import datetime, timedelta
from collections import Counter
tenant = fabric.tenant
# Get last 7 days of activities
end = datetime.now()
start = end - timedelta(days=7)
events = tenant.activityEvents(start=start, end=end)
# Count activities by type
activity_counts = Counter(e.activity for e in events)
print("\nTop 10 Activities:")
for activity, count in activity_counts.most_common(10):
print(f" {activity}: {count}")
# Count activities by user
user_counts = Counter(e.user_id for e in events)
print(f"\nMost Active Users:")
for user, count in user_counts.most_common(5):
print(f" {user}: {count} actions")
See Also¶
- Capacity Administration - Capacity management
- Workspaces - Workspace operations