How to read a file from Azure Blob Container using Python

Viewed 6562

How can I read files in the Azure blob container using Python? Im trying to read some JSON files in container for flattening them.

Im new to Azure and dont have much idea about this. I could connect to the container using "BlobServiceClient". But, Im not sure how to read the files from a folder in teh container

Thanks

1 Answers

If you want to read a file from Azure blob with python, please refer to the following code

from azure.storage.blob import BlobServiceClient
connection_string=''
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("<container name>")
blob_client = container_client.get_blob_client("<blob name>")
blob_client.download_blob().readall() # read blob content as string

For more details, please refer to the document

Related