7
votes

I am trying to access Azure Table Storage via python.

Following an old walkthrough here: https://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-python#install-the-azure-storage-sdk-for-python

but the Python SDK it references for Azure Tables specifically (https://github.com/Azure/azure-storage-python) has been moved/deprecated in favor of Azure Cosmos DB SDK.

In the deprecation note, they say to use this SDK: https://github.com/Azure/azure-cosmosdb-python

In the documentation for that SDK, they refer you to https://azure.microsoft.com/en-us/develop/python/

In the Table Storage and link on that page, it refers you back to the first link (!!)

============

1) All I want to do is query traditional Azure Table Storage (NOT CosmosDB) with a Python SDK

2) Ideally, that Python SDK also includes the encryption/decryption capability for Azure Tables.

What am I missing / does that python SDK still exist anywhere?

Note: I see https://github.com/Azure/azure-cosmosdb-python/tree/master/azure-cosmosdb-table but this SDK seems to require a CosmosDB deployment -- it can't connect to traditional AzureTables. Is my understanding incorrect?

Thanks for any help you can offer.

3
Hi,any updates now?Jay Gong
thanks for the answer you provided! Helpful to know - though I was looking for the explanation if it was completely absorbed/interchangeable with the cosmos python sdk, which Laurent's answer makes clearASX

3 Answers

9
votes

The Azure CosmosDB Table SDK IS Azure Storage Tables SDK. Re-branding is part of some re-org inside Microsoft, but this is the same code and same endpoint, same everything.

Storage SDK was one big client, it was split into Table/Queue/Blog/Files packages, in order to give ownership of Table to CosmosDB team.

https://docs.microsoft.com/en-us/azure/cosmos-db/table-support

The new Azure Cosmos DB Python SDK is the only SDK that supports Azure Table storage in Python. This SDK connects with both Azure Table storage and Azure Cosmos DB Table API.

You can also compare the code, you'll see:

(I work at MS in the Azure SDK for Python team)

2
votes

Azure Table Storage has a new python library in preview release that is available for installation via pip. To install use the following pip command

pip install azure-data-tables

This SDK is able to target either a Tables or Cosmos endpoint (albeit there are known issues with Cosmos).

For your use case of querying an Azure Table Storage account, there's two query methods.

Querying a single table:

from azure.data.tables import TableClient

table_client = TableClient.from_connection_string(conn_str, table_name="myTableName")
query_filter = "RowKey eq 'row_key_5'"
for entity in table_client.query_entities(filter=query_filter):
    print(entity)

Querying a storage account for tables:

from azure.data.tables import TableServiceClient

table_service_client = TableServiceClient.from_connection_string(conn_str, table_name="myTableName")
query_filter = "TableName eq 'myTable'"
for table in table_service_client .query_entities(filter=query_filter):
    print(table.table_name)

For more samples on the library check out the samples hosted on the Azure GitHub Repository.

(FYI I work at Microsoft on the Azure SDK for Python team)

0
votes

Indeed , Azure hides part of the Table Storage SDK guided links facilitate the promotion of the Cosmos DB Table API. As you mentioned in your answer, the Azure Storage SDK is now incorporated into the Cosmos menu.

However , I found the old Azure Table Storage Python SDK from previous version in the repo.

enter image description here

You could refer to the above link even if it's no longer updated.

By the way, you could see the benefits by moving to Azure Cosmos Table API from Azure Table Storage from this link.

Hope it helps you.