Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Python SDK: BlobServiceClient vs. BlobClient?

Most (all?) of the Azure Storage Python SDK examples I've seen demonstrate creating a BlobServiceClient in order to then create a BlobClient for uploading / downloading blobs (ref1, ref2, etc.).

Why create a BlobServiceClient then a BlobClient instead of just directly creating a BlobClient?

Example:

from azure.storage.blob import BlobClient


def create_blob_client(connection_string):
    try:
        blob_client = BlobClient.from_connection_string(connection_string)
    except Exception as e:
        logging.error(f"Error creating Blob Service Client: {e}")
    return blob_client

connection_string = os.environ["CONNECTION_STRING"]

blob_client = create_blob_client(connection_string)
like image 387
SeaDude Avatar asked Nov 18 '25 01:11

SeaDude


1 Answers

Why create a BlobServiceClient then a BlobClient instead of just directly creating a BlobClient?

BlobClient only allows you to work with blobs so if you want to work with just blobs, you can directly create a BlobClient and work with it. No need for you to create a BlobServiceClient first and then create BlobClient from it.

BlobServiceClient comes into picture If you want to perform operations at the blob service level like setting CORS or list blob containers in a storage account. At that time you will need BlobServiceClient.

like image 77
Gaurav Mantri Avatar answered Nov 20 '25 15:11

Gaurav Mantri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!