CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-azure-data-tables

Microsoft Azure Data Tables Client Library for Python

90

0.96x
Overview
Eval results
Files

service-management.mddocs/

Service Management

Account-level operations for managing Azure Tables service including table lifecycle management, service configuration, analytics, and Cross-Origin Resource Sharing (CORS) settings.

Capabilities

Service Client Initialization

Create and configure TableServiceClient for account-level operations with various authentication methods.

class TableServiceClient:
    def __init__(
        self,
        endpoint: str,
        credential: Optional[Any] = None,
        *,
        audience: Optional[str] = None,
        api_version: Optional[str] = None,
        **kwargs
    ):
        """
        Initialize TableServiceClient for account-level operations.

        Parameters:
        - endpoint: Full URL to the Tables account
        - credential: Authentication credential (AzureNamedKeyCredential, SAS token, etc.)
        - audience: Service audience for token authentication
        - api_version: Storage API version to use
        """

    @classmethod
    def from_connection_string(
        cls,
        conn_str: str,
        **kwargs
    ) -> "TableServiceClient":
        """
        Create client from connection string.

        Parameters:
        - conn_str: Connection string with account credentials

        Returns:
        TableServiceClient instance
        """

Usage Example

from azure.data.tables import TableServiceClient
from azure.core.credentials import AzureNamedKeyCredential

# From connection string
service_client = TableServiceClient.from_connection_string(
    conn_str="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey"
)

# From endpoint and credential
credential = AzureNamedKeyCredential("myaccount", "mykey")
service_client = TableServiceClient(
    endpoint="https://myaccount.table.core.windows.net/",
    credential=credential
)

Table Management

Create, delete, list, and query tables within the storage account.

class TableServiceClient:
    def create_table(self, table_name: str, **kwargs) -> TableClient:
        """
        Create a new table.

        Parameters:
        - table_name: Name of the table to create

        Returns:
        TableClient for the created table

        Raises:
        ResourceExistsError: If table already exists
        """

    def create_table_if_not_exists(self, table_name: str, **kwargs) -> TableClient:
        """
        Create table if it doesn't exist.

        Parameters:
        - table_name: Name of the table

        Returns:
        TableClient for the table
        """

    def delete_table(self, table_name: str, **kwargs) -> None:
        """
        Delete a table.

        Parameters:
        - table_name: Name of the table to delete

        Raises:
        ResourceNotFoundError: If table doesn't exist
        """

    def list_tables(
        self,
        *,
        results_per_page: Optional[int] = None,
        **kwargs
    ) -> ItemPaged[TableItem]:
        """
        List all tables in the account.

        Parameters:
        - results_per_page: Maximum number of tables per page

        Returns:
        Paged iterator of TableItem objects
        """

    def query_tables(
        self,
        query_filter: str,
        *,
        results_per_page: Optional[int] = None,
        parameters: Optional[Dict[str, Any]] = None,
        **kwargs
    ) -> ItemPaged[TableItem]:
        """
        Query tables with OData filter.

        Parameters:
        - query_filter: OData filter expression
        - results_per_page: Maximum results per page
        - parameters: Parameter substitution values

        Returns:
        Paged iterator of matching TableItem objects
        """

    def get_table_client(self, table_name: str, **kwargs) -> TableClient:
        """
        Get TableClient for specific table.

        Parameters:
        - table_name: Name of the table

        Returns:
        TableClient instance
        """

Usage Example

from azure.data.tables import TableServiceClient

service_client = TableServiceClient.from_connection_string(conn_str)

# Create table
table_client = service_client.create_table("customers")

# List all tables
for table in service_client.list_tables():
    print(f"Table: {table.name}")

# Query tables by name pattern
tables = service_client.query_tables("TableName ge 'c'")
for table in tables:
    print(f"Found table: {table.name}")

# Delete table
service_client.delete_table("old_table")

Service Properties

Configure service-level settings including analytics logging, metrics collection, and CORS rules.

class TableServiceClient:
    def get_service_properties(self, **kwargs) -> Dict[str, object]:
        """
        Get current service properties.

        Returns:
        Dictionary containing service configuration including:
        - analytics_logging: TableAnalyticsLogging settings
        - hour_metrics: TableMetrics for hourly data
        - minute_metrics: TableMetrics for minute data
        - cors: List of TableCorsRule objects
        """

    def set_service_properties(
        self,
        *,
        analytics_logging: Optional[TableAnalyticsLogging] = None,
        hour_metrics: Optional[TableMetrics] = None,
        minute_metrics: Optional[TableMetrics] = None,
        cors: Optional[List[TableCorsRule]] = None,
        **kwargs
    ) -> None:
        """
        Set service properties.

        Parameters:
        - analytics_logging: Logging configuration
        - hour_metrics: Hourly metrics configuration
        - minute_metrics: Minute metrics configuration
        - cors: CORS rules list
        """

    def get_service_stats(self, **kwargs) -> Dict[str, object]:
        """
        Get service statistics including geo-replication status.

        Returns:
        Dictionary with replication statistics

        Note:
        Only available for read-access geo-redundant storage accounts
        """

Usage Example

from azure.data.tables import (
    TableServiceClient, TableAnalyticsLogging, 
    TableMetrics, TableRetentionPolicy, TableCorsRule
)

service_client = TableServiceClient.from_connection_string(conn_str)

# Configure analytics logging
logging_config = TableAnalyticsLogging(
    version="1.0",
    delete=True,
    read=True,
    write=True,
    retention_policy=TableRetentionPolicy(enabled=True, days=7)
)

# Configure metrics
metrics_config = TableMetrics(
    version="1.0",
    enabled=True,
    include_apis=True,
    retention_policy=TableRetentionPolicy(enabled=True, days=30)
)

# Configure CORS
cors_rule = TableCorsRule(
    allowed_origins=["https://example.com"],
    allowed_methods=["GET", "POST"],
    allowed_headers=["x-ms-*"],
    exposed_headers=["x-ms-*"],
    max_age_in_seconds=3600
)

# Apply configuration
service_client.set_service_properties(
    analytics_logging=logging_config,
    hour_metrics=metrics_config,
    minute_metrics=metrics_config,
    cors=[cors_rule]
)

# Get current properties
properties = service_client.get_service_properties()
print(f"Logging enabled: {properties['analytics_logging'].read}")

Data Models

class TableItem:
    """Represents a table in the service."""
    name: str

class TableAnalyticsLogging:
    """Analytics logging configuration."""
    def __init__(
        self,
        version: str = "1.0",
        delete: bool = False,
        read: bool = False,
        write: bool = False,
        retention_policy: TableRetentionPolicy = None
    ): ...

class TableMetrics:
    """Service metrics configuration."""
    def __init__(
        self,
        version: str = "1.0",
        enabled: bool = False,
        include_apis: bool = None,
        retention_policy: TableRetentionPolicy = None
    ): ...

class TableRetentionPolicy:
    """Data retention policy."""
    def __init__(self, enabled: bool = False, days: int = None): ...

class TableCorsRule:
    """Cross-Origin Resource Sharing rule."""
    def __init__(
        self,
        allowed_origins: List[str],
        allowed_methods: List[str],
        allowed_headers: List[str],
        exposed_headers: List[str],
        max_age_in_seconds: int
    ): ...

Install with Tessl CLI

npx tessl i tessl/pypi-azure-data-tables

docs

async-operations.md

batch-operations.md

entity-data-types.md

error-handling.md

index.md

security-access-control.md

service-management.md

table-operations.md

tile.json