🎩
wilmerags 🌱
  • Home
  • Social
  • Cloud
    • Aws
  • Stats
  • Code
    • Scrum
    • Ssh
    • Vim
    • Dvc
    • Postgresql
    • Tmux
    • Terraform
    • Web tools
    • Sql
    • Rest api
    • Mongo
    • Docker
    • Octave
    • Elasticsearch
    • Kubernetes
    • Bash
    • Rabbitmq
    • Databases
      • Mongo
      • Elasticsearch
      • Sql
        • Postgresql
    • Devops
      • Terraform
      • Docker
      • Kubernetes
      • Rabbitmq
    • Python
      • Airflow
      • Keras
      • Spark
      • Azure
      • Matplotlib
      • Jupyter
      • Numpy
      • Databases
      • Sklearn
      • Requests
      • Pandas
      • Elasticsearch
      • Tensorflow
    • Git
      • Gitflow
    • R
      • Lpsolve
  • Indie-hacker
  • Macos
  • Interesting
  • Thoughts
    • Health
    • Work
    • Relationships
    • On the need of expressiveness
    • On organizing knowledge
    • On the importance of questions
  • Linux
    • Vim
    • Tmux
  • Webdev
    • Vue
  • Readings
    • Psychology
    • Habits
    • Projects management
    • Quotes
    • Dopamine detox
  • Ai
    • Ml
      • Xgboost
      • Performance evaluation
      • Community detection
      • Cloud_platforms
        • Ai platform
        • Sagemaker
      • Unsupervised_learning
    • Nlp
    • DS
Powered by GitBook
On this page
  1. Code
  2. Python

Azure

Frequently used code for azure related code snippets

PreviousSparkNextMatplotlib

Last updated 3 years ago

Was this helpful?

CtrlK

Was this helpful?

Download blobs locally

from azure.storage.blob import BlobServiceClient
import os

conn_str = ""
container_name = ""
blob_name = ""
local_path = ""

download_file_path = os.path.join(local_path, blob_name)
blob_service_client = BlobServiceClient.from_connection_string(conn_str)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
with open(download_file_path, "wb") as download_file:
    download_file.write(blob_client.download_blob().readall())

List files/folders in blob

from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
#Create a Blob Storage Account client

connect_str = <connectionstring>
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
#Create a container client

container_name="dummy"
container_client=blob_service_client.get_container_client(container_name)
#This will list all blobs in the container inside dir1 folder/directory

blob_list = container_client.list_blobs(name_starts_with="dir1/")
for blob in blob_list:
	print("\t" + blob.name)