Getting Started With Azure Storage API In Python For Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in today's lesson we're going to learn how to get started with Azure cloud storage API in Python alright so there's going to be a beginner tutorial but I do expect that you have at least some experience what can we add you in Python in general let's get started right so first we need to open our browser they want to log into our address account it can log into your account by going to photo.assure.com if you don't have account simply just sign up for account and it's free now on the home page you want to click on this hamburger icon they want to select storage accounts now on the top one to click on create to create a storage account so basically you can create multiple accounts for different purposes now you need to choose the subscription in the resource Group now for demonstration purpose I'm going to leave this my subscription in Resource Group as default then can click on review now there are multiple things you can configure and I need to go by Sim slot I pay one of the validations all right so let me go back to the basic tab okay all right so here I forgot to click provide the uh the instant details information now you need to provide a name for the account now name this as JJ demo account and make sure that your account name does not contain any space underscore and the letters need to be in lowercase then select the region that is closest to you as for the performance I'm going to choose standard so by default the standard performance is already pretty fast but I want to make sure that you don't have any uh latency issue then you can choose premium which is going to be a little bit more expensive then you can set up the tiers but for now I'm going to choose standard now click on review now as I mentioned before there are other scenes that you can configure and we shall cover those in a separate video but for now this is going to be a beginner tutorial series I'm going to simply just go to the basics now here click on create now it's going to initializing the deployment and it's going to basically set the storage account now just give a second now once the account is created can we close this now we can go into the overview page right so if only go back to the home page again I want to click into storage accounts now here's my GG demo account storage on the overview page you can see all the information that are tied to a decent storage account now here I want to click on access keys answers want to automate Microsoft address storage using python now from the assets Keys page you're going to see two sets of keys now to connect to my JJ demo account storage I'm going to copy my connection string copy the connection string and save that somewhere safe for example you can save the connection string near environment variable and for demonstration purpose I'm going to save the connection stream in my python script all right so name the variable storage connection string now paste the string here let me explain this all right now we need to install the python package now to install the address storage python package we can use the commit pip install Azure Dash storage Dash blog and to connect to Azure service we need to install another python Library called Azure Dash identity enter to install the python libraries now for this demo I'm going to show you how to do two things I'm going to show you how to create a container using python followed by uploading my files to this container that I'm about to create pretty soon now if I go into my project folder in my files folder so here with this icon so image files down to upload to my address to your account right so once we installed the Azure storage client libraries we can go ahead and import the libraries now for this exercise I'm going to import the OS module and to connect to my address storage account we need to input The Blob service client class all right so let's see now first we need to create a instance of The Blob service client object right so from The Blob service client class I should uh phone connection string and we're going to pass the issue this should be let me see oh I have a typo this should be storage we need to pass the storage connection string to the function stream method and only the outputs block service client now if I simply run this code block and it's going to construct this blob service client object and this object here basically uh it's a bridge that connecting to here let me go into my container so this blob service client object it's basically linking to my JJ demo account container right here in here another type of me fix that once we construct the connection to our address storage account or container and we can now go ahead and do the things that I want to do based on our use cases next I want to create a container now name the container choose a image folder right so unfortunately we cannot use any space so any Dash or any underscore in our container name Now to create a container on the blob service client Archer let me delete this line here we can use the create container method that will provide the container name actually let me name this as container name and you can also set the access using the public access parameter you can set the varios well if you want to provide public access to the overall container if so want to use the string blob that's the S has a parameter value if I want to provide public access to the entire container then we will set the value to container if I want to set everything as private which is going to be the default they want to use the access value of now for now I'm going to set the public access us off and which is going to be the default value so I'll get rid of the parameter now go ahead and create the container now going back to my container a refresh and here's my GJ image folder container now to upload files to that container oh and here I've got to grab the output right so I'll name this as container client now let me delete this uh container right here and I'll recreate the container now it's like the container is still in process right let me try again okay so let me name these two uh image folder two so I've got used the refresh button it's okay so here's my JJ image folder 2 container so as you can see that we can quickly use Python to create a container of Buddha so if you need to create multiple containers then using python we can quickly achieve that now to upload my image files to this JJ image folder to container which is going to be just a container client object here all right so first I need to create a variable that point to my image file folder and when it says file folder and the folder name is going to be files down to erase each file in the files folder so I can say for file name in now if I want to list all the files I can use the oyster does the function and I'll provide for the path and that's going to return a list when all the files name in my files folder now once I have the name of each file I need to first of all create a blob object right so from The Blob service client option dot gets blob client we need to provide the container name we want to save the file and the container name is going to be just a container name variable as for the file name you will need to assign the file name to the blob parameter all right so here I'm going to print message uploading file or by the file name now at this point we have created The Blob object but this object is currently in a empty State means that this blob object does not contain any data now to convert this Bob object into Azure file we need to upload the byte string or upload the data bytes to create the Azure file right so here I can say wait open don't need to provide the file path and it's going to be file folder and the file name aim for them all is going to read as binary those data it's just name this as file data now from the pull-up option we can upload the data using the upload block method it will combine the file data string and that's it now if I go ahead and run this code block it looks like all the files are uploaded now just to measured uh ever since I uploaded so I'm going to go back to my account refresh now go into my JJ image folder 2 container and here are all the image files that I uploaded and let me open this one of the file and I can see that this file size is 362 KB and click on download and open the file and here's the image that I just uploaded to my storage account so this is going to be everything we're going to cover in this video and hope you guys found this video useful and don't forget to subscribe and I'll see you guys next time bye
Info
Channel: Jie Jenn
Views: 8,215
Rating: undefined out of 5
Keywords: azure, azure storage, azure storage api, azure blob storage, azure blob storage api, azure python
Id: gMG3JQpyhTo
Channel Id: undefined
Length: 12min 22sec (742 seconds)
Published: Wed Jan 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.