New to Claude Skills? Learn how to install them →

sickn33 on GitHub

Azure Identity SDK for Python

Free

Streamline Azure authentication in Python applications.

Get this skill

Free · Opens the source repo

What Azure Identity SDK for Python does

The Azure Identity SDK for Python provides a comprehensive solution for authenticating Azure SDK clients using Microsoft Entra ID. This library simplifies the authentication process by offering various credential types and a recommended credential chain that adapts to different environments, including local development and production. By utilizing the DefaultAzureCredential, developers can seamlessly switch between local and cloud environments without modifying their code.

This SDK supports multiple authentication methods, such as service principals, managed identities, and token caching, making it suitable for a wide range of applications. The DefaultAzureCredential is particularly useful as it automatically attempts to authenticate using the most appropriate method based on the environment. This feature reduces the complexity of managing credentials and enhances security by avoiding hardcoded secrets.

In addition to the DefaultAzureCredential, the SDK includes specific credential types like ManagedIdentityCredential for Azure-hosted resources and ClientSecretCredential for service principals. Developers can also customize the credential chain to fit their specific needs, ensuring flexibility in how authentication is handled. The library is designed for both synchronous and asynchronous operations, allowing for efficient integration into applications that require non-blocking calls.

Overall, the Azure Identity SDK for Python is ideal for developers working with Azure services who need a reliable and secure way to manage authentication in their applications. Its straightforward installation and extensive documentation make it accessible for both beginners and experienced developers alike.

When to use it

Use this skill when developing Python applications that require authentication to access Azure services, particularly when using Microsoft Entra ID.

When not to use it

Avoid this skill if your application does not interact with Azure services or if you require a different authentication mechanism not supported by this SDK.

What you can build with it

Local Development

Use DefaultAzureCredential to authenticate when developing locally without hardcoding credentials.

Production Deployment

Utilize ManagedIdentityCredential for applications running on Azure services to leverage managed identities.

Custom Authentication Flows

Create a ChainedTokenCredential to define a specific order of authentication methods tailored to your application's needs.

How to install Azure Identity SDK for Python

View source

1. Install with the skills CLI

npx skills add sickn33/agentic-awesome-skills/azure-identity-py --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by sickn33

Azure Identity SDK for Python

Authentication library for Azure SDK clients using Microsoft Entra ID (formerly Azure AD).

Installation

pip install azure-identity

Environment Variables

# Service Principal (for production/CI)
AZURE_TENANT_ID=<your-tenant-id>
AZURE_CLIENT_ID=<your-client-id>
AZURE_CLIENT_SECRET=<your-client-secret>

# User-assigned Managed Identity (optional)
AZURE_CLIENT_ID=<managed-identity-client-id>

DefaultAzureCredential

The recommended credential for most scenarios. Tries multiple authentication methods in order:

from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient

# Works in local dev AND production without code changes
credential = DefaultAzureCredential()

client = BlobServiceClient(
    account_url="https://<account>.blob.core.windows.net",
    credential=credential
)

Credential Chain Order

OrderCredentialEnvironment
1EnvironmentCredentialCI/CD, containers
2WorkloadIdentityCredentialKubernetes
3ManagedIdentityCredentialAzure VMs, App Service, Functions
4SharedTokenCacheCredentialWindows only
5VisualStudioCodeCredentialVS Code with Azure extension
6AzureCliCredentialaz login
7AzurePowerShellCredentialConnect-AzAccount
8AzureDeveloperCliCredentialazd auth login

Customizing DefaultAzureCredential

# Exclude credentials you don't need
credential = DefaultAzureCredential(
    exclude_environment_credential=True,
    exclude_shared_token_cache_credential=True,
    managed_identity_client_id="<user-assigned-mi-client-id>"  # For user-assigned MI
)

# Enable interactive browser (disabled by default)
credential = DefaultAzureCredential(
    exclude_interactive_browser_credential=False
)

Specific Credential Types

ManagedIdentityCredential

For Azure-hosted resources (VMs, App Service, Functions, AKS):

from azure.identity import ManagedIdentityCredential

# System-assigned managed identity
credential = ManagedIdentityCredential()

# User-assigned managed identity
credential = ManagedIdentityCredential(
    client_id="<user-assigned-mi-client-id>"
)

ClientSecretCredential

For service principal with secret:

from azure.identity import ClientSecretCredential

credential = ClientSecretCredential(
    tenant_id=os.environ["AZURE_TENANT_ID"],
    client_id=os.environ["AZURE_CLIENT_ID"],
    client_secret=os.environ["AZURE_CLIENT_SECRET"]
)

AzureCliCredential

Uses the account from az login:

from azure.identity import AzureCliCredential

credential = AzureCliCredential()

ChainedTokenCredential

Custom credential chain:

from azure.identity import (
    ChainedTokenCredential,
    ManagedIdentityCredential,
    AzureCliCredential
)

# Try managed identity first, fall back to CLI
credential = ChainedTokenCredential(
    ManagedIdentityCredential(client_id="<user-assigned-mi-client-id>"),
    AzureCliCredential()
)

Credential Types Table

CredentialUse CaseAuth Method
DefaultAzureCredentialMost scenariosAuto-detect
ManagedIdentityCredentialAzure-hosted appsManaged Identity
ClientSecretCredentialService principalClient secret
ClientCertificateCredentialService principalCertificate
AzureCliCredentialLocal developmentAzure CLI
AzureDeveloperCliCredentialLocal developmentAzure Developer CLI
InteractiveBrowserCredentialUser sign-inBrowser OAuth
DeviceCodeCredentialHeadless/SSHDevice code flow

Getting Tokens Directly

from azure.identity import DefaultAzureCredential

credential = DefaultAzureCredential()

# Get token for a specific scope
token = credential.get_token("https://management.azure.com/.default")
print(f"Token expires: {token.expires_on}")

# For Azure Database for PostgreSQL
token = credential.get_token("https://ossrdbms-aad.database.windows.net/.default")

Async Client

from azure.identity.aio import DefaultAzureCredential
from azure.storage.blob.aio import BlobServiceClient

async def main():
    credential = DefaultAzureCredential()
    
    async with BlobServiceClient(
        account_url="https://<account>.blob.core.windows.net",
        credential=credential
    ) as client:
        # ... async operations
        pass
    
    await credential.close()

Best Practices

  1. Use DefaultAzureCredential for code that runs locally and in Azure
  2. Never hardcode credentials — use environment variables or managed identity
  3. Prefer managed identity in production Azure deployments
  4. Use ChainedTokenCredential when you need a custom credential order
  5. Close async credentials explicitly or use context managers
  6. Set AZURE_CLIENT_ID for user-assigned managed identities
  7. Exclude unused credentials to speed up authentication

When to Use

This skill is applicable to execute the workflow or actions described in the overview.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Frequently asked questions about Azure Identity SDK for Python

Similar skills