Azure Blob - Read using Python

前端 未结 5 819
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 03:18

Can someone tell me if it is possible to read a csv file directly from Azure blob storage as a stream and process it using Python? I know it can be done using C#.Net (shown

5条回答
  •  一个人的身影
    2020-12-14 04:01

    One can stream from blob with python like this:

    from tempfile import NamedTemporaryFile
    from azure.storage.blob.blockblobservice import BlockBlobService
    
    entry_path = conf['entry_path']
    container_name = conf['container_name']
    blob_service = BlockBlobService(
                account_name=conf['account_name'],
                account_key=conf['account_key'])
    
    def get_file(filename):
        local_file = NamedTemporaryFile()
        blob_service.get_blob_to_stream(container_name, filename, stream=local_file, 
        max_connections=2)
    
        local_file.seek(0)
        return local_file
    

提交回复
热议问题