or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

alerts.mdbenefits.mddimensions.mdexports.mdindex.mdprice-sheet.mdquery-forecast.mdreports.mdscheduled-actions.mdviews.md

price-sheet.mddocs/

0

# Price Sheet Operations

1

2

Download pricing information and rate cards for Azure services through price sheet operations. These operations provide access to current and historical pricing data for billing accounts with Microsoft Partner Agreement or Microsoft Customer Agreement.

3

4

## Capabilities

5

6

### Invoice Price Sheet Download

7

8

Download the price sheet for a specific invoice, providing detailed pricing information for all services used during that billing period.

9

10

```python { .api }

11

def begin_download(

12

billing_account_name: str,

13

billing_profile_name: str,

14

invoice_name: str

15

) -> LROPoller[DownloadURL]:

16

"""

17

Gets a URL to download the pricesheet for an invoice.

18

19

Args:

20

billing_account_name (str): The ID that uniquely identifies a billing account

21

billing_profile_name (str): The ID that uniquely identifies a billing profile

22

invoice_name (str): The ID that uniquely identifies an invoice

23

24

Returns:

25

LROPoller[DownloadURL]: Long-running operation poller for price sheet download

26

27

Note:

28

Supported for billing accounts with Microsoft Partner Agreement or Microsoft Customer Agreement.

29

"""

30

```

31

32

### Current Month Price Sheet Download

33

34

Download the current month's price sheet for a billing profile, providing up-to-date pricing information for all available Azure services.

35

36

```python { .api }

37

def begin_download_by_billing_profile(

38

billing_account_name: str,

39

billing_profile_name: str

40

) -> LROPoller[DownloadURL]:

41

"""

42

Gets a URL to download the current month's pricesheet for a billing profile.

43

44

Args:

45

billing_account_name (str): The ID that uniquely identifies a billing account

46

billing_profile_name (str): The ID that uniquely identifies a billing profile

47

48

Returns:

49

LROPoller[DownloadURL]: Long-running operation poller for price sheet download

50

51

Note:

52

Supported for billing accounts with Microsoft Partner Agreement or Microsoft Customer Agreement.

53

Due to Azure product growth, download may be a Zip file containing multiple CSV files.

54

"""

55

```

56

57

## Usage Examples

58

59

### Download Invoice Price Sheet

60

61

```python

62

from azure.identity import DefaultAzureCredential

63

from azure.mgmt.costmanagement import CostManagementClient

64

65

# Initialize client

66

credential = DefaultAzureCredential()

67

client = CostManagementClient(credential)

68

69

# Define billing identifiers

70

billing_account_name = "12345678-1234-1234-1234-123456789012:12345678-1234-1234-1234-123456789012_2019-05-31"

71

billing_profile_name = "BP123456-5678-9012-3456-789012345678"

72

invoice_name = "INV-2024-01-123456"

73

74

# Start price sheet download

75

print(f"Starting price sheet download for invoice {invoice_name}")

76

operation = client.price_sheet.begin_download(

77

billing_account_name=billing_account_name,

78

billing_profile_name=billing_profile_name,

79

invoice_name=invoice_name

80

)

81

82

print("Price sheet download initiated...")

83

print(f"Operation status: {operation.status()}")

84

85

# Wait for completion

86

result = operation.result()

87

print(f"Download completed. URL expires at: {result.expiry_time}")

88

print(f"Download URL: {result.download_url}")

89

```

90

91

### Download Current Month Price Sheet

92

93

```python

94

import time

95

from datetime import datetime, timedelta

96

97

# Download current month's price sheet

98

print("Starting current month price sheet download...")

99

current_operation = client.price_sheet.begin_download_by_billing_profile(

100

billing_account_name=billing_account_name,

101

billing_profile_name=billing_profile_name

102

)

103

104

print("Current month price sheet download initiated...")

105

106

# Monitor progress

107

while not current_operation.done():

108

print("Price sheet generation in progress...")

109

time.sleep(30) # Wait 30 seconds

110

111

current_result = current_operation.result()

112

print(f"Current month price sheet ready")

113

print(f"Valid until: {current_result.valid_till}")

114

print(f"Download URL: {current_result.download_url}")

115

116

# Download and process price sheet

117

if current_result.download_url:

118

print("Price sheet is ready for download")

119

print(f"URL will expire at: {current_result.expiry_time}")

120

121

# Calculate time remaining

122

if current_result.expiry_time:

123

time_remaining = current_result.expiry_time - datetime.utcnow()

124

print(f"Time remaining to download: {time_remaining}")

125

```

