Authentication — Python SDK Quick Reference
Condensed from azure-identity-py. Full patterns (async, ChainedTokenCredential, token caching, all credential types) in the azure-identity-py plugin skill if installed.
Install
pip install azure-identityQuick Start
Auth:
DefaultAzureCredentialis for local development. See auth-best-practices.md for production patterns.
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential()Best Practices
- Use DefaultAzureCredential for local development only (CLI, PowerShell, VS Code). In production, use ManagedIdentityCredential — see auth-best-practices.md
- Never hardcode credentials — use environment variables or managed identity
- Prefer managed identity in production Azure deployments
- Use ChainedTokenCredential when you need a custom credential order
- Close async credentials explicitly or use context managers
- Set AZURECLIENTID env var for user-assigned managed identities
- Exclude unused credentials to speed up authentication