Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions sdk/storage/azure-storage-blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Blob storage is ideal for:
* Storing data for backup and restore, disaster recovery, and archiving
* Storing data for analysis by an on-premises or Azure-hosted service

[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/azure/storage/blob) | [Package (PyPi)](https://pypi.org/project/azure-storage-blob/) | [API reference documentation](https://docs.microsoft.com/rest/api/storageservices/blob-service-rest-api) | [Product documentation](https://docs.microsoft.com/azure/storage/) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests)
[Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/azure/storage/blob) | [Package (PyPi)](https://pypi.org/project/azure-storage-blob/) | [API reference documentation](https://azure.github.io/azure-sdk-for-python/ref/azure.storage.blob.html) | [Product documentation](https://docs.microsoft.com/azure/storage/) | [Samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests)


## Getting started
Expand Down Expand Up @@ -124,6 +124,17 @@ blob = BlobClient.from_connection_string("my_connection_string", container="myco
with open("./SampleSource.txt", "rb") as data:
blob.upload_blob(data)
```
Use the async client to upload a blob to your container.

```python
from azure.storage.blob.aio import BlobClient

blob = BlobClient.from_connection_string("my_connection_string", container="mycontainer", blob="my_blob")

with open("./SampleSource.txt", "rb") as data:
await blob.upload_blob(data)
```

### Downloading a blob
Download a blob from your container.

Expand All @@ -137,8 +148,21 @@ with open("./BlockDestination.txt", "wb") as my_blob:
my_blob.writelines(blob_data.content_as_bytes())
```

Download a blob asynchronously.

```python
from azure.storage.blob.aio import BlobClient

blob = BlobClient.from_connection_string("my_connection_string", container="mycontainer", blob="my_blob")

with open("./BlockDestination.txt", "wb") as my_blob:
stream = await blob.download_blob()
data = await stream.content_as_bytes()
my_blob.write(data)
```

### Enumerating blobs
List the blob in your container.
List the blobs in your container.

```python
from azure.storage.blob import ContainerClient
Expand All @@ -150,6 +174,19 @@ for blob in blob_list:
print(blob.name + '\n')
```

List the blobs asynchronously.

```python
from azure.storage.blob.aio import ContainerClient

container = ContainerClient.from_connection_string("my_connection_string", container="mycontainer")

blob_list = []
async for blob in container.list_blobs():
blob_list.append(blob)
print(blob_list)
```

## Troubleshooting
Storage Blob clients raise exceptions defined in [Azure Core](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/docs/exceptions.md).

Expand All @@ -163,27 +200,27 @@ Get started with our [Blob samples](https://github.com/Azure/azure-sdk-for-pytho

Several Storage Blobs Python SDK samples are available to you in the SDK's GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Storage Blobs:

* [`test_blob_samples_hello_world.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_hello_world.py) - Examples for common Storage Blob tasks:
* [`test_blob_samples_hello_world.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_hello_world.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_hello_world_async.py)) - Examples for common Storage Blob tasks:
* Set up a container
* Create a block, page, or append blob
* Upload blobs
* Download blobs
* Delete blobs

* [`test_blob_samples_authentication.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_authentication.py) - Examples for authenticating and creating the client:
* [`test_blob_samples_authentication.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_authentication.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_authentication_async.py)) - Examples for authenticating and creating the client:
* From a connection string
* From a shared access key
* From a shared access signature token
* From active directory

* [`test_blob_samples_service.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_service.py) - Examples for interacting with the blob service:
* [`test_blob_samples_service.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_service.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_service_async.py)) - Examples for interacting with the blob service:
* Get account information
* Get and set service properties
* Get service statistics
* Create, list, and delete containers
* Get the Blob or Container client

* [`test_blob_samples_containers.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_containers.py) - Examples for interacting with containers:
* [`test_blob_samples_containers.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_containers.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_containers_async.py)) - Examples for interacting with containers:
* Create a container and delete containers
* Set metadata on containers
* Get container properties
Expand All @@ -192,12 +229,13 @@ Several Storage Blobs Python SDK samples are available to you in the SDK's GitHu
* Upload, list, delete blobs in container
* Get the blob client to interact with a specific blob

* [`test_blob_samples_common.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_common.py) - Examples common to all types of blobs:
* [`test_blob_samples_common.py`](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_common.py) ([async version](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/storage/azure-storage-blob/tests/test_blob_samples_common_async.py)) - Examples common to all types of blobs:
* Create a snapshot
* Delete a blob snapshot
* Soft delete a blob
* Undelete a blob
* Acquire a lease on a blob
* Copy a blob from a URL


### Additional documentation
Expand Down
Loading