client_factory Module

Functions

get_client_from_auth_file

Return a SDK client initialized with auth file.

Disclaimer: This is NOT the recommended approach, see https://aka.ms/azsdk/python/identity/migration for guidance.

You can specific the file path directly, or fill the environment variable AZURE_AUTH_LOCATION. File must be UTF-8.

This method will fill automatically the following client parameters:

  • credentials
  • subscription_id
  • base_url

Parameters provided in kwargs will override parameters and be passed directly to the client.


   from azure.common.client_factory import get_client_from_auth_file
   from azure.mgmt.compute import ComputeManagementClient
   client = get_client_from_auth_file(ComputeManagementClient)

Example of file:


   {
       "clientId": "ad735158-65ca-11e7-ba4d-ecb1d756380e",
       "clientSecret": "b70bb224-65ca-11e7-810c-ecb1d756380e",
       "subscriptionId": "bfc42d3a-65ca-11e7-95cf-ecb1d756380e",
       "tenantId": "c81da1d8-65ca-11e7-b1d1-ecb1d756380e",
       "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
       "resourceManagerEndpointUrl": "https://management.azure.com/",
       "activeDirectoryGraphResourceId": "https://graph.windows.net/",
       "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
       "galleryEndpointUrl": "https://gallery.azure.com/",
       "managementEndpointUrl": "https://management.core.windows.net/"
   }

New in version 1.1.7.

Deprecated since version 1.1.28.

get_client_from_auth_file(client_class, auth_path=None, **kwargs)

Parameters

Name Description
client_class
Required

A SDK client class

auth_path
str

Path to the file.

default value: None

Returns

Type Description

An instantiated client

Exceptions

Type Description
KeyError if AZURE_AUTH_LOCATION is not an environment variable and no path is provided
FileNotFoundError if provided file path does not exists
json.JSONDecodeError if provided file is not JSON valid
UnicodeDecodeError if file is not UTF8 compliant
See also

https://aka.ms/azsdk/python/identity/migration

get_client_from_cli_profile

Return a SDK client initialized with current CLI credentials, CLI default subscription and CLI default cloud.

Disclaimer: This is NOT the recommended approach to authenticate with CLI login, this method is deprecated. use https://pypi.org/project/azure-identity/ and AzureCliCredential instead. See example code below:


   from azure.identity import AzureCliCredential
   from azure.mgmt.compute import ComputeManagementClient
   client = ComputeManagementClient(AzureCliCredential(), subscription_id)

This method is not working for azure-cli-core>=2.21.0 (released in March 2021).

For compatible azure-cli-core (< 2.20.0), This method will automatically fill the following client parameters:

  • credentials/credential
  • subscription_id
  • base_url

Parameters provided in kwargs will override CLI parameters and be passed directly to the client.


   from azure.common.client_factory import get_client_from_cli_profile
   from azure.mgmt.compute import ComputeManagementClient
   client = get_client_from_cli_profile(ComputeManagementClient)

New in version 1.1.6.

Deprecated since version 1.1.28.

get_client_from_cli_profile(client_class, **kwargs)

Parameters

Name Description
client_class
Required

A SDK client class

Returns

Type Description

An instantiated client

Exceptions

Type Description
ImportError if azure-cli-core package is not available
See also

https://aka.ms/azsdk/python/identity/migration

get_client_from_json_dict

Return a SDK client initialized with a JSON auth dict.

Disclaimer: This is NOT the recommended approach, see https://aka.ms/azsdk/python/identity/migration for guidance.

This method will fill automatically the following client parameters:

  • credentials
  • subscription_id
  • base_url
  • tenant_id

Parameters provided in kwargs will override parameters and be passed directly to the client.


   from azure.common.client_factory import get_client_from_auth_file
   from azure.mgmt.compute import ComputeManagementClient
   config_dict = {
       "clientId": "ad735158-65ca-11e7-ba4d-ecb1d756380e",
       "clientSecret": "b70bb224-65ca-11e7-810c-ecb1d756380e",
       "subscriptionId": "bfc42d3a-65ca-11e7-95cf-ecb1d756380e",
       "tenantId": "c81da1d8-65ca-11e7-b1d1-ecb1d756380e",
       "activeDirectoryEndpointUrl": "https://login.microsoftonline.com",
       "resourceManagerEndpointUrl": "https://management.azure.com/",
       "activeDirectoryGraphResourceId": "https://graph.windows.net/",
       "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/",
       "galleryEndpointUrl": "https://gallery.azure.com/",
       "managementEndpointUrl": "https://management.core.windows.net/"
   }
   client = get_client_from_json_dict(ComputeManagementClient, config_dict)

New in version 1.1.7.

Deprecated since version 1.1.28.

get_client_from_json_dict(client_class, config_dict, **kwargs)

Parameters

Name Description
client_class
Required

A SDK client class

config_dict
Required

A config dict.

Returns

Type Description

An instantiated client

Exceptions

Type Description
KeyError if AZURE_AUTH_LOCATION is not an environment variable and no path is provided
FileNotFoundError if provided file path does not exists
json.JSONDecodeError if provided file is not JSON valid
UnicodeDecodeError if file is not UTF8 compliant
See also

https://aka.ms/azsdk/python/identity/migration