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

budget-management.mddocs/

0

# Budget Management

1

2

Create, update, and manage budgets with notifications, alerts, and spending controls for comprehensive cost management across different Azure scopes. This module provides full CRUD operations for budget lifecycle management.

3

4

## Capabilities

5

6

### Budget Listing

7

8

Retrieve all budgets for a specified scope.

9

10

```python { .api }

11

def list(scope: str, **kwargs) -> Iterable[BudgetsListResult]:

12

"""

13

List all budgets for the defined scope.

14

15

Parameters:

16

- scope: The scope for the budget query (str)

17

18

Returns:

19

Iterable[BudgetsListResult]: Collection of budgets

20

"""

21

```

22

23

### Budget Retrieval

24

25

Get a specific budget by name and scope.

26

27

```python { .api }

28

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

29

"""

30

Get a specific budget by scope and budget name.

31

32

Parameters:

33

- scope: The scope for the budget (str)

34

- budget_name: Name of the budget (str)

35

36

Returns:

37

Budget: The budget details

38

"""

39

```

40

41

### Budget Creation and Updates

42

43

Create new budgets or update existing ones with comprehensive configuration options.

44

45

```python { .api }

46

def create_or_update(

47

scope: str,

48

budget_name: str,

49

parameters: Budget,

50

**kwargs

51

) -> Budget:

52

"""

53

Create or update a budget with notification settings.

54

55

Parameters:

56

- scope: The scope for the budget (str)

57

- budget_name: Name of the budget (str)

58

- parameters: Budget configuration (Budget)

59

60

Returns:

61

Budget: The created or updated budget

62

"""

63

```

64

65

### Budget Deletion

66

67

Remove budgets that are no longer needed.

68

69

```python { .api }

70

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

71

"""

72

Delete a specific budget.

73

74

Parameters:

75

- scope: The scope for the budget (str)

76

- budget_name: Name of the budget to delete (str)

77

"""

78

```

79

80

**Usage Example:**

81

82

```python

83

# Create a monthly budget with notifications

84

scope = f"/subscriptions/{subscription_id}"

85

budget_name = "monthly-cost-budget"

86

87

# Define budget configuration

88

from azure.mgmt.consumption.models import (

89

Budget, BudgetTimePeriod, CurrentSpend, ForecastSpend, Notification

90

)

91

92

budget_config = Budget(

93

category="Cost",

94

amount=1000.0,

95

time_grain="Monthly",

96

time_period=BudgetTimePeriod(

97

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

98

),

99

current_spend=CurrentSpend(amount=0.0, unit="USD"),

100

notifications={

101

"actual_50": Notification(

102

enabled=True,

103

operator="GreaterThan",

104

threshold=50,

105

contact_emails=["finance@company.com"],

106

contact_groups=[],

107

contact_roles=["Owner"]

108

),

109

"actual_80": Notification(

110

enabled=True,

111

operator="GreaterThan",

112

threshold=80,

113

contact_emails=["finance@company.com", "admin@company.com"],

114

contact_groups=[],

115

contact_roles=["Owner", "Contributor"]

116

),

117

"forecast_100": Notification(

118

enabled=True,

119

operator="GreaterThan",

120

threshold=100,

121

contact_emails=["finance@company.com"],

122

contact_groups=[],

123

contact_roles=["Owner"],

124

threshold_type="Forecasted"

125

)

126

}

127

)

128

129

# Create the budget

130

created_budget = client.budgets.create_or_update(

131

scope=scope,

132

budget_name=budget_name,

133

parameters=budget_config

134

)

135

136

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

137

print(f"Amount: {created_budget.amount} {created_budget.current_spend.unit}")

138

139

# List all budgets

140

budgets = client.budgets.list(scope=scope)

141

for budget in budgets:

142

print(f"Budget: {budget.name} - {budget.amount}")

143

print(f"Current spend: {budget.current_spend.amount}")

144

if budget.forecast_spend:

145

print(f"Forecasted spend: {budget.forecast_spend.amount}")

146

147

# Update budget amount

148

budget_config.amount = 1500.0

149

updated_budget = client.budgets.create_or_update(

150

scope=scope,

151

budget_name=budget_name,

152

parameters=budget_config

153

)

154

155

# Get specific budget

156

budget = client.budgets.get(scope=scope, budget_name=budget_name)

157

print(f"Retrieved budget: {budget.name}")

158

159

# Delete budget when no longer needed

160

client.budgets.delete(scope=scope, budget_name=budget_name)

161

print("Budget deleted")

162

```

