pythonazureazure-storageazure-table-storage

Fetching Windows Azure Storage tables names through python API


I'm trying to fetch the names of all the tables of my Windows Azure Storage Account in order to delete them with table_service.delete_table('tasktable').

Unfortunately I didn't find anything in the Windows Azure HOWTO. I only found the official REST API documentation and this blog which explain what I want to do, but it's not in python.

Is there any way to fetch all the name table using python?


Solution

  • 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).

    To query all tables and subsequently delete you can use the list_tables method like this:

    from azure.data.tables import TableServiceClient
    
    table_service_client = TableServiceClient.from_connection_string(my_conn_str)
    
    for table in table_service_client.list_tables():
        table_service_client.delete_table(table.table_name)
    

    You can also use the query_tables method and an OData filter to delete only a subset of the tables:

    ...
    table_filter = "TableName ne 'tableToKeep'"
    
    for table in table_service_client.query_tables(filter=table_filter):
        table_service_client.delete_table(table.table_name)
    

    (FYI, I am a Microsoft employee on the Azure SDK for Python team)