{"id":7,"library":"azure-identity","title":"Azure Identity SDK","description":"Microsoft's Azure authentication library for Python. Provides credential classes for authenticating against Azure services. Primary interface is DefaultAzureCredential which chains multiple credential sources. Current version is 1.23.1 (Mar 2026).","status":"active","version":"1.23.1","language":"python","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity","tags":["azure","authentication","cloud","microsoft","identity","managed-identity"],"install":[{"cmd":"pip install azure-identity","lang":"bash","label":"Python (core)"},{"cmd":"pip install azure-identity-broker","lang":"bash","label":"Python (broker/WAM support)"}],"dependencies":[{"reason":"Required for Windows Web Account Manager (WAM) auth and VisualStudioCodeCredential support.","package":"azure-identity-broker","optional":true},{"reason":"Required for async credential usage via azure.identity.aio.","package":"aiohttp","optional":true}],"imports":[{"note":"Always import directly from azure.identity. Use async variant from azure.identity.aio for async code.","wrong":"import azure.identity; azure.identity.DefaultAzureCredential()","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"Use ManagedIdentityCredential explicitly in production instead of DefaultAzureCredential to avoid silent wrong-identity issues.","wrong":"DefaultAzureCredential() in production","symbol":"ManagedIdentityCredential","correct":"from azure.identity import ManagedIdentityCredential"},{"note":"Async credentials live in azure.identity.aio, not azure.identity.","wrong":"from azure.identity import DefaultAzureCredential  # in async context","symbol":"AsyncDefaultAzureCredential","correct":"from azure.identity.aio import DefaultAzureCredential"}],"quickstart":{"code":"from azure.identity import DefaultAzureCredential\nfrom azure.storage.blob import BlobServiceClient\n\n# reads from env, CLI, managed identity etc in order\ncredential = DefaultAzureCredential()\nclient = BlobServiceClient(\n    account_url='https://<account>.blob.core.windows.net',\n    credential=credential\n)","lang":"python","description":"Minimal Azure authentication using DefaultAzureCredential 1.23.x."},"warnings":[{"fix":"In production use ManagedIdentityCredential() or ClientSecretCredential(tenant_id, client_id, client_secret) explicitly. Reserve DefaultAzureCredential for local dev only.","message":"DefaultAzureCredential silently picks wrong identity. In dev with az login active, authenticates as personal account instead of service principal. Auth succeeds with no error but wrong identity.","severity":"breaking","affected_versions":"all"},{"fix":"credential = DefaultAzureCredential(additionally_allowed_tenants=['*'])","message":"Multi-tenant token requests fail since v1.11.0. Error: 'The current credential is not configured to acquire tokens for tenant X.' Breaks when using az login --tenant with a different tenant than your resource.","severity":"breaking","affected_versions":">= 1.11.0"},{"fix":"Explicitly exclude if not needed: DefaultAzureCredential(exclude_visual_studio_code_credential=True)","message":"VisualStudioCodeCredential was removed from DefaultAzureCredential chain, then re-enabled in a later version. Behaviour varies by version. Requires azure-identity-broker to work in current versions.","severity":"gotcha","affected_versions":"1.10.0 - 1.23.x"},{"fix":"async with DefaultAzureCredential() as credential:\n    token = await credential.get_token(scope)","message":"Async credentials in azure.identity.aio must be explicitly closed. Failing to close leaks transport sessions.","severity":"gotcha","affected_versions":"all"},{"fix":"Never set logging_enable=True in production.","message":"DEBUG logging via logging_enable=True exposes tokens and secrets in logs.","severity":"gotcha","affected_versions":"all"},{"fix":"Use Python 3.10+ for new projects.","message":"Python 3.8 support dropped August 2025. Python 3.9 support ends April 2026.","severity":"deprecated","affected_versions":">= 1.21.0"},{"fix":"Install the 'azure-storage-blob' package: pip install azure-storage-blob","message":"ModuleNotFoundError: No module named 'azure.storage' indicates that the 'azure-storage-blob' package was not installed. This package is required to use 'BlobServiceClient'.","severity":"breaking","affected_versions":"all"},{"fix":"Install the required storage package, e.g., 'pip install azure-storage-blob'.","message":"ModuleNotFoundError: No module named 'azure.storage' indicates a missing dependency. The script attempts to import from 'azure.storage.blob' but the 'azure-storage-blob' package was not installed.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-11T18:09:43.020Z","next_check":"2026-04-17T00:00:00.000Z","problems":[{"fix":"Ensure the `azure-identity` package is installed: `pip install azure-identity`. If using a virtual environment, activate it before installing or running the script.","cause":"The `azure-identity` library is not installed in the Python environment where the code is being executed, or the virtual environment is not correctly activated.","error":"ModuleNotFoundError: No module named 'azure.identity'"},{"fix":"This is a general error, and the fix depends on the underlying credential that failed. Common resolutions include:\n\n*   **EnvironmentCredential (when nested):** Ensure environment variables for service principal authentication (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` or `AZURE_CLIENT_CERTIFICATE_PATH`) are correctly set.\n*   **Multi-tenant authentication:** If authenticating to a tenant different from the one logged into via Azure CLI or other tools, add `additionally_allowed_tenants=['*']` (to allow any tenant) or specific tenant IDs when initializing `DefaultAzureCredential`.\n*   **ManagedIdentityCredential (when nested):** Verify that managed identity is enabled and correctly configured on the Azure resource (e.g., VM, App Service, Function App) where the code is running, and that the identity has the necessary Azure RBAC permissions.\n*   **General troubleshooting:** Enable logging for `azure-identity` to get detailed information on which specific credential in the chain is failing and why.","cause":"The `DefaultAzureCredential` attempts to authenticate using a chain of credential types (e.g., environment variables, managed identity, Azure CLI, Visual Studio Code). This error indicates that none of the credentials in its chain successfully acquired an access token, often due to misconfiguration of the environment or the identity being used.","error":"DefaultAzureCredential failed to retrieve a token from the included credentials."},{"fix":"Verify the following:\n\n*   **Azure RBAC roles:** Ensure the identity (user, service principal, or managed identity) has the appropriate Azure RBAC roles assigned for the specific Azure service and resource it's trying to access.\n*   **Scope/Audience:** Confirm that the `scope` or `resource URI` provided when requesting the token (e.g., `https://storage.azure.com/.default` for Azure Storage) is correct for the target service.\n*   **Token validity:** Ensure the tokens are not expired; Azure SDKs usually handle token refreshing automatically, but persistent issues might point to underlying permission or configuration problems preventing successful refresh.","cause":"The access token acquired by the credential is either missing, invalid, expired, or the audience (resource URI/scope) for which the token was requested does not match the expected audience of the target Azure service. This usually indicates an issue with the permissions assigned to the identity or an incorrect scope/resource URI in the token request.","error":"ClientAuthenticationError: (None) Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-11","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.5,"mem_mb":12.1,"disk_size":"40.8M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.38,"mem_mb":12.1,"disk_size":"40.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.99,"mem_mb":12.1,"disk_size":"41M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.92,"mem_mb":12.1,"disk_size":"79M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.77,"mem_mb":13.2,"disk_size":"44.0M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.77,"mem_mb":13.2,"disk_size":"44.0M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.66,"mem_mb":13.2,"disk_size":"44M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.61,"mem_mb":13.2,"disk_size":"83M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.52,"mem_mb":12.9,"disk_size":"35.6M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.3,"mem_mb":12.8,"disk_size":"35.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.36,"mem_mb":12.8,"disk_size":"36M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.58,"mem_mb":12.8,"disk_size":"74M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.41,"mem_mb":13,"disk_size":"35.2M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.36,"mem_mb":12.9,"disk_size":"35.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.51,"mem_mb":13,"disk_size":"36M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.52,"mem_mb":13,"disk_size":"74M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.28,"mem_mb":11.9,"disk_size":"40.8M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.15,"mem_mb":11.8,"disk_size":"40.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.06,"mem_mb":11.9,"disk_size":"41M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.06,"mem_mb":11.9,"disk_size":"83M"}]},"quickstart_checks":{"last_tested":"2026-05-11","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}