Created
March 13, 2019 12:05
-
-
Save axsaucedo/67598ab8fa9c0e1788a8d9c0c266af9a to your computer and use it in GitHub Desktop.
Print the size of an azure blob with the Python AzureSDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from azure.storage.blob import BlockBlobService, PublicAccess | |
CONTAINER_NAME = os.environ["AZURE_CONTAINER_NAME"] | |
AZURE_STORAGE_ACCOUNT = os.environ["AZURE_STORAGE_ACCOUNT"] | |
AZURE_STORAGE_KEY = os.environ["AZURE_STORAGE_KEY"] | |
bbs = BlockBlobService( | |
account_name=AZURE_STORAGE_ACCOUNT, | |
account_key=AZURE_STORAGE_KEY) | |
bbs = BlockBlobService( | |
account_name=AZURE_STORAGE_ACCOUNT, | |
account_key=AZURE_STORAGE_KEY) | |
total_size = 0 | |
generator = bbs.list_blobs(CONTAINER_NAME) | |
for blob in generator: | |
curr_blob = BlockBlobService.get_blob_properties( | |
bbs, | |
CONTAINER_NAME, | |
blob.name) | |
length = curr_blob.properties.content_length | |
total_size = total_size + length | |
print("Total: ", round(total_size/(1024**3), 2), " GB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment