Microsoft Azure Identity Library for Python
Azure Identity client library for Python
- an Azure subscription
- if you don't have one, you can sign up for a free account
- Python 2.7 or 3.5.3+
Install the package
Install Azure Identity with pip:
pip install azure-identity
Azure Identity offers a variety of credential classes in the
namespace. These are accepted by Azure SDK data plane clients. Each client
library documents its Azure Identity integration in its README and samples.
Azure SDK resource management libraries (which have
mgmt in their names)
do not accept these credentials.
Credentials differ mostly in configuration:
||service principal or managed identity||none for managed identity; environment variables for service principal|
||service principal||environment variables|
||service principal||constructor parameters|
||service principal||constructor parameters|
Credentials can be chained and tried in turn until one succeeds; see chaining credentials for details.
All credentials have an async equivalent in the
These are supported on Python 3.5.3+. See the
async credentials example for details.
DefaultAzureCredential is appropriate for most scenarios. It supports
authenticating as a service principal or managed identity. To authenticate
as a service principal, provide configuration in environment variables as
described in the next section.
Authenticating as a managed identity requires no configuration, but does require platform support. See the managed identity documentation for more information.
EnvironmentCredential are configured for service
principal authentication with these environment variables:
||service principal's app id|
||id of the principal's Azure Active Directory tenant|
||one of the service principal's client secrets|
||path to a PEM-encoded certificate file including private key (without password)|
AZURE_CLIENT_CERTIFICATE_PATH must be set.
If both are set, the client secret will be used.
# The default credential first checks environment variables for configuration as described above. # If environment configuration is incomplete, it will try managed identity. from azure.identity import DefaultAzureCredential credential = DefaultAzureCredential() # Azure SDK clients accept the credential as a parameter from azure.keyvault.secrets import SecretClient client = SecretClient(vault_url, credential)
Authenticating as a service principal:
# using a client secret from azure.identity import ClientSecretCredential credential = ClientSecretCredential(client_id, client_secret, tenant_id) # using a certificate from azure.identity import CertificateCredential # requires a PEM-encoded certificate with private key, not protected with a password cert_path = "/app/certs/certificate.pem" credential = CertificateCredential(client_id, tenant_id, cert_path) # using environment variables from azure.identity import EnvironmentCredential # authenticate with client secret or certificate, # depending on environment variable settings # (see "Environment variables" above for variable names and expected values) credential = EnvironmentCredential()
from azure.identity import ClientSecretCredential, ManagedIdentityCredential, ChainedTokenCredential first_principal = ClientSecretCredential(client_id, client_secret, tenant_id) second_principal = ClientSecretCredential(another_client_id, another_secret, tenant_id) # when an access token is requested, the chain will try each # credential in order, stopping when one provides a token credential_chain = ChainedTokenCredential(first_principal, second_principal) # the chain can be used anywhere a credential is required from azure.keyvault.secrets import SecretClient client = SecretClient(vault_url, credential=credential_chain)
# all credentials have async equivalents supported on Python 3.5.3+ from azure.identity.aio import DefaultAzureCredential default_credential = DefaultAzureCredential() # async credentials have the same API and configuration as # their synchronous counterparts... from azure.identity.aio import ClientSecretCredential credential = ClientSecretCredential(client_id, client_secret, tenant_id) # ...and are used with async Azure SDK clients in the same way from azure.keyvault.aio import SecretClient client = SecretClient(vault_url, credential)
azure.core.exceptions.ClientAuthenticationError when they fail
ClientAuthenticationError has a
message attribute which
describes why authentication failed. When raised by
the message collects error messages from each credential in the chain.
If you encounter bugs or have suggestions, please open an issue.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
First preview release of the library.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size azure_identity-1.0.0b1-py2.py3-none-any.whl (19.2 kB)||File type Wheel||Python version py2.py3||Upload date||Hashes View hashes|
|Filename, size azure_identity-1.0.0b1-py3-none-any.whl (19.2 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size azure-identity-1.0.0b1.zip (27.5 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for azure_identity-1.0.0b1-py2.py3-none-any.whl
Hashes for azure_identity-1.0.0b1-py3-none-any.whl