or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

aggregated-cost.mdbudget-management.mdclient-management.mdcost-analysis.mdcredits-billing.mdindex.mdoperations.mdreservation-management.mdtags-operations.mdusage-analytics.md

index.mddocs/

0

# Azure Consumption Management Client

1

2

A comprehensive Python client library that enables programmatic access and management of Azure consumption resources for Enterprise Subscriptions. The library provides complete cost monitoring, budgeting, and optimization capabilities through Azure Resource Manager APIs.

3

4

## Package Information

5

6

- **Package Name**: azure-mgmt-consumption

7

- **Language**: Python

8

- **Installation**: `pip install azure-mgmt-consumption`

9

- **Authentication**: Azure credentials required

10

11

## Core Imports

12

13

```python

14

from azure.mgmt.consumption import ConsumptionManagementClient

15

```

16

17

Common authentication pattern:

18

19

```python

20

from azure.identity import DefaultAzureCredential

21

from azure.mgmt.consumption import ConsumptionManagementClient

22

23

credential = DefaultAzureCredential()

24

client = ConsumptionManagementClient(credential, subscription_id)

25

```

26

27

## Basic Usage

28

29

```python

30

from azure.identity import DefaultAzureCredential

31

from azure.mgmt.consumption import ConsumptionManagementClient

32

33

# Authenticate and create client

34

credential = DefaultAzureCredential()

35

subscription_id = "your-subscription-id"

36

client = ConsumptionManagementClient(credential, subscription_id)

37

38

# Get usage details for current billing period

39

scope = f"/subscriptions/{subscription_id}"

40

usage_details = client.usage_details.list(scope=scope)

41

42

for usage in usage_details:

43

print(f"Resource: {usage.instance_name}")

44

print(f"Cost: {usage.cost} {usage.billing_currency}")

45

print(f"Usage Date: {usage.date}")

46

47

# Create a budget

48

budget_name = "monthly-budget-2024"

49

budget_scope = f"/subscriptions/{subscription_id}"

50

51

budget = {

52

"category": "Cost",

53

"amount": 1000.0,

54

"time_grain": "Monthly",

55

"time_period": {

56

"start_date": "2024-01-01T00:00:00Z"

57

},

58

"notifications": {

59

"actual_80": {

60

"enabled": True,

61

"operator": "GreaterThan",

62

"threshold": 80,

63

"contact_emails": ["admin@company.com"]

64

}

65

}

66

}

67

68

created_budget = client.budgets.create_or_update(budget_scope, budget_name, budget)

69

print(f"Budget created: {created_budget.name}")

70

```

71

72

## Architecture

73

74

The Azure Consumption Management Client follows the Azure SDK pattern with operation-specific classes accessed through the main client:

75

76

- **ConsumptionManagementClient**: Main entry point providing access to all consumption operations

77

- **Operation Classes**: Specialized classes for different resource types (budgets, usage, reservations, etc.)

78

- **Model Classes**: Data structures representing Azure consumption resources and responses

79

- **Authentication Integration**: Built-in support for Azure credential providers and token management

80

- **Pagination Support**: Automatic handling of large result sets with iterator patterns

81

82

The client supports both synchronous and asynchronous operations (via the `aio` module) and provides comprehensive error handling with Azure-standard exceptions.

83

84

## Capabilities

85

86

### Client Initialization

87

88

Main client class initialization and configuration for accessing Azure consumption management APIs.

89

90

```python { .api }

91

class ConsumptionManagementClient:

92

def __init__(

93

self,

94

credential: TokenCredential,

95

subscription_id: str,

96

base_url: str = "https://management.azure.com",

97

**kwargs

98

) -> None: ...

99

```

100

101

[Client Management](./client-management.md)

102

103

### Usage Details and Analytics

104

105

Access detailed usage information, marketplace transactions, and consumption analytics for Azure resources across various scopes and time periods.

106

107

```python { .api }

108

# Usage details operations

109

def list(

110

scope: str,

111

expand: str = None,

112

filter: str = None,

113

skiptoken: str = None,

114

top: int = None,

115

metric: str = None

116

) -> Iterable[UsageDetailsListResult]: ...

117

```

118

119

[Usage and Analytics](./usage-analytics.md)

120

121

### Budget Management

122

123

Create, update, and manage budgets with notifications, alerts, and spending controls for cost management across different Azure scopes.

124

125

```python { .api }

126

# Budget operations

127

def list(scope: str) -> Iterable[BudgetsListResult]: ...

128

def get(scope: str, budget_name: str) -> Budget: ...

129

def create_or_update(scope: str, budget_name: str, parameters: Budget) -> Budget: ...

130

def delete(scope: str, budget_name: str) -> None: ...

131

```

132

133

[Budget Management](./budget-management.md)

134

135

### Reservation Management

136

137

Access reservation summaries, details, recommendations, and transaction history for cost optimization through Azure Reserved Instances.

138

139

```python { .api }

140

# Reservation summaries

141

def list(

142

resource_scope: str,

143

grain: str,

144

start_date: str = None,

145

end_date: str = None,

146

filter: str = None,

147

reservation_id: str = None,

148

reservation_order_id: str = None

149

) -> Iterable[ReservationSummariesListResult]: ...

150

151

# Reservation recommendations

152

def list(resource_scope: str, filter: str = None) -> Iterable[ReservationRecommendationsListResult]: ...

153

```

