Skip to content

Description:

  • Work with azure blob storage

Resources:

This notebook reads these environment variables. Set them before you start Jupyter:

  • AZURE_STORAGE_ACCOUNT_NAME: your Azure Storage account name.
  • AZURE_STORAGE_CONTAINER: a blob container in that storage account.
  • AZURE_STORAGE_ACCOUNT_KEY: an access key for that storage account.

Synchronously list the blobs in a private container

import os
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
account_name = os.environ["AZURE_STORAGE_ACCOUNT_NAME"]
container_name = os.environ["AZURE_STORAGE_CONTAINER"]
account_key = os.environ["AZURE_STORAGE_ACCOUNT_KEY"]
account_url = f"https://{account_name}.blob.core.windows.net/{container_name}"
storage_options = {'account_name': account_name, 'account_key': account_key, 'account_url': account_url, 'container_name': container_name}
container_client = ContainerClient(**storage_options)
container_client.list_blobs()

Asyncronously list the blobs in a public container

from azure.storage.blob.aio import BlobServiceClient, ContainerClient, BlobPrefix
azure_storage_account_name = "azureopendatastorage"
azure_storage_account_url = f"https://{azure_storage_account_name}.blob.core.windows.net/"
azure_storage_sas_token = r""
container_name = "nyctlc"
folder_name = "yellow"
c_client = ContainerClient(account_name=azure_storage_account_name, container_name=container_name, account_url=azure_storage_account_url)
c_client.list_blobs()

ganymede is made by Eugo