Registry / azure / azure-identity

azure-identity

JSON →
library1.25.3pypypi✓ verified 26d ago

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).

pip install azure-identity
INSTALL
IMPORT
SIG · AZURE-IDENTITY
A
azure-identity
azurepythonv1.25.3
Install
4.0s avg
Import
1043ms
Disk
61MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.25.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.960 runs
installs and imports cleanly · install 0.0s · import 1.070s · 42.5MB
glibc
py 3.103.960 runs
installs and imports cleanly · install 4.0s · import 1.016s · 82MB
61MB installed
● package 61MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DefaultAzureCredential
from azure.identity import DefaultAzureCredential
import azure.identity; azure.identity.DefaultAzureCredential()
Always import directly from azure.identity. Use async variant from azure.identity.aio for async code.
ManagedIdentityCredential
from azure.identity import ManagedIdentityCredential
DefaultAzureCredential() in production
Use ManagedIdentityCredential explicitly in production instead of DefaultAzureCredential to avoid silent wrong-identity issues.
AsyncDefaultAzureCredential
from azure.identity.aio import DefaultAzureCredential
from azure.identity import DefaultAzureCredential # in async context
Async credentials live in azure.identity.aio, not azure.identity.

Minimal Azure authentication using DefaultAzureCredential 1.23.x.

from azure.identity import DefaultAzureCredential from azure.storage.blob import BlobServiceClient # reads from env, CLI, managed identity etc in order credential = DefaultAzureCredential() client = BlobServiceClient( account_url='https://<account>.blob.core.windows.net', credential=credential )
Debug
Known issues
breakingDefaultAzureCredential 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.
fix
In production use ManagedIdentityCredential() or ClientSecretCredential(tenant_id, client_id, client_secret) explicitly. Reserve DefaultAzureCredential for local dev only.
affects: all
breakingMulti-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.
fix
credential = DefaultAzureCredential(additionally_allowed_tenants=['*'])
affects: >= 1.11.0
gotchaVisualStudioCodeCredential 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.
fix
Explicitly exclude if not needed: DefaultAzureCredential(exclude_visual_studio_code_credential=True)
affects: 1.10.0 - 1.23.x
gotchaAsync credentials in azure.identity.aio must be explicitly closed. Failing to close leaks transport sessions.
fix
async with DefaultAzureCredential() as credential:
    token = await credential.get_token(scope)
affects: all
gotchaDEBUG logging via logging_enable=True exposes tokens and secrets in logs.
fix
Never set logging_enable=True in production.
affects: all
deprecatedPython 3.8 support dropped August 2025. Python 3.9 support ends April 2026.
fix
Use Python 3.10+ for new projects.
affects: >= 1.21.0
breakingModuleNotFoundError: No module named 'azure.storage' indicates that the 'azure-storage-blob' package was not installed. This package is required to use 'BlobServiceClient'.
fix
Install the 'azure-storage-blob' package: pip install azure-storage-blob
affects: all
breakingModuleNotFoundError: 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.
fix
Install the required storage package, e.g., 'pip install azure-storage-blob'.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.identity'
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.
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.
DefaultAzureCredential failed to retrieve a token from the included credentials.
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.
fix
This is a general error, and the fix depends on the underlying credential that failed. Common resolutions include:

*   **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.
*   **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`.
*   **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.
*   **General troubleshooting:** Enable logging for `azure-identity` to get detailed information on which specific credential in the chain is failing and why.
ClientAuthenticationError: (None) Unauthorized. Access token is missing, invalid, audience is incorrect (https://cognitiveservices.azure.com), or have expired
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.
fix
Verify the following:

*   **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.
*   **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.
*   **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.
Upgrade
Version history
1.25.3latest on PyPI · released Mar 13, 2026
Audit
Dependencies
azure-identity-brokeroptionalRequired for Windows Web Account Manager (WAM) auth and VisualStudioCodeCredential support.
aiohttpoptionalRequired for async credential usage via azure.identity.aio.
Agent activity
58 hits · last 30 days
node
50
Amazon
1
OpenAI (training)
1
Resources