Azure Synapse Access Control Client Library for Python

0.7.0 · active · verified Thu Apr 09

The Azure Synapse Access Control Client Library for Python enables programmatic management of role assignments within Azure Synapse Analytics workspaces. Azure Synapse is an integrated analytics service that unifies big data and data warehousing capabilities. This package is part of the broader Azure SDK for Python, with its latest public release `0.7.0` from August 2021, indicating a slower release cadence for this specific client compared to other Azure SDK components, and it is a pre-1.0.0 beta version.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and use the `AccessControlClient` to list role definitions and assignments in an Azure Synapse Analytics workspace. Ensure your `SYNAPSE_WORKSPACE_ENDPOINT` environment variable is set to your Synapse workspace's development endpoint (e.g., `https://<your-workspace-name>.dev.azuresynapse.net`) and that the authenticated principal has sufficient permissions, such as 'Synapse Administrator' or specific RBAC roles, to perform these operations.

import os
from azure.identity import DefaultAzureCredential
from azure.synapse.accesscontrol import AccessControlClient

# Set your Synapse Workspace endpoint as an environment variable or replace directly
# Example: 'https://<your-workspace-name>.dev.azuresynapse.net'
synapse_workspace_endpoint = os.environ.get('SYNAPSE_WORKSPACE_ENDPOINT', 'https://your-synapse-workspace.dev.azuresynapse.net')

# Authenticate using DefaultAzureCredential. This will try various methods
# like environment variables, managed identity, and interactive browser login.
credential = DefaultAzureCredential()

# Create an AccessControlClient
client = AccessControlClient(endpoint=synapse_workspace_endpoint, credential=credential)

try:
    print("Listing role definitions...")
    role_definitions = client.list_role_definitions()
    for role in role_definitions:
        print(f"- {role.name} (ID: {role.id})")

    # Example: List role assignments (requires appropriate permissions)
    print("\nListing role assignments...")
    role_assignments = client.list_role_assignments()
    for assignment in role_assignments:
        print(f"- Role Assignment ID: {assignment.id}, Role ID: {assignment.role_definition_id}, Principal ID: {assignment.principal_id}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure you have the correct permissions (e.g., Synapse Administrator) and the SYNAPSE_WORKSPACE_ENDPOINT is correctly set.")

view raw JSON →