Reputation: 3203
I've added the Azure package to my Anaconda distribution and also installed the Azure Storage SDK for Python. I'm attempting to read the files already uploaded to a specific blob container using:
from azure.storage import BlobService
blob_service = BlobService(account_name='azure subscription name',
account_key='azure subscription key')
blobs = []
marker = None
while True:
batch = blob_service.list_blobs('vrc', marker=marker, prefix='VRC_')
blobs.extend(batch)
if not batch.next_marker:
break
marker = batch.next_marker
for blob in blobs:
print(blob.name)
When I run this script, I receive the following error:
ImportError: No module named 'azure.storage'
How do I resolve this issue so that I can read the text files and PDFs in my blob container?
Upvotes: 1
Views: 3842
Reputation: 1891
This is old question but become relevant due to latest deprecation of some code blocks in SDK.
Please follow the below to get list of blob files in a given container with modified date too.
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
storageconnectionstring='yourstorageconnectionstring'
blobclient=BlobServiceClient.from_connection_string(storageconnectionstring)
containerclient=blobclient.get_container_client('yourblobcontainername')
for blobs in containerclient.list_blobs():
print (blobs['name'],": Modified: ",blobs['last_modified'])
Upvotes: 2
Reputation: 71031
Not quite sure how you installed the storage sdk, or what version you're using, but you should just need to do the following:
Install:
pip install azure-storage
Import and instantiate blob service:
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name="<storagename>",account_key="<storagekey>")
At that point, you should be able to list blobs (or download blobs, or whatever else you need to do).
Upvotes: 2