

# Python program to bulk download blobs from azure storageįrom multiprocessing.pool import ThreadPool Don't forget to change MY_CONNECTION_STRING, LOCAL_BLOB_PATH and MY_BLOB_CONTAINER variables. The program currently uses 10 threads, but you can increase it if you want faster downloads. This substantially speeds up your download if you have good bandwidth. The following program uses ThreadPool class in Python to download files in parallel from Azure storage. My_blobs = self.my_container.list_blobs()īytes = self.my_container.get_blob_client(blob).download_blob().readall()Īzure_blob_file_downloader = AzureBlobFileDownloader()Īzure_blob_file_downloader.download_all_blobs_in_container()įast/Parallel File Downloads from Azure Blob Storage Using Python With open(download_file_path, "wb") as file:ĭef download_all_blobs_in_container(self): Os.makedirs(os.path.dirname(download_file_path), exist_ok=True) # for nested blobs, create local path as well! Self.my_container = self.blob_service_client.get_container_client(MY_BLOB_CONTAINER)ĭef save_blob(self,file_name,file_content):ĭownload_file_path = os.path.join(LOCAL_BLOB_PATH, file_name)

Self.blob_service_client = om_connection_string(MY_CONNECTION_STRING) # Initialize the connection to Azure storage account

Print("Intializing AzureBlobFileDownloader") # Replace with the local folder where you want files to be downloaded # Usually starts with DefaultEndpointsProtocol=https. # IMPORTANT: Replace connection string with your storage account connection string # Uses latest python SDK() for Azure blob storageįrom import BlobServiceClient, BlobClientįrom import ContentSettings, ContainerClient # Python program to bulk download blob files from azure storage See the next program below to see how this can be speeded up using python's ThreadPool class. Note that the program may take a while if your storage account contains a large number of blob files. The connection string can be obtained from Azure portal and it contains the account url and access key inside it. The program will create local folders for blobs which use virtual folder names(name containing slashes).īefore running the program ensure you give proper values for MY_CONNECTION_STRING, MY_BLOB_CONTAINER and LOCAL_BLOB_PATH. The following python program uses Azure python SDK for storage to download all blobs in a storage container to a specified local folder. How to Bulk Download Files from Azure Blob Storage Using Python Now you are all set to run the following python programs.
