CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-mgmt-storage

Microsoft Azure Storage Management Client Library for Python

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

table-storage.mddocs/

Table Storage Management

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.

Capabilities

Table Service Configuration

Configure table service properties including CORS rules, logging, and metrics settings.

class TableServicesOperations:
    def get_service_properties(
        self,
        resource_group_name: str,
        account_name: str
    ) -> TableServiceProperties:
        """
        Gets the properties of a storage account's Table service.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        
        Returns:
        TableServiceProperties with current configuration
        """
    
    def set_service_properties(
        self,
        resource_group_name: str,
        account_name: str,
        parameters: TableServiceProperties
    ) -> TableServiceProperties:
        """
        Sets the properties of a storage account's Table service.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        - parameters: Table service properties to configure
        
        Returns:
        Updated TableServiceProperties
        """
    
    def list(
        self,
        resource_group_name: str,
        account_name: str
    ) -> ListTableServices:
        """
        Lists all table services for a storage account.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        
        Returns:
        ListTableServices containing table services
        """

Usage example:

from azure.mgmt.storage.models import (
    TableServiceProperties, CorsRules, CorsRule
)

# Configure table service with CORS rules for web applications
cors_rule = CorsRule(
    allowed_origins=["https://mywebapp.com", "https://admin.myapp.com"],
    allowed_methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
    allowed_headers=["accept", "content-type", "x-ms-version", "x-ms-date"],
    exposed_headers=["x-ms-request-id", "x-ms-version", "Date"],
    max_age_in_seconds=7200
)

table_properties = TableServiceProperties(
    properties=TableServicePropertiesProperties(
        cors=CorsRules(cors_rules=[cors_rule])
    )
)

updated_service = client.table_services.set_service_properties(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    parameters=table_properties
)

# Get current table service properties
current_properties = client.table_services.get_service_properties(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123"
)

print(f"Table service configured with {len(current_properties.cors.cors_rules)} CORS rules")

Table Management

Create, configure, and manage individual tables with access policies and signed identifiers.

class TableOperations:
    def create(
        self,
        resource_group_name: str,
        account_name: str,
        table_name: str,
        parameters: Table
    ) -> Table:
        """
        Creates a new table with the specified name.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        - table_name: Name of the table (3-63 chars, alphanumeric)
        - parameters: Table properties and configuration
        
        Returns:
        Created Table
        """
    
    def update(
        self,
        resource_group_name: str,
        account_name: str,
        table_name: str,
        parameters: Table
    ) -> Table:
        """
        Updates table properties or access policies.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        - table_name: Name of the table
        - parameters: Updated table properties
        
        Returns:
        Updated Table
        """
    
    def get(
        self,
        resource_group_name: str,
        account_name: str,
        table_name: str
    ) -> Table:
        """
        Gets the table with the specified name.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        - table_name: Name of the table
        
        Returns:
        Table with properties and access policies
        """
    
    def delete(
        self,
        resource_group_name: str,
        account_name: str,
        table_name: str
    ) -> None:
        """
        Deletes the table with the specified name.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        - table_name: Name of the table to delete
        """
    
    def list(
        self,
        resource_group_name: str,
        account_name: str
    ) -> ItemPaged[Table]:
        """
        Lists all tables in a storage account.
        
        Parameters:
        - resource_group_name: Name of the resource group
        - account_name: Name of the storage account
        
        Returns:
        Paginated list of Table objects
        """

Usage example:

from azure.mgmt.storage.models import (
    Table, TableAccessPolicy, TableSignedIdentifier
)
from datetime import datetime, timedelta

# Create a table with access policies
access_policy = TableAccessPolicy(
    start_time=datetime.utcnow(),
    expiry_time=datetime.utcnow() + timedelta(days=30),
    permissions="raud"  # read, add, update, delete
)

signed_identifier = TableSignedIdentifier(
    id="ReadWritePolicy",
    access_policy=access_policy
)

new_table = Table(
    properties=TableProperties(
        signed_identifiers=[signed_identifier]
    )
)

created_table = client.table.create(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    table_name="CustomerData",
    parameters=new_table
)

print(f"Created table: {created_table.name}")

# Create multiple tables for different data types
table_names = [
    "UserProfiles",
    "ProductCatalog", 
    "OrderHistory",
    "InventoryTracking",
    "AuditLogs",
    "SessionData"
]

