Skip to main content

Azure Table Utils

A Python client for managing tables and entities in Azure Table Storage, designed to simplify interactions with Azure Storage accounts.

Overview

The AzureStorageTableClient class provides a robust interface to interact with Azure Table Storage. It supports creating, deleting, and listing tables, as well as managing entities (rows) with batch operations and comprehensive error handling.

Features

  • Connect to Azure Table Storage using account name and access key.
  • Create, delete, and list tables.
  • Create or update entities in batches (up to 100 entities per transaction).
  • Delete entities by PartitionKey and RowKey.
  • Validates inputs (e.g., table names, required entity keys, replace blank space to "_" in the columns/properties names). Azure Table does not accept blank space in the columns/properties.
  • Handles Azure service and network errors (e.g., DNS issues, invalid credentials).

Requirements

  • Python 3.11.8 or higher
  • Azure Storage Table account with account_name and access_key
  • azure-data-tables (included in the repository)
  • utils.py (included in the repository)

Installation

pip install azure_table_client

Install the package

from azure_table_client import AzureStorageTableClient, BuilderQuery, Operator import os

Initialize with environment variables

  • account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME")
  • access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY")

Initializing the Client

client = AzureStorageTableClient(account_name=account_name, access_key=access_key) / /

Method Examples

1. get_table_names() -> List[str]

Retrieves a list of table names from the Azure Table service.

Returns

  • List[str]: A list of table names in the Azure Table of the Azure Storage account.

Raises

  • AttributeError: If create_connection() was not called to initialize table_service_client.
  • HttpResponseError: If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError: If there is a network or service connectivity issue.

2. create_table(self, table_name:str) -> bool:

Creates a table in the Azure Table of the Azure Storage account.

Parameters

  • table_name (str): The name for the new table that must be alphanumeric, cannot begin with a number, and must be between 3-63 characters long.

Returns

  • bool: True if the table was successfully created.

Raises

  • ValueError: If the table_name is not alphanumeric, is not between 3-63 characters long, or begins with a number.
  • AttributeError: If create_connection() was not called to initialize table_service_client.
  • HttpResponseError: If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError: If there is a network or service connectivity issue.

3. delete_table(self, table_name:str) -> bool

Checks if the table exists using the method get_table_names(). Deletes a table in the Azure Table of the Azure Storage account.

Parameters

  • table_name (str): The name of the table to be deleted.

Returns

  • bool: True if the table was successfully deleted.

Raises

  • ValueError: If the table_name is empty, invalid, or not found in the storage account.
  • AttributeError: If create_connection() was not called to initialize table_service_client.
  • HttpResponseError: If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError: If there is a network or service connectivity issue.

4. update_create_entity(self, table_name:str, entity:List[dict], mode:Literal['merge', 'replace']='merge') -> None

If the table does not exist, it creates. Calls the function create_entity_batch() to create a list of lists with a maximum of 100 entities each. Creates/Updates an entity (similar to a row) to a table in the Azure Table of the Azure Storage account. If an entity with the same PartitionKey and RowKey already exists, it will be updated with the mode:

  • UpdateMode.REPLACE: Replacing the existing entity with the given one, deleting any existing properties not included in the submitted entity.
  • UpdateMode.MERGE: Updating the existing entity only on the properties provided as argument.

Parameters

  • table_name (str): The name of the table where the entity will be created.
  • entity (List[dict]): A list of at least one dictionary, having these minimal elements {'PartitionKey': <non-empty string>, 'RowKey': <string>}. Additional keys must not have ponctuation or space. Any punctuation is replaced by "_"
  • mode (Literal['merge', 'replace']): The mode for updating the entity:
    • replace: Replacing the existing entity with the given one, deleting any existing properties not included in the submitted entity.
    • merge: Updating the existing entity only on the properties provided as argument.

Returns

  • None

Raises

  • ValueError: If the table_name is empty or invalid, or if the entity is not a non-empty list of non-empty dictionaries, or if its dictionaries do not have the keys PartitionKey or RowKey.
  • AttributeError: If create_connection() was not called to initialize table_service_client.
  • Exception: If create_entity_batch() returns an error.
  • HttpResponseError: If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError: If there is a network or service connectivity issue.

5. delete_entity(self, table_name:str, partition_key:str, row_key:str) -> bool

Deletes an entity from a specific table.

Parameters

  • table_name (str): The name of the table where the entity will be deleted from.
  • partition_key (str): The name of the partition.
  • row_key (str): The name of the row.

Returns

  • bool: True if the entity was successfully deleted.

Raises

  • ValueError: If the table_name, partition_key, or row_key is empty or invalid, or if create_connection() was not called to initialize table_service_client.
  • HttpResponseError: If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError: If there is a network or service connectivity issue.

6. select_entity(self, table_name:str, query_filter:str, parameters: Dict[str, Any]=None, select: str|List[str]=None, results_per_page: int=None) -> Iterator

Make a query to the Azure Storage Table. You can use the class QueryBuilder to create the query. There are two ways to create a query:

        6.1 Using only the parameter 'query_filter'
            query_filter="LastName ge 'A' and LastName lt 'B'"
        
        6.2 Using only the parameter 'query_filter' with the class QueryBuilder
            query_filter = (QueryBuilder()
                            .set_column('LastName')
                            .set_operator(Operator.GREATERTHANOREQUAL)
                            .set_value('A')
                            .set_column('LastName')
                            .set_operator(Operator.LESSTHAN)
                            .set_value('B')
                            .get_query()
                            )
        
        6.3 Using both the parameters 'query_filter' and 'parameters'
            parameters = {"first": first_name, "last": last_name}
            query_filter = "FirstName eq @first or LastName eq @last"

Parameters

  • table_name: str
    • The name of the table where the query will be made.
  • query_filter: str
    • The query itself, following one of the templates provided.
  • parameters: dict, optional
    • The parameters to be passed into the query if using template C.
  • select: str | List[str], optional
    • A string or list of strings representing the columns to be retrieved by the query.
  • results_per_page: int, optional
    • Defines the total number of records per page in the paginated iterator. Default is 1000 records.

Returns

  • Iterator
    • An iterator composed of pages, with each page containing the records.

Raises

  • ValueError
    • If table_name, partition_key, or row_key is empty or invalid.
    • If create_connection() was not called to initialize table_service_client.
  • HttpResponseError
    • If the request to the Azure Table service fails (e.g., invalid credentials or table not found).
  • ServiceRequestError
    • If there is a network or service connectivity issue.

Metadata

Release files for azure-table-utils 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for azure-table-utils 0.0.6
File Size Uploaded Provenance
azure_table_utils-0.0.6.tar.gz 8.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for azure-table-utils 0.0.6
File Interpreter ABI Platform
azure_table_utils-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / azure_table_utils-0.0.6.tar.gz

Download URL azure_table_utils-0.0.6.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
32fd5b747c8eb70680312aec6803598df934e7a7c994f85bb30b454a5ff705b0
BLAKE2b-256 checksum
How to use checksums
e7565dc8f6fcba04fbd29372458bad546b2118f5690e6a5b420b59ef23070272
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / azure_table_utils-0.0.6-py3-none-any.whl

Download URL azure_table_utils-0.0.6-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af22d87f85dc7e092d65be9ae4532b8e2955326e88600c3f3bd76f40978e5bda
BLAKE2b-256 checksum
How to use checksums
73ec8bf0c07ea2899a62ba7f6b5540eb6dd90b6580f5e85105041ef88bbc70e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for azure-table-utils 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page