Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon

Work with Azure Blob Storage Using the Azure SDK for Python

In this lab, you will get an opportunity to perform simple operations against an Azure Blob storage account using Python code and confirm that your code is operating as intended by checking your work in the Azure portal. During the lab you will: - Connect to an existing storage account - Create a container on the account - Upload a blob to the container While the language used in this lab is Python, developers with apprentice-level coding experience in any modern, object-oriented language should be able to successfully complete the objectives through the use of research hints provided in the lab instructions. If you get stuck, the lab guide and solution video provide additional help.

Azure icon

Path Info

Clock icon Beginner
Clock icon 45m
Clock icon May 18, 2023

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge


    1. Open an incognito or in-private window and log in to the Azure portal using the user name and password provided in the lab environment.
    2. From within the portal, initiate the Cloud Shell to select Bash (versus PowerShell) and set up with new backing storage — do not use the existing storage account deployed into the lab environment. You will need both storage accounts to complete the lab.

    Note: You are free to write the code for this lab in Visual Studio Code or another IDE, if you have experience in that environment. Just make sure you download the GitHub project file to ensure you have instructions and hints. Be aware that the lab guide and the solution video are based on working in the Cloud Shell editor, but it won't substantially change the code you write.

  2. Challenge

    Upload a Blob to a New Storage Container

    In the file, which you should have open in the Cloud Shell editor, follow the instructions and hints to modify and author additional code to:

    1. Populate the my_connection_string variable with the primary connection string you retrieved from the storage account, using the Azure portal.
    2. Instantiate the BlobServiceClient.
    3. Create a new ContainerClient object.
    4. Create a container on the storage account using the instantiated ContainerClient object. If the instructions tell you to use an exact name for a deployed resource, be sure to follow those instructions, as the lab grading tool may be looking specifically for that name.
    5. Instantiate a BlobClient.
    6. Upload a blob using the SampleBlob.txt file.

    When you are ready, be sure to save your file in the code editor and then execute it at the command line with:


    Navigate to the the storage account in the Azure portal to confirm the creation of a new container and a blob in that container.

    Extra Challenges — Just for Fun

    • Create more than one container and then write the code to delete one of them.
    • Compose Python code to confirm the existence of the container and blob, rather than using the portal.


    • You will need to instantiate the BlobServiceClient using the connection string you retrieved from the portal. Do not use a SAS token or just the key. You need to use the primary connection string.
    • If the instructions tell you to use an exact name for a deployed resource, be sure to follow those instructions, as the lab grading tool may be looking specifically for that name.
    • See the Additional Information and Resources section of the lab for a link to the Python SDK and samples to help you author the code.
    • If you still need help after considering these tips, you can copy-paste the code from the lab guide and/or watch the solution video.
  3. Challenge

    Prepare Environment

    At this point, you should be at the command prompt in the Cloud Shell environment.

    1. From the Bash command prompt, execute the git clone command using the URL provided in the Additional Information and Resources section of the lab, followed by AZ204_Labs to alias the downloaded folder to a friendly name.
    2. Once the project is downloaded, use the Cloud Editor to open the file in the AZ204_Labs/work_with_storage/python folder.
    3. From the Bash command prompt, change to the working directory: cd AZ204_Labs/work_with_storage/python.
    4. Run this command to install the library we will be working with in the lab: pip install azure-storage-blob.
    5. Minimize (do not close) the Cloud Shell pane and navigate to the Azure Storage account that is already set up for you. The name of the account starts with pythonlab. Be sure to go to that account and not the one you set up to back your cloud storage.
    6. Navigate to the location of the primary connection string and copy it. Be sure to copy the connection string and not just the key. Also, note that access keys and connection strings are different from SAS (shared access signature) tokens. It is not considered best practice for security to use either connection strings or SAS tokens on production accounts, but it's fine for these lab exercises.
    7. Return to your Cloud Shell window.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans