Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a blob exist in python azure

Since the new update of azure-storage-blob, the blockblobservice is depreciated

How can I check that a blob exist ?

This answer is not working with the new version of azure-storage-blob Faster Azure blob name search with python?

I found this issue on GitHub : https://github.com/Azure/azure-sdk-for-python/issues/12744

like image 470
RaphWork Avatar asked May 11 '26 20:05

RaphWork


1 Answers

Version 12.5.0 released on 2020-09-10 has now the exists method in the new SDK.

For example,

Sync:

from azure.storage.blob import BlobClient

blob = BlobClient.from_connection_string(conn_str="my_connection_string", container_name="mycontainer", blob_name="myblob")
exists = blob.exists()
print(exists)

Async:

import asyncio

async def check():
    from azure.storage.blob.aio import BlobClient
    blob = BlobClient.from_connection_string(conn_str="my_connection_string", container_name="mycontainer", blob_name="myblob")
    async with blob:
        exists = await blob.exists()
        print(exists)
like image 97
krishg Avatar answered May 14 '26 10:05

krishg



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!