0

using azure python function, I am able to read the full file at once. (Read data from Azure blob storage in Azure Function in python)

blob_client = BlobClient.from_blob_url("your Blob SAS URL here")
download_stream = blob_client.download_blob()
logging.info('=========below is content of test1')
logging.info(download_stream.readall())
logging.info('=========above is content of test1')

Is there a way you can read the blob file line by line? Thank you!

luecs
  • 5
  • 1

2 Answers2

0

You may try this code to read blob file line by line


str1 = block_blob_service.get_blob_to_text(container_name,blob_name)

#split the string str1 with newline.
arr1 = str1.content.splitlines()

#read the one line each time.
for a1 in arr1:
    print(a1)

for more refere you may check with this link

read the text file in azure storage blob line by line using python

ShrutiJoshi-MT
  • 1,622
  • 1
  • 4
  • 9
0

For completeness here my code to access with the SAS token:

from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='<account_name>', account_key=None,sas_token ='<sas_token>')
str1 = block_blob_service.get_blob_to_text('<container_name>','<blob_name>')
arr1 = str1.content.splitlines()
#read the one line each time.
for a1 in arr1:
    print(a1)

As a pitfall, the SAS token starts without the ? symbol. The SAS token shall start with something like: 'sv='

luecs
  • 5
  • 1