You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article shows how to set or change the access tier for a block blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
20
+
This article shows how to set or change the access tier for a block blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
21
+
22
+
To learn about changing a blob's access tier using asynchronous APIs, see [Change a blob's access tier asynchronously](#change-a-blobs-access-tier-asynchronously).
21
23
22
24
## Prerequisites
23
25
@@ -62,6 +64,37 @@ The following code example shows how to rehydrate an archived blob to the `Hot`
62
64
63
65
To learn more about copying a blob with Python, see [Copy a blob with Python](storage-blob-copy-python.md).
64
66
67
+
## Change a blob's access tier asynchronously
68
+
69
+
The Azure Blob Storage client library for Python supports changing a blob's access tier asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
70
+
71
+
Follow these steps to change a blob's access tier using asynchronous APIs:
72
+
73
+
1. Add the following import statements:
74
+
75
+
```python
76
+
import asyncio
77
+
78
+
from azure.storage.blob import (
79
+
StandardBlobTier
80
+
)
81
+
from azure.identity.aio import DefaultAzureCredential
82
+
from azure.storage.blob.aio import (
83
+
BlobServiceClient,
84
+
BlobClient
85
+
)
86
+
```
87
+
88
+
1. Add code to run the program using `asyncio.run`. This function runs the passed coroutine, `main()`in our example, and manages the `asyncio` event loop. Coroutines are declared with the async/await syntax. In this example, the `main()` coroutine first creates the top level `BlobServiceClient` using `asyncwith`, then calls the method that changes the blob's access tier. Note that only the top level client needs to use `async with`, as other clients created from it share the same connection pool.
1. Add code to change the blob's access tier. The code is the same as the synchronous example, except that the method is declared with the `async` keyword and the `await` keyword is used when calling the `set_standard_blob_tier` method.
With this basic setup in place, you can implement other examples in this article as coroutines using async/await syntax.
97
+
65
98
## Resources
66
99
67
100
To learn more about setting access tiers using the Azure Blob Storage client library for Python, see the following resources.
@@ -76,7 +109,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
76
109
77
110
### Code samples
78
111
79
-
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_access_tiers.py)
112
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_access_tiers.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_access_tiers_async.py) code samples from this article (GitHub)
0 commit comments