How to: push data to Azure BLOB using Python in 3 lines

Daniel R Carletti
1 min readJan 28, 2019

I hate long tutorials that don’t explain the absolute basics, so this quick and practical read should get you up and running in no time.

Easiest thing in the world. Let’s get straight to it. This is the most simple way to do it. First, you will need a few things from Azure:

  1. Account Name
  2. Account Key
  3. Container Name

You will need to download and install the azure BLOB library.

pip install azure-storage-blob

Now, the actual code to upload a “Hello World” file:

from azure.storage.blob import BlockBlobService, PublicAccessblock_blob_service = BlockBlobService(account_name='account_name', account_key='account_key')block_blob_service.create_blob_from_text("container_name", filename_with_path, "Hello World", encoding='utf-8')

You will now have a file where you specified with filename_with_path. This looks something like ‘Folder/Subfolder/filename.txt’. No need to include the container name or anything else.

That’s it. If you need anything else, take a look at the Azure Quickstart and sample file provided by Microsoft. They provide many more options for uploading files. Be it from text, bytes, stream or even from an actual file on your system. Check it out.

--

--