for table_name in table_names:
    # Create read-only policy for audit tables
    if "audit" in table_name.lower() or "log" in table_name.lower():
        audit_policy = TableAccessPolicy(
            start_time=datetime.utcnow(),
            expiry_time=datetime.utcnow() + timedelta(days=365),
            permissions="r"  # read-only
        )
        audit_identifier = TableSignedIdentifier(
            id="ReadOnlyPolicy",
            access_policy=audit_policy
        )
        table_params = Table(
            properties=TableProperties(
                signed_identifiers=[audit_identifier]
            )
        )
    else:
        # Create full access policy for operational tables
        full_policy = TableAccessPolicy(
            start_time=datetime.utcnow(),
            expiry_time=datetime.utcnow() + timedelta(days=90),
            permissions="raud"
        )
        full_identifier = TableSignedIdentifier(
            id="FullAccessPolicy",
            access_policy=full_policy
        )
        table_params = Table(
            properties=TableProperties(
                signed_identifiers=[full_identifier]
            )
        )
    
    client.table.create(
        resource_group_name="my-resource-group",
        account_name="mystorageaccount123",
        table_name=table_name,
        parameters=table_params
    )

# List all tables
tables = list(client.table.list(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123"
))

print(f"Total tables: {len(tables)}")
for table in tables:
    print(f"Table: {table.name}")
    if hasattr(table, 'properties') and table.properties.signed_identifiers:
        for identifier in table.properties.signed_identifiers:
            print(f"  Policy: {identifier.id}, Permissions: {identifier.access_policy.permissions}")

# Update table access policy
updated_policy = TableAccessPolicy(
    start_time=datetime.utcnow(),
    expiry_time=datetime.utcnow() + timedelta(days=60),
    permissions="rau"  # removed delete permission
)

updated_identifier = TableSignedIdentifier(
    id="RestrictedPolicy",
    access_policy=updated_policy
)

updated_table = Table(
    properties=TableProperties(
        signed_identifiers=[updated_identifier]
    )
)

client.table.update(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    table_name="CustomerData",
    parameters=updated_table
)

# Get specific table details
table_details = client.table.get(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    table_name="CustomerData"
)

print(f"Table details for {table_details.name}:")
print(f"  ID: {table_details.id}")
print(f"  Type: {table_details.type_}")
if table_details.properties.signed_identifiers:
    for identifier in table_details.properties.signed_identifiers:
        print(f"  Policy: {identifier.id}")
        print(f"    Permissions: {identifier.access_policy.permissions}")
        print(f"    Expires: {identifier.access_policy.expiry_time}")

Table Access Control

Generate SAS tokens for table access with fine-grained permissions.

# Example of generating SAS tokens for table access
from azure.mgmt.storage.models import ServiceSasParameters, Services, SignedResourceTypes

# Generate SAS token for specific table with read/write access
table_sas_params = ServiceSasParameters(
    canonical_name=f"/table/mystorageaccount123/CustomerData",
    resource=SignedResource.O,  # Object (table)
    permissions=Permissions.RAU,  # Read, Add, Update
    services=Services.T,  # Table service
    resource_types=SignedResourceTypes.O,  # Object
    shared_access_start_time=datetime.utcnow(),
    shared_access_expiry_time=datetime.utcnow() + timedelta(hours=8),
    partition_key_start="Customer001",
    partition_key_end="Customer999",
    row_key_start="2024-01-01",
    row_key_end="2024-12-31"
)

sas_response = client.storage_accounts.list_service_sas(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    parameters=table_sas_params
)

print(f"SAS token for table access: {sas_response.service_sas_token}")

# Generate read-only SAS for analytics
readonly_sas_params = ServiceSasParameters(
    canonical_name=f"/table/mystorageaccount123/AuditLogs",
    resource=SignedResource.O,
    permissions=Permissions.R,  # Read-only
    services=Services.T,
    resource_types=SignedResourceTypes.O,
    shared_access_expiry_time=datetime.utcnow() + timedelta(days=7)
)

readonly_sas = client.storage_accounts.list_service_sas(
    resource_group_name="my-resource-group",
    account_name="mystorageaccount123",
    parameters=readonly_sas_params
)

print(f"Read-only SAS for audit logs: {readonly_sas.service_sas_token}")

Types

class TableServiceProperties:
    """Table service properties configuration."""
    id: str
    name: str
    type_: str
    properties: TableServicePropertiesProperties

class TableServicePropertiesProperties:
    """Properties of table service."""
    cors: CorsRules

class Table:
    """Table resource."""
    id: str
    name: str
    type_: str
    properties: TableProperties

class TableProperties:
    """Properties of a table."""
    table_name: str
    signed_identifiers: List[TableSignedIdentifier]

class TableSignedIdentifier:
    """Signed identifier for table access."""
    id: str
    access_policy: TableAccessPolicy

class TableAccessPolicy:
    """Access policy for table operations."""
    start_time: datetime
    expiry_time: datetime
    permissions: str

class ListTableServices:
    """List of table services."""
    value: List[TableServiceProperties]

class ListTableResource:
    """Table resource in list results."""
    name: str
    properties: TableProperties

Install with Tessl CLI

npx tessl i tessl/pypi-azure-mgmt-storage

docs

blob-storage.md

file-storage.md

index.md

policy-management.md

queue-storage.md

security-access.md

storage-accounts.md

storage-tasks.md

table-storage.md

utilities.md

tile.json