0
# Table Storage Management
1
2
Azure Table service configuration and table management operations. Azure Table storage provides a NoSQL key-value store for structured data with fast access and high availability.
3
4
## Capabilities
5
6
### Table Service Configuration
7
8
Configure table service properties including CORS rules, logging, and metrics settings.
9
10
```python { .api }
11
class TableServicesOperations:
12
def get_service_properties(
13
self,
14
resource_group_name: str,
15
account_name: str
16
) -> TableServiceProperties:
17
"""
18
Gets the properties of a storage account's Table service.
19
20
Parameters:
21
- resource_group_name: Name of the resource group
22
- account_name: Name of the storage account
23
24
Returns:
25
TableServiceProperties with current configuration
26
"""
27
28
def set_service_properties(
29
self,
30
resource_group_name: str,
31
account_name: str,
32
parameters: TableServiceProperties
33
) -> TableServiceProperties:
34
"""
35
Sets the properties of a storage account's Table service.
36
37
Parameters:
38
- resource_group_name: Name of the resource group
39
- account_name: Name of the storage account
40
- parameters: Table service properties to configure
41
42
Returns:
43
Updated TableServiceProperties
44
"""
45
46
def list(
47
self,
48
resource_group_name: str,
49
account_name: str
50
) -> ListTableServices:
51
"""
52
Lists all table services for a storage account.
53
54
Parameters:
55
- resource_group_name: Name of the resource group
56
- account_name: Name of the storage account
57
58
Returns:
59
ListTableServices containing table services
60
"""
61
```
62
63
Usage example:
64
65
```python
66
from azure.mgmt.storage.models import (
67
TableServiceProperties, CorsRules, CorsRule
68
)
69
70
# Configure table service with CORS rules for web applications
71
cors_rule = CorsRule(
72
allowed_origins=["https://mywebapp.com", "https://admin.myapp.com"],
73
allowed_methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
74
allowed_headers=["accept", "content-type", "x-ms-version", "x-ms-date"],
75
exposed_headers=["x-ms-request-id", "x-ms-version", "Date"],
76
max_age_in_seconds=7200
77
)
78
79
table_properties = TableServiceProperties(
80
properties=TableServicePropertiesProperties(
81
cors=CorsRules(cors_rules=[cors_rule])
82
)
83
)
84
85
updated_service = client.table_services.set_service_properties(
86
resource_group_name="my-resource-group",
87
account_name="mystorageaccount123",
88
parameters=table_properties
89
)
90
91
# Get current table service properties
92
current_properties = client.table_services.get_service_properties(
93
resource_group_name="my-resource-group",
94
account_name="mystorageaccount123"
95
)
96
97
print(f"Table service configured with {len(current_properties.cors.cors_rules)} CORS rules")
98
```
99
100
### Table Management
101
102
Create, configure, and manage individual tables with access policies and signed identifiers.
103
104
```python { .api }
105
class TableOperations:
106
def create(
107
self,
108
resource_group_name: str,
109
account_name: str,
110
table_name: str,
111
parameters: Table
112
) -> Table:
113
"""
114
Creates a new table with the specified name.
115
116
Parameters:
117
- resource_group_name: Name of the resource group
118
- account_name: Name of the storage account
119
- table_name: Name of the table (3-63 chars, alphanumeric)
120
- parameters: Table properties and configuration
121
122
Returns:
123
Created Table
124
"""
125
126
def update(
127
self,
128
resource_group_name: str,
129
account_name: str,
130
table_name: str,
131
parameters: Table
132
) -> Table:
133
"""
134
Updates table properties or access policies.
135
136
Parameters:
137
- resource_group_name: Name of the resource group
138
- account_name: Name of the storage account
139
- table_name: Name of the table
140
- parameters: Updated table properties
141
142
Returns:
143
Updated Table
144
"""
145
146
def get(
147
self,
148
resource_group_name: str,
149
account_name: str,
150
table_name: str
151
) -> Table:
152
"""
153
Gets the table with the specified name.
154
155
Parameters:
156
- resource_group_name: Name of the resource group
157
- account_name: Name of the storage account
158
- table_name: Name of the table
159
160
Returns:
161
Table with properties and access policies
162
"""
163
164
def delete(
165
self,
166
resource_group_name: str,
167
account_name: str,
168
table_name: str
169
) -> None:
170
"""
171
Deletes the table with the specified name.
172
173
Parameters:
174
- resource_group_name: Name of the resource group
175
- account_name: Name of the storage account
176
- table_name: Name of the table to delete
177
"""
178
179
def list(
180
self,
181
resource_group_name: str,
182
account_name: str
183
) -> ItemPaged[Table]:
184
"""
185
Lists all tables in a storage account.
186
187
Parameters:
188
- resource_group_name: Name of the resource group
189
- account_name: Name of the storage account
190
191
Returns:
192
Paginated list of Table objects
193
"""
194
```
195
196
Usage example:
197
198
```python
199
from azure.mgmt.storage.models import (
200
Table, TableAccessPolicy, TableSignedIdentifier
201
)
202
from datetime import datetime, timedelta
203
204
# Create a table with access policies
205
access_policy = TableAccessPolicy(
206
start_time=datetime.utcnow(),
207
expiry_time=datetime.utcnow() + timedelta(days=30),
208
permissions="raud" # read, add, update, delete
209
)
210
211
signed_identifier = TableSignedIdentifier(
212
id="ReadWritePolicy",
213
access_policy=access_policy
214
)
215
216
new_table = Table(
217
properties=TableProperties(
218
signed_identifiers=[signed_identifier]
219
)
220
)
221
222
created_table = client.table.create(
223
resource_group_name="my-resource-group",
224
account_name="mystorageaccount123",
225
table_name="CustomerData",
226
parameters=new_table
227
)
228
229
print(f"Created table: {created_table.name}")
230
231
# Create multiple tables for different data types
232
table_names = [
233
"UserProfiles",
234
"ProductCatalog",
235
"OrderHistory",
236
"InventoryTracking",
237
"AuditLogs",
238
"SessionData"
239
]
240
241
for table_name in table_names:
242
# Create read-only policy for audit tables
243
if "audit" in table_name.lower() or "log" in table_name.lower():
244
audit_policy = TableAccessPolicy(
245
start_time=datetime.utcnow(),
246
expiry_time=datetime.utcnow() + timedelta(days=365),
247
permissions="r" # read-only
248
)
249
audit_identifier = TableSignedIdentifier(
250
id="ReadOnlyPolicy",
251
access_policy=audit_policy
252
)
253
table_params = Table(
254
properties=TableProperties(
255
signed_identifiers=[audit_identifier]
256
)
257
)
258
else:
259
# Create full access policy for operational tables
260
full_policy = TableAccessPolicy(
261
start_time=datetime.utcnow(),
262
expiry_time=datetime.utcnow() + timedelta(days=90),
263
permissions="raud"
264
)
265
full_identifier = TableSignedIdentifier(
266
id="FullAccessPolicy",
267
access_policy=full_policy
268
)
269
table_params = Table(
270
properties=TableProperties(
271
signed_identifiers=[full_identifier]
272
)
273
)
274
275
client.table.create(
276
resource_group_name="my-resource-group",
277
account_name="mystorageaccount123",
278
table_name=table_name,
279
parameters=table_params
280
)
281
282
# List all tables
283
tables = list(client.table.list(
284
resource_group_name="my-resource-group",
285
account_name="mystorageaccount123"
286
))
287
288
print(f"Total tables: {len(tables)}")
289
for table in tables:
290
print(f"Table: {table.name}")
291
if hasattr(table, 'properties') and table.properties.signed_identifiers:
292
for identifier in table.properties.signed_identifiers:
293
print(f" Policy: {identifier.id}, Permissions: {identifier.access_policy.permissions}")
294
295
# Update table access policy
296
updated_policy = TableAccessPolicy(
297
start_time=datetime.utcnow(),
298
expiry_time=datetime.utcnow() + timedelta(days=60),
299
permissions="rau" # removed delete permission
300
)
301
302
updated_identifier = TableSignedIdentifier(
303
id="RestrictedPolicy",
304
access_policy=updated_policy
305
)
306
307
updated_table = Table(
308
properties=TableProperties(
309
signed_identifiers=[updated_identifier]
310
)
311
)
312
313
client.table.update(
314
resource_group_name="my-resource-group",
315
account_name="mystorageaccount123",
316
table_name="CustomerData",
317
parameters=updated_table
318
)
319
320
# Get specific table details
321
table_details = client.table.get(
322
resource_group_name="my-resource-group",
323
account_name="mystorageaccount123",
324
table_name="CustomerData"
325
)
326
327
print(f"Table details for {table_details.name}:")
328
print(f" ID: {table_details.id}")
329
print(f" Type: {table_details.type_}")
330
if table_details.properties.signed_identifiers:
331
for identifier in table_details.properties.signed_identifiers:
332
print(f" Policy: {identifier.id}")
333
print(f" Permissions: {identifier.access_policy.permissions}")
334
print(f" Expires: {identifier.access_policy.expiry_time}")
335
```
336
337
### Table Access Control
338
339
Generate SAS tokens for table access with fine-grained permissions.
340
341
```python
342
# Example of generating SAS tokens for table access
343
from azure.mgmt.storage.models import ServiceSasParameters, Services, SignedResourceTypes
344
345
# Generate SAS token for specific table with read/write access
346
table_sas_params = ServiceSasParameters(
347
canonical_name=f"/table/mystorageaccount123/CustomerData",
348
resource=SignedResource.O, # Object (table)
349
permissions=Permissions.RAU, # Read, Add, Update
350
services=Services.T, # Table service
351
resource_types=SignedResourceTypes.O, # Object
352
shared_access_start_time=datetime.utcnow(),
353
shared_access_expiry_time=datetime.utcnow() + timedelta(hours=8),
354
partition_key_start="Customer001",
355
partition_key_end="Customer999",
356
row_key_start="2024-01-01",
357
row_key_end="2024-12-31"
358
)
359
360
sas_response = client.storage_accounts.list_service_sas(
361
resource_group_name="my-resource-group",
362
account_name="mystorageaccount123",
363
parameters=table_sas_params
364
)
365
366
print(f"SAS token for table access: {sas_response.service_sas_token}")
367
368
# Generate read-only SAS for analytics
369
readonly_sas_params = ServiceSasParameters(
370
canonical_name=f"/table/mystorageaccount123/AuditLogs",
371
resource=SignedResource.O,
372
permissions=Permissions.R, # Read-only
373
services=Services.T,
374
resource_types=SignedResourceTypes.O,
375
shared_access_expiry_time=datetime.utcnow() + timedelta(days=7)
376
)
377
378
readonly_sas = client.storage_accounts.list_service_sas(
379
resource_group_name="my-resource-group",
380
account_name="mystorageaccount123",
381
parameters=readonly_sas_params
382
)
383
384
print(f"Read-only SAS for audit logs: {readonly_sas.service_sas_token}")
385
```
386
387
## Types
388
389
```python { .api }
390
class TableServiceProperties:
391
"""Table service properties configuration."""
392
id: str
393
name: str
394
type_: str
395
properties: TableServicePropertiesProperties
396
397
class TableServicePropertiesProperties:
398
"""Properties of table service."""
399
cors: CorsRules
400
401
class Table:
402
"""Table resource."""
403
id: str
404
name: str
405
type_: str
406
properties: TableProperties
407
408
class TableProperties:
409
"""Properties of a table."""
410
table_name: str
411
signed_identifiers: List[TableSignedIdentifier]
412
413
class TableSignedIdentifier:
414
"""Signed identifier for table access."""
415
id: str
416
access_policy: TableAccessPolicy
417
418
class TableAccessPolicy:
419
"""Access policy for table operations."""
420
start_time: datetime
421
expiry_time: datetime
422
permissions: str
423
424
class ListTableServices:
425
"""List of table services."""
426
value: List[TableServiceProperties]
427
428
class ListTableResource:
429
"""Table resource in list results."""
430
name: str
431
properties: TableProperties
432
```