To do this, pass the storageĬonnection string to the client's from_connection_string class method: from import BlobServiceClient connection_string = "DefaultEndpointsProtocol=https AccountName=xxxx AccountKey=xxxx EndpointSuffix=" service = BlobServiceClient. Use the key as the credential parameter to authenticate the client: from import BlobServiceClient service = BlobServiceClient ( account_url = ", credential = "" )Ĭreating the client from a connection stringĭepending on your use case and authorization method, you may prefer to initialize a client instance with a storageĬonnection string instead of providing the account URL and credential separately. Section or by running the following Azure CLI command:Īz storage account keys list -g MyResourceGroup -n MyStorageAccount This can be found in the Azure Portal under the "Access Keys" (aka account key or access key), provide the key as a string. utcnow () + timedelta ( hours = 1 ) ) blob_service_client = BlobServiceClient ( account_url = ", credential = sas_token )
You can generate a SAS token from the Azure Portal under "Shared access signature" or use one of the generate_sas()įunctions to create a sas token for the storage account, container, or blob: from datetime import datetime, timedelta from import BlobServiceClient, generate_account_sas, ResourceTypes, AccountSasPermissions sas_token = generate_account_sas ( account_name = "", account_key = "", resource_types = ResourceTypes ( service = True ), permission = AccountSasPermissions ( read = True ), expiry = datetime. If your account URL includes the SAS token, omit the credential parameter. To use a shared access signature (SAS) token, Use the returned token credential to authenticate the client: from azure.identity import DefaultAzureCredential from import BlobServiceClient token_credential = DefaultAzureCredential () blob_service_client = BlobServiceClient ( account_url = ", credential = token_credential ) Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:ĪZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET.Grant access to Azure Blob data with RBAC in the Azure Portal.Register a new AAD application and give permissions to access Azure Storage.Provide an instance of the desired credential type obtained from the To use an Azure Active Directory (AAD) token credential, The credential parameter may be provided in a number of different forms, depending on the type of Or Azure CLI: # Get the blob service account url for the storage accountĪz storage account show -n my-storage-account-name -g my-resource-group -query "primaryEndpoints.blob" Types of credentials You can find the storage account's blob service URL using the To create a client object, you will need the storage account's blob service account URL and aĬredential that allows you to access the storage account: from import BlobServiceClient service = BlobServiceClient ( account_url = ", credential = credential ) Looking up the account URL Interaction with these resources starts with an instance of aĬlient. The Azure Storage Blobs client library for Python allows you to interact with three types of resources: the storageĪccount itself, blob storage containers, and blobs. Or Azure CLI: # Create a new resource group to hold the storage account - # if using an existing resource group, skip this stepĪz group create -name my-resource-group -location westus2Īz storage account create -n my-storage-account-name -g my-resource-group If you wish to create a new storage account, you can use the
#MICROSOFT AZURE STORAGE EMULATOR CRASHES INSTALL#
Install the Azure Storage Blobs client library for Python with pip: pip install azure-storage-blob
#MICROSOFT AZURE STORAGE EMULATOR CRASHES CODE#
Source code | Package (PyPI) | API reference documentation | Product documentation | Samples Getting started Prerequisites