Microsoft Azure common code library providing shared utilities, exceptions, and profile management for all Azure Python SDK packages.
npx @tessl/cli install tessl/pypi-azure-common@1.1.0Microsoft Azure common code library that provides shared utilities and functionality for all Azure Python SDK packages. It includes core exception classes for consistent error handling across Azure services, profile definitions for managing API versions across different Azure environments including hybrid cloud deployments, and client factory functions for creating Azure service clients.
pip install azure-common# Core exceptions and constants
from azure.common import AzureException, AzureHttpError, __version__, __author__
# Profile management
from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin, InvalidMultiApiClientError
# Client factory functions (deprecated)
from azure.common.client_factory import (
get_client_from_cli_profile,
get_client_from_json_dict,
get_client_from_auth_file
)
# CLI credentials and cloud functions (deprecated)
from azure.common.credentials import (
get_cli_profile,
get_azure_cli_credentials
)
from azure.common.cloud import get_cli_active_cloud
# Exception and authentication re-exports
from azure.common.exceptions import (
CloudError,
ClientException,
SerializationError,
DeserializationError,
TokenExpiredError,
ClientRequestError,
AuthenticationError,
HttpOperationError
)
# Authentication classes re-exported from credentials
from azure.common.credentials import (
BasicAuthentication,
BasicTokenAuthentication,
OAuthTokenAuthentication,
InteractiveCredentials,
ServicePrincipalCredentials,
UserPassCredentials
)from azure.common import AzureException, AzureHttpError, AzureConflictHttpError
from azure.profiles import KnownProfiles, ProfileDefinition
# Exception handling
try:
# Some Azure operation that might fail
pass
except AzureHttpError as e:
if e.status_code == 404:
print("Resource not found")
elif e.status_code == 409:
print("Resource conflict")
else:
print(f"HTTP error: {e.status_code}")
except AzureException as e:
print(f"Azure error: {e}")
# Using predefined profiles for API version management
profile = KnownProfiles.v2020_09_01_hybrid
print(f"Using profile: {profile.value.label}")
# Creating custom profile
custom_profile = ProfileDefinition({
"azure.mgmt.compute.ComputeManagementClient": {
None: "2020-06-01"
}
}, "custom-profile")The azure-common library serves as the foundation layer for the Azure SDK ecosystem, providing:
Core exception classes providing consistent error handling across all Azure services. The exception hierarchy automatically creates appropriate subclasses based on HTTP status codes.
class AzureException(Exception):
"""Base exception for Azure operations."""
pass
class AzureHttpError(AzureException):
"""HTTP error with automatic subclass creation."""
def __init__(self, message, status_code): ...
class AzureConflictHttpError(AzureHttpError):
"""HTTP 409 conflict error."""
pass
class AzureMissingResourceHttpError(AzureHttpError):
"""HTTP 404 missing resource error."""
passProfile definitions for managing API versions across different Azure environments, enabling applications to target specific API versions or switch between cloud environments.
class ProfileDefinition:
"""Custom profile definition for API versions."""
def __init__(self, profile_dict, label=None): ...
def get_profile_dict(self): ...
class KnownProfiles(Enum):
"""Predefined Azure profiles with API version mappings."""
default = ...
latest = ...
v2017_03_09_profile = ...
v2018_03_01_hybrid = ...
v2019_03_01_hybrid = ...
v2020_09_01_hybrid = ...Deprecated client factory functions for creating Azure service clients from various authentication sources. These functions are deprecated as of version 1.1.28 in favor of azure-identity.
def get_client_from_cli_profile(client_class, **kwargs):
"""Create SDK client from CLI credentials (deprecated)."""
...
def get_client_from_json_dict(client_class, config_dict, **kwargs):
"""Create SDK client from JSON auth dict (deprecated)."""
...
def get_client_from_auth_file(client_class, auth_path=None, **kwargs):
"""Create SDK client from auth file (deprecated)."""
...Deprecated functions for integrating with Azure CLI credentials and cloud configurations. These functions are deprecated as of version 1.1.28 in favor of azure-identity.
def get_cli_profile():
"""Return a CLI profile class (deprecated)."""
...
def get_azure_cli_credentials(resource=None, with_tenant=False):
"""Return CLI credentials and subscription ID (deprecated)."""
...
def get_cli_active_cloud():
"""Return a CLI active cloud (deprecated)."""
...Package metadata constants providing version and author information.
__version__: str
"""Package version string (e.g., '1.1.28')"""
__author__: str
"""Author information: 'Microsoft Corp. <azpysdkhelp@microsoft.com>'"""