Registry / azure / azure-data-tables

azure-data-tables

JSON →
library12.7.0pypypi✓ verified 25d ago

The `azure-data-tables` library is the Python SDK for Azure Table Storage and Azure Cosmos DB for Table API. It provides synchronous and asynchronous clients for managing tables, entities, and performing queries. This library is part of the 'track 2' Azure SDK, offering a modern, consistent, and Pythonic interface. The current stable version is 12.7.0, with releases typically aligning with broader Azure SDK updates for bug fixes and minor features.

pip install azure-data-tables
INSTALL
IMPORT
SIG · AZURE-DATA-TABLES
A
azure-data-tables
azurepythonv12.7.0
Install
3.4s avg
Import
470ms
Disk
25MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v12.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.500s · 25.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.4s · import 0.440s · 27MB
25MB installed
● package 25MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TableServiceClient
from azure.data.tables import TableServiceClient
from azure.cosmosdb.table import TableService
Old 'track 1' SDK (azure-cosmosdb-table or azure-storage-table) uses different client names and import paths. azure-data-tables is the modern 'track 2' library.
TableClient
from azure.data.tables import TableClient
ResourceExistsError
from azure.core.exceptions import ResourceExistsError
Common Azure SDK exceptions are found in azure.core.exceptions.

This quickstart demonstrates how to initialize a `TableServiceClient` using a connection string, create a table, add an entity, query for it, and then delete it. For production, consider using `azure-identity` with `DefaultAzureCredential` and an endpoint URL for authentication.

import os from azure.data.tables import TableServiceClient, TableEntity from azure.core.exceptions import ResourceExistsError # --- Configuration --- # Replace with your storage account connection string or set as an environment variable # Example: 'DefaultEndpointsProtocol=https;AccountName=<account>;AccountKey=<key>;EndpointSuffix=core.windows.net' connection_string = os.environ.get('AZURE_TABLES_CONNECTION_STRING', 'YOUR_CONNECTION_STRING_HERE') # --- Client Initialization --- # For AAD auth, use TableServiceClient(endpoint=os.environ.get('AZURE_TABLES_ENDPOINT'), credential=DefaultAzureCredential()) # Ensure 'AZURE_TABLES_ENDPOINT' is set (e.g., 'https://<accountname>.table.core.windows.net/') try: table_service_client = TableServiceClient.from_connection_string(conn_str=connection_string) table_name = "MyTestTable" table_client = table_service_client.get_table_client(table_name=table_name) # --- Create Table (if it doesn't exist) --- try: print(f"Creating table '{table_name}'...") table_client.create_table() print(f"Table '{table_name}' created.") except ResourceExistsError: print(f"Table '{table_name}' already exists.") # --- Add an Entity --- print("Adding entity...") entity = TableEntity(PartitionKey="pk1", RowKey="rk1", name="Alice", age=30) table_client.upsert_entity(entity) print("Entity added/updated.") # --- Query Entity --- print("Querying entity...") queried_entity = table_client.get_entity(partition_key="pk1", row_key="rk1") print(f"Queried entity: {queried_entity['name']}, {queried_entity['age']}") # --- List Entities (simple query) --- print("Listing entities...") entities = table_client.query_entities(filter="PartitionKey eq 'pk1'") for ent in entities: print(f" - PK: {ent['PartitionKey']}, RK: {ent['RowKey']}, Name: {ent.get('name')}") # --- Delete Entity --- print("Deleting entity...") table_client.delete_entity(partition_key="pk1", row_key="rk1") print("Entity deleted.") # --- Delete Table (cleanup) --- # print(f"Deleting table '{table_name}'...") # table_client.delete_table() # print(f"Table '{table_name}' deleted.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingMajor API changes exist when migrating from older Azure Table Storage SDKs (e.g., `azure-storage-table` v1.x or `azure-cosmosdb-table`) to `azure-data-tables` (v12.x). This is a complete re-architecture following Azure SDK 'track 2' guidelines.
fix
Rewrite client initialization (`TableServiceClient.from_connection_string` or `TableServiceClient(endpoint, credential)`), entity operations (`create_table`, `upsert_entity`, `get_entity`, `query_entities`, `delete_entity`), and exception handling to match the new API surface. Consult the official migration guide.
affects: All versions before 12.0.0 (i.e., v12.x compared to v1.x of older libraries)
gotchaAzure Table Storage/Cosmos DB for Table API require every entity to have a `PartitionKey` and `RowKey`. These must be string types and together form the unique identifier for an entity within a table.
fix
Always include `PartitionKey` and `RowKey` in your `TableEntity` objects. Ensure they are strings. Design your keys carefully to optimize queries and transactions.
affects: All
gotchaAzure Table Storage operations (especially queries) are eventually consistent. A write operation might not be immediately visible to subsequent read operations across all nodes.
fix
Design your application with eventual consistency in mind. For operations requiring immediate consistency, consider using Cosmos DB with strong consistency levels, but be aware of higher costs.
affects: All
gotchaEntity Group Transactions (EGTs) are limited. All operations within an EGT (batch operation) must operate on entities that share the *same PartitionKey*.
fix
When using `submit_transaction`, ensure all entities in the transaction batch have identical `PartitionKey` values. If you need to update entities with different partition keys, you must perform separate operations.
affects: All
breakingClient initialization using a connection string (`TableServiceClient.from_connection_string`) will fail if the connection string is blank or malformed. It must adhere to a specific format including protocol, account name, and account key.
fix
Ensure the connection string provided is not empty and is correctly formatted (e.g., `DefaultEndpointsProtocol=https;AccountName=<your_account_name>;AccountKey=<your_account_key>;EndpointSuffix=core.windows.net`). Double-check for typos or missing components. Alternatively, initialize the client using an endpoint and a `TableSharedKeyCredential`.
affects: All
gotchaThe Azure Table Storage client requires a valid connection string or endpoint and credentials for initialization. An empty, malformed, or missing connection string/credentials will prevent the client from connecting to the service.
fix
Ensure the connection string (e.g., obtained from the Azure portal) or endpoint and credentials are correctly provided to `TableServiceClient.from_connection_string` or `TableServiceClient(endpoint, credential)`. Verify their format and completeness.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.data.tables'
The 'azure-data-tables' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install azure-data-tables'.
ImportError: cannot import name 'TableServiceClient' from 'azure.data.tables'
The 'azure-data-tables' package is not installed or the import statement is incorrect.
fix
Ensure the package is installed and use the correct import statement: 'from azure.data.tables import TableServiceClient'.
ValueError: Table names must be alphanumeric, cannot begin with a number, and must be between 3 and 63 characters long.
The provided table name does not meet Azure Table Storage naming conventions.
fix
Use a valid table name that adheres to Azure's naming rules: alphanumeric, not starting with a number, and 3-63 characters long.
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Conflict'
Attempting to create a table that already exists in the storage account.
fix
Check if the table exists before creating it, or use 'create_table_if_not_exists' method to avoid conflicts.
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Not Found'
Attempting to access or delete a table that does not exist.
fix
Verify the table's existence before performing operations, or handle the exception appropriately.
Upgrade
Version history
12.7.0latest on PyPI · released May 6, 2025
Audit
Dependencies
azure-identityoptionalRequired for Azure Active Directory (AAD) authentication methods like DefaultAzureCredential.
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
azure-data-tables — pip install azure-data-tables · libregistry