154

155

[Reservation Management](./reservation-management.md)

156

157

### Cost Analysis and Reporting

158

159

Analyze charges, balances, aggregated costs, and marketplace usage for comprehensive financial reporting and cost allocation.

160

161

```python { .api }

162

# Charges operations

163

def list(

164

scope: str,

165

start_date: str = None,

166

end_date: str = None,

167

filter: str = None,

168

apply: str = None

169

) -> ChargesListResult: ...

170

171

# Balance operations

172

def get_by_billing_account(billing_account_id: str) -> Balance: ...

173

```

174

175

[Cost Analysis](./cost-analysis.md)

176

177

### Credits and Billing

178

179

Manage Azure credits, lots, events, and price sheet information for Enterprise Agreement and Microsoft Customer Agreement billing accounts.

180

181

```python { .api }

182

# Credits operations

183

def get(billing_account_id: str, billing_profile_id: str) -> CreditSummary: ...

184

185

# Price sheet operations

186

def get(expand: str = None, skiptoken: str = None, top: int = None) -> PriceSheetResult: ...

187

```

188

189

[Credits and Billing](./credits-billing.md)

190

191

### Tags Management

192

193

Retrieve all available tag keys for cost allocation and management across various Azure scopes including subscriptions, billing accounts, and management groups.

194

195

```python { .api }

196

def get(scope: str, **kwargs) -> Optional[TagsResult]:

197

"""

198

Get all available tag keys for the defined scope.

199

200

Parameters:

201

- scope: The scope for tag operations (str)

202

203

Returns:

204

Optional[TagsResult]: Available tag keys and values

205

"""

206

```

207

208

[Tags Operations](./tags-operations.md)

209

210

### Aggregated Cost Analysis

211

212

Access aggregated cost data for management groups across current and historical billing periods for comprehensive cost oversight.

213

214

```python { .api }

215

def get_by_management_group(

216

management_group_id: str,

217

filter: str = None,

218

**kwargs

219

) -> ManagementGroupAggregatedCostResult:

220

"""

221

Get aggregate cost for a management group and child groups.

222

223

Parameters:

224

- management_group_id: Azure Management Group ID (str)

225

- filter: Optional filter expression (str)

226

227

Returns:

228

ManagementGroupAggregatedCostResult: Aggregated cost data

229

"""

230

231

def get_for_billing_period_by_management_group(

232

management_group_id: str,

233

billing_period_name: str,

234

**kwargs

235

) -> ManagementGroupAggregatedCostResult:

236

"""

237

Get aggregate cost for specific billing period.

238

239

Parameters:

240

- management_group_id: Azure Management Group ID (str)

241

- billing_period_name: Billing period name (str)

242

243

Returns:

244

ManagementGroupAggregatedCostResult: Historical aggregated cost data

245

"""

246

```

247

248

[Aggregated Cost](./aggregated-cost.md)

249

250

### API Operations

251

252

List all available consumption REST API operations for service discovery and capability exploration.

253

254

```python { .api }

255

def list(**kwargs) -> Iterable[OperationListResult]:

256

"""

257

List all available consumption REST API operations.

258

259

Returns:

260

Iterable[OperationListResult]: Available API operations

261

"""

262

```

263

264

[API Operations](./operations.md)

265

266

## Types

267

268

### Core Client Types

269

270

```python { .api }

271

from azure.core.credentials import TokenCredential

272

273

class ConsumptionManagementClient:

274

def __init__(

275

self,

276

credential: TokenCredential,

277

subscription_id: str,

278

base_url: str = "https://management.azure.com",

279

**kwargs

280

) -> None: ...

281

282

def close(self) -> None: ...

283

def __enter__(self) -> ConsumptionManagementClient: ...

284

def __exit__(self, *exc_details) -> None: ...

285

```

286

287

### Common Response Types

288

289

```python { .api }

290

from typing import Iterable, Optional

291

292

# List result containers

293

class UsageDetailsListResult: ...

294

class BudgetsListResult: ...

295

class ChargesListResult: ...

296

class MarketplacesListResult: ...

297

class ReservationSummariesListResult: ...

298

class ReservationDetailsListResult: ...

299

class ReservationRecommendationsListResult: ...

300

class ReservationTransactionsListResult: ...

301

class OperationListResult: ...

302

```

303

304

### Enumeration Types

305

306

```python { .api }

307

# Billing and time-related enums

308

class BillingFrequency: ...

309

class TimeGrainType: ...

310

class Datagrain: ...

311

class Term: ...

312

313

# Budget and operator enums

314

class BudgetOperatorType: ...

315

class OperatorType: ...

316

class ThresholdType: ...

317

class CategoryType: ...

318

319

# Reservation and pricing enums

320

class ReservationRecommendationKind: ...

321

class PricingModelType: ...

322

class LookBackPeriod: ...

323

class Scope: ...

324

325

# Status and metric enums

326

class Status: ...

327

class Metrictype: ...

328

class UsageDetailsKind: ...

329

class ChargeSummaryKind: ...

330

class EventType: ...

331

class LotSource: ...

332

class CultureCode: ...

333

334

# Operations response types

335

class TagsResult: ...

336

class ManagementGroupAggregatedCostResult: ...

337

class OperationListResult: ...

338

class PriceSheetResult: ...

339

```