Setting Azure Storage Account Blob Metadata with Python Script

Those who may have followed my previous post will recall that I tried to incorporate steps in a Logic App to try and retrieve a blob’s metadata and quickly found that there wasn’t a built-in action that allowed me to retrieve the tags. I spent a considerable amount of time to research but didn’t have much luck with the built-in features of the Logic App. There was a bit of hope for me last week when I wanted to try and set blob metadata tags as I was able to find the Set Blob Metadata REST API (https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-metadata?tabs=microsoft-entra-id) but after numerous attempts and failures, I decided to go with writing a Python script (https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-properties-metadata-python) to achieve this.

This post is meant to be part one of two to achieve this with a Python script. Part #1 is this post where I will provide a script that allows you to hard code the blob parameters (storage account URL, container name, blob path, and blob file name) to set the blob metadata. Part #2 will be a walkthrough for how to convert this script to an Azure Function App that will receive a JSON payload to set a blob’s metadata.

The Python script can be found here at my following repo: https://github.com/terenceluk/Azure/blob/main/Storage%20Account/Set-Blob-Metadata.py

To use the script, update the # Blob details variables, then run the script and authenticate with an Entra ID account with the appropriate permissions.

Here is a sample run for a blob in a container in sub folders:

 

Here is a sample run for a blob in a container in root of the container:

 

I will be following up with another post to demonstrate how to convert and set up an Azure Function App that can be incorporated into a Logic App.