126

127

### Batch Price Sheet Downloads

128

129

```python

130

import concurrent.futures

131

from typing import Dict, List

132

133

def download_price_sheets_for_invoices(invoice_names: List[str]) -> Dict[str, str]:

134

"""Download price sheets for multiple invoices concurrently"""

135

136

def download_single_invoice(invoice_name: str) -> tuple[str, str]:

137

operation = client.price_sheet.begin_download(

138

billing_account_name=billing_account_name,

139

billing_profile_name=billing_profile_name,

140

invoice_name=invoice_name

141

)

142

result = operation.result()

143

return invoice_name, result.download_url

144

145

# Download price sheets concurrently

146

download_urls = {}

147

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:

148

future_to_invoice = {

149

executor.submit(download_single_invoice, invoice): invoice

150

for invoice in invoice_names

151

}

152

153

for future in concurrent.futures.as_completed(future_to_invoice):

154

invoice_name = future_to_invoice[future]

155

try:

156

invoice_name, download_url = future.result()

157

download_urls[invoice_name] = download_url

158

print(f"Price sheet ready for {invoice_name}")

159

except Exception as exc:

160

print(f"Invoice {invoice_name} generated an exception: {exc}")

161

162

return download_urls

163

164

# Download price sheets for multiple invoices

165

invoice_list = ["INV-2024-01-123456", "INV-2024-02-234567", "INV-2024-03-345678"]

166

price_sheet_urls = download_price_sheets_for_invoices(invoice_list)

167

168

for invoice, url in price_sheet_urls.items():

169

print(f"{invoice}: {url}")

170

```

171

172

### Error Handling and Retry Logic

173

174

```python

175

from azure.core.exceptions import HttpResponseError

176

import time

177

178

def download_price_sheet_with_retry(max_retries: int = 3):

179

"""Download price sheet with retry logic for robustness"""

180

181

for attempt in range(max_retries):

182

try:

183

print(f"Attempt {attempt + 1} to download price sheet...")

184

185

operation = client.price_sheet.begin_download_by_billing_profile(

186

billing_account_name=billing_account_name,

187

billing_profile_name=billing_profile_name

188

)

189

190

# Wait for completion with timeout

191

start_time = time.time()

192

timeout = 300 # 5 minutes

193

194

while not operation.done():

195

if time.time() - start_time > timeout:

196

raise TimeoutError("Price sheet download timed out")

197

time.sleep(10)

198

199

result = operation.result()

200

print("Price sheet download successful!")

201

return result

202

203

except HttpResponseError as e:

204

print(f"HTTP error on attempt {attempt + 1}: {e.status_code} - {e.message}")

205

if attempt == max_retries - 1:

206

raise

207

time.sleep(2 ** attempt) # Exponential backoff

208

209

except TimeoutError as e:

210

print(f"Timeout on attempt {attempt + 1}: {e}")

211

if attempt == max_retries - 1:

212

raise

213

time.sleep(30)

214

215

except Exception as e:

216

print(f"Unexpected error on attempt {attempt + 1}: {e}")

217

if attempt == max_retries - 1:

218

raise

219

time.sleep(10)

220

221

# Use retry logic

222

try:

223

price_sheet_result = download_price_sheet_with_retry()

224

print(f"Final download URL: {price_sheet_result.download_url}")

225

except Exception as e:

226

print(f"Failed to download price sheet after retries: {e}")

227

```

228

229

## Data Models

230

231

```python { .api }

232

class DownloadURL:

233

"""

234

The URL to download the generated price sheet.

235

236

Attributes:

237

expiry_time (datetime): The time at which report URL becomes invalid/expires in UTC

238

valid_till (datetime): The time at which report URL becomes invalid/expires in UTC

239

download_url (str): The URL to download the generated price sheet

240

"""

241

expiry_time: datetime

242

valid_till: datetime

243

download_url: str

244

```

245

246

Price sheet operations provide essential functionality for accessing Azure pricing data, supporting both invoice-specific and current pricing information downloads. The operations use long-running operation patterns to handle potentially large price sheet files and support concurrent downloads for multiple billing periods.