Skip to content

Instantly share code, notes, and snippets.

@hamelsmu
Created May 26, 2021 03:51
Show Gist options
  • Save hamelsmu/9fe4eb524001a19e396d28aac2754952 to your computer and use it in GitHub Desktop.
Save hamelsmu/9fe4eb524001a19e396d28aac2754952 to your computer and use it in GitHub Desktop.
How to upload data to Azure Blob Store
import os
from azure.storage.blob import BlobServiceClient
blob_service_client = BlobServiceClient.from_connection_string(os.getenv('AZURE_STORAGE_CONNECTION_STRING'))
with open('gh_repo_topics.parquet', 'rb') as data:
blob_client = container_client.upload_blob(name="sample_data/gh_repo_topics.parquet", data=data, overwrite=True)
####### Downloading files ##########
f = container_client.download_blob("sample_data/gh_repo_topics.parquet")
# You can read the file into memory like this
hello = f.readall()
# Or you can write the file out to disk like this
with open("sample_data/gh_repo_topics.parquet", 'wb') as d:
f.readinto(d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment