Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Azure Identity client library for Python

Azure Identity simplifies authentication across the Azure SDK. It supports token authentication using an Azure Active Directory service principal or managed identity.

Getting started

Prerequisites

  • an Azure subscription
  • Python 2.7 or 3.5.3+

Install the package

Install Azure Identity with pip:

pip install azure-identity

Key concepts

Credentials

Azure Identity offers a variety of credential classes in the azure.identity 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:

credential class identity configuration
DefaultAzureCredential service principal or managed identity none for managed identity; environment variables for service principal
ManagedIdentityCredential managed identity none
EnvironmentCredential service principal environment variables
ClientSecretCredential service principal constructor parameters
CertificateCredential 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 azure.identity.aio namespace. These are supported on Python 3.5.3+. See the async credentials example for details.

DefaultAzureCredential

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.

Environment variables

DefaultAzureCredential and EnvironmentCredential are configured for service principal authentication with these environment variables:

variable name value
AZURE_CLIENT_ID service principal's app id
AZURE_TENANT_ID id of the principal's Azure Active Directory tenant
AZURE_CLIENT_SECRET one of the service principal's client secrets
AZURE_CLIENT_CERTIFICATE_PATH path to a PEM-encoded certificate file including private key (without password)

Either AZURE_CLIENT_SECRET or AZURE_CLIENT_CERTIFICATE_PATH must be set. If both are set, the client secret will be used.

Examples

DefaultAzureCredential

# 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()

Chaining credentials:

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)

Async credentials:

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

Troubleshooting

General

Credentials raise azure.core.exceptions.ClientAuthenticationError when they fail to authenticate. ClientAuthenticationError has a message attribute which describes why authentication failed. When raised by ChainedTokenCredential, the message collects error messages from each credential in the chain.

Next steps

Provide Feedback

If you encounter bugs or have suggestions, please open an issue.

Contributing

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.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Impressions

Release History

1.0.0b1

First preview release of the library.

Metadata

Release files for azure-identity 1.0.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for azure-identity 1.0.0b1
File Size Uploaded Provenance Actions
azure-identity-1.0.0b1.zip 27.5 kB Without provenance Details for azure-identity-1.0.0b1.zip

Built distributions (wheels)

Table of built distributions (wheels) for azure-identity 1.0.0b1
File Interpreter ABI Platform Actions
azure_identity-1.0.0b1-py3-none-any.whl Python 3 none any Details for azure_identity-1.0.0b1-py3-none-any.whl
azure_identity-1.0.0b1-py2.py3-none-any.whl Python 3, Python 2 none any Details for azure_identity-1.0.0b1-py2.py3-none-any.whl

Total release size: 66.0 kB

Release files / azure-identity-1.0.0b1.zip

Download URL azure-identity-1.0.0b1.zip
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
44c843c52a874e05547400165c53fac47726be24943a59f6d3fdd9b3a84db777
BLAKE2b-256 checksum
How to use checksums
6a183fc714e98b87f26d7e313577dd24a67fa401cd07eda4df0bea0ab285a81d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Release files / azure_identity-1.0.0b1-py3-none-any.whl

Download URL azure_identity-1.0.0b1-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89445f7eb8763dd57889fae488d85aaa54ffaacb417b49c151a55b9eee3a057c
BLAKE2b-256 checksum
How to use checksums
6eecc06d6ec847dbb86b6c877ea0d90c98dfa6ddd7b39cc364a28bf4df4c7b0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

Release files / azure_identity-1.0.0b1-py2.py3-none-any.whl

Download URL azure_identity-1.0.0b1-py2.py3-none-any.whl
Size 19.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1a2f4d5eb3c75b9be115974e9dbb66c3fee218da8592918d86c37324c7d46b89
BLAKE2b-256 checksum
How to use checksums
37c2cc019e8927150337cb90c92ddb06381c2327da297ac51f6dae5aeb068dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

Security for azure-identity 1.0.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page