0
# Client Management
1
2
Core client initialization, configuration, and lifecycle management for the Azure Consumption Management Client. This handles authentication, connection management, and client configuration.
3
4
## Capabilities
5
6
### Client Initialization
7
8
Initialize the ConsumptionManagementClient with Azure credentials and configuration.
9
10
```python { .api }
11
class ConsumptionManagementClient:
12
def __init__(
13
self,
14
credential: TokenCredential,
15
subscription_id: str,
16
base_url: str = "https://management.azure.com",
17
**kwargs
18
) -> None:
19
"""
20
Initialize the Consumption Management Client.
21
22
Parameters:
23
- credential: Azure credential for authentication (TokenCredential)
24
- subscription_id: Azure Subscription ID (str)
25
- base_url: Service URL, defaults to "https://management.azure.com" (str)
26
- **kwargs: Additional configuration parameters
27
"""
28
```
29
30
**Usage Example:**
31
32
```python
33
from azure.identity import DefaultAzureCredential
34
from azure.mgmt.consumption import ConsumptionManagementClient
35
36
# Using DefaultAzureCredential (recommended)
37
credential = DefaultAzureCredential()
38
client = ConsumptionManagementClient(
39
credential=credential,
40
subscription_id="12345678-1234-1234-1234-123456789abc"
41
)
42
43
# Using specific credential types
44
from azure.identity import ClientSecretCredential
45
46
credential = ClientSecretCredential(
47
tenant_id="tenant-id",
48
client_id="client-id",
49
client_secret="client-secret"
50
)
51
client = ConsumptionManagementClient(credential, subscription_id)
52
```
53
54
### Context Management
55
56
The client supports context manager protocol for automatic resource cleanup.
57
58
```python { .api }
59
def __enter__(self) -> ConsumptionManagementClient:
60
"""Enter context manager, returns self."""
61
62
def __exit__(self, *exc_details) -> None:
63
"""Exit context manager, closes client resources."""
64
65
def close(self) -> None:
66
"""Explicitly close the client and clean up resources."""
67
```
68
69
**Usage Example:**
70
71
```python
72
# Using context manager (recommended)
73
with ConsumptionManagementClient(credential, subscription_id) as client:
74
budgets = client.budgets.list(scope)
75
# Client automatically closed when exiting context
76
77
# Manual resource management
78
client = ConsumptionManagementClient(credential, subscription_id)
79
try:
80
budgets = client.budgets.list(scope)
81
finally:
82
client.close()
83
```
84
85
### Low-Level Request Handling
86
87
Access to low-level HTTP request functionality for custom operations.
88
89
```python { .api }
90
def _send_request(
91
self,
92
request: HttpRequest,
93
**kwargs
94
) -> HttpResponse:
95
"""
96
Send a custom HTTP request through the client's configured pipeline.
97
98
Parameters:
99
- request: The HTTP request to send (HttpRequest)
100
- **kwargs: Additional request options (stream: bool, etc.)
101
102
Returns:
103
HttpResponse: The response from the service
104
"""
105
```
106
107
**Usage Example:**
108
109
```python
110
from azure.core.rest import HttpRequest
111
112
# Create custom request
113
request = HttpRequest("GET", "https://management.azure.com/custom-endpoint")
114
response = client._send_request(request)
115
print(f"Status: {response.status_code}")
116
```
117
118
## Types
119
120
### Authentication Types
121
122
```python { .api }
123
from azure.core.credentials import TokenCredential
124
125
# Base credential interface
126
class TokenCredential:
127
"""Base interface for Azure credential providers."""
128
```
129
130
### HTTP Types
131
132
```python { .api }
133
from azure.core.rest import HttpRequest, HttpResponse
134
135
class HttpRequest:
136
"""Represents an HTTP request."""
137
138
class HttpResponse:
139
"""Represents an HTTP response."""
140
```
141
142
### Client Configuration
143
144
```python { .api }
145
class ConsumptionManagementClientConfiguration:
146
"""Internal configuration class for the client."""
147
```