Udayan Subuddhi IN
Udayan Subuddhi IN

Reputation: 43

How can I read a text file from Azure blob storage directly without downloading it to a local file(using python)?

How can i reads a text blob in Azure without downloading it? I am able to download the file and then read it but, i prefer it to be read without downloading.

print("\nList blobs in the container")
generator = block_blob_service.list_blobs(container_name)                  
for blob1 in generator:
    print("\t Blob name: " + blob.name)

Is there any operation in 'blob1' object, which would allow me to read the text file directly.(like blob1.read or blob1.text or something like this)?

Upvotes: 3

Views: 9172

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136334

You can use get_blob_to_text method.

block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')

blob = block_blob_service.get_blob_to_text('mycontainer', 'myblockblob')
print(blob.content)

Upvotes: 5

Related Questions