163

164

## Types

165

166

### Budget Models

167

168

```python { .api }

169

class Budget:

170

"""Budget configuration and status."""

171

id: str

172

name: str

173

type: str

174

etag: str

175

category: str # "Cost" or "Usage"

176

amount: float

177

time_grain: str # "Monthly", "Quarterly", "Annually", "BillingMonth", "BillingQuarter", "BillingAnnual"

178

time_period: BudgetTimePeriod

179

filter: BudgetFilter

180

current_spend: CurrentSpend

181

forecast_spend: ForecastSpend

182

notifications: Dict[str, Notification]

183

184

class BudgetTimePeriod:

185

"""Time period configuration for budget."""

186

start_date: str # ISO 8601 datetime

187

end_date: str # ISO 8601 datetime (optional)

188

189

class CurrentSpend:

190

"""Current spending information."""

191

amount: float

192

unit: str # Currency code

193

194

class ForecastSpend:

195

"""Forecasted spending information."""

196

amount: float

197

unit: str # Currency code

198

```

199

200

### Budget Filtering

201

202

```python { .api }

203

class BudgetFilter:

204

"""Filtering options for budget scope."""

205

and_: List[BudgetFilterProperties]

206

or_: List[BudgetFilterProperties]

207

not_: BudgetFilterProperties

208

dimensions: BudgetComparisonExpression

209

tags: BudgetComparisonExpression

210

211

class BudgetFilterProperties:

212

"""Individual filter properties."""

213

dimensions: BudgetComparisonExpression

214

tags: BudgetComparisonExpression

215

216

class BudgetComparisonExpression:

217

"""Comparison expression for budget filters."""

218

name: str

219

operator: str # "In", "Contains"

220

values: List[str]

221

```

222

223

### Notification Configuration

224

225

```python { .api }

226

class Notification:

227

"""Budget notification settings."""

228

enabled: bool

229

operator: str # "EqualTo", "GreaterThan", "GreaterThanOrEqualTo"

230

threshold: float # Percentage (0-1000)

231

contact_emails: List[str]

232

contact_groups: List[str]

233

contact_roles: List[str] # "Owner", "Contributor", "Reader"

234

threshold_type: str # "Actual" or "Forecasted"

235

locale: str # Culture code for notifications

236

```

237

238

### List Results

239

240

```python { .api }

241

class BudgetsListResult:

242

"""Container for budget list response."""

243

value: List[Budget]

244

next_link: str

245

```

246

247

### Enumeration Types

248

249

```python { .api }

250

class CategoryType:

251

"""Budget category types."""

252

COST = "Cost"

253

USAGE = "Usage"

254

255

class TimeGrainType:

256

"""Time grain options for budgets."""

257

MONTHLY = "Monthly"

258

QUARTERLY = "Quarterly"

259

ANNUALLY = "Annually"

260

BILLING_MONTH = "BillingMonth"

261

BILLING_QUARTER = "BillingQuarter"

262

BILLING_ANNUAL = "BillingAnnual"

263

264

class BudgetOperatorType:

265

"""Budget comparison operators."""

266

IN = "In"

267

CONTAINS = "Contains"

268

269

class OperatorType:

270

"""Notification threshold operators."""

271

EQUAL_TO = "EqualTo"

272

GREATER_THAN = "GreaterThan"

273

GREATER_THAN_OR_EQUAL_TO = "GreaterThanOrEqualTo"

274

275

class ThresholdType:

276

"""Notification threshold types."""

277

ACTUAL = "Actual"

278

FORECASTED = "Forecasted"

279

```