0

when running the azure CLI command:

az storage account blob-service-properties show --account-name sa36730 --resource-group rg-exercise1

The output json contains the filed isVersioningEnabled. I am trying to get this field using python sdk.

I wrote this code but the output doesnt contain the version enabled information.

def blob_service_properties():
    connection_string = "<connection string>"


    # Instantiate a BlobServiceClient using a connection string
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)
    properties = blob_service_client.get_service_properties()
    pprint.pprint(properties)
    # [END get_blob_service_properties]

My output looks like:

{'analytics_logging': <azure.storage.blob._models.BlobAnalyticsLogging object at 0x7ff0f8b7c340>,
 'cors': [<azure.storage.blob._models.CorsRule object at 0x7ff1088b61c0>],
 'delete_retention_policy': <azure.storage.blob._models.RetentionPolicy object at 0x7ff0f8b9b1c0>,
 'hour_metrics': <azure.storage.blob._models.Metrics object at 0x7ff0f8b9b700>,
 'minute_metrics': <azure.storage.blob._models.Metrics object at 0x7ff0f8b9b3d0>,
 'static_website': <azure.storage.blob._models.StaticWebsite object at 0x7ff0f8ba5c10>,
 'target_version': None}

Is there a way to get the versioning information using Python SDK for storage blob?

abhinav singh
  • 1,024
  • 1
  • 12
  • 34

2 Answers2

0

I tried the below steps, it worked for me, in my environment

To get the Blobservice properties you can use azure-mgmt-storage package.

You can use the below to get the blob service properties.

Code:

from azure.mgmt.storage import StorageManagementClient
from azure.identity import DefaultAzureCredential

storage_client=StorageManagementClient(credential=DefaultAzureCredential(),subscription_id="<your subscription Id>")
blob_service_list = storage_client.blob_services.list("<your resourcegrouup name>', '<your account name>')
for items in blob_service_list:
    print(items)

Console:

enter image description here

Dasari Kamali
  • 811
  • 2
  • 2
  • 6
0

Thanks to DasariKamali for pointing me in the right direction. This is a more direct way to get the answer:

Code:

from azure.mgmt.storage import StorageManagementClient
from azure.identity import DefaultAzureCredential

storage_client=StorageManagementClient(credential=DefaultAzureCredential(),subscription_id='<subscription_id>')
properties = storage_client.blob_services.get_service_properties('<resource_group_name>', '<account_name>')
print(properties.is_versioning_enabled)
Dale
  • 26
  • 3