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
In addition to the data they contain, blobs support system properties and user-defined metadata. This article shows how to manage system properties and user-defined metadata using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
21
21
22
+
To learn about managing properties and metadata using asynchronous APIs, see [Set blob metadata asynchronously](#set-blob-metadata-asynchronously).
23
+
22
24
## Prerequisites
23
25
24
26
- This article assumes you already have a project set up to work with the Azure Blob Storage client library for Python. To learn about setting up your project, including package installation, adding `import` statements, and creating an authorized client object, see [Get started with Azure Blob Storage and Python](storage-blob-python-get-started.md).
@@ -51,15 +53,15 @@ Any properties not explicitly set are cleared. To preserve any existing properti
51
53
52
54
The following code example sets the `content_type` and `content_language` system properties on a blob, while preserving the existing properties:
To retrieve metadata, call the [get_blob_properties](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-get-blob-properties) method on your blob to populate the metadata collection, then read the values, as shown in the example below. The `get_blob_properties` method retrieves blob properties and metadata by calling both the [Get Blob Properties](/rest/api/storageservices/get-blob-properties) operation and the [Get Blob Metadata](/rest/api/storageservices/get-blob-metadata) operation.
75
77
76
78
The following code example reads metadata on a blob and prints each key/value pair:
The Azure Blob Storage client library for Python supports managing blob properties and metadata asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
85
+
86
+
Follow these steps to set blob metadata using asynchronous APIs:
87
+
88
+
1. Add the following import statements:
89
+
90
+
```python
91
+
import asyncio
92
+
93
+
from azure.identity.aio import DefaultAzureCredential
94
+
from azure.storage.blob.aio import BlobServiceClient
95
+
```
96
+
97
+
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 sets the blob metadata. Note that only the top level client needs to use `asyncwith`, as other clients created from it share the same connection pool.
98
+
99
+
```python
100
+
asyncdefmain():
101
+
sample = BlobSamples()
102
+
103
+
#TODO: Replace <storage-account-name> with your actual storage account name
1. Add code to set the blob metadata. 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 `get_blob_properties`and`set_blob_metadata` methods.
With this basic setup in place, you can implement other examples in this article as coroutines using async/await syntax.
79
119
80
120
## Resources
81
121
@@ -92,6 +132,6 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
92
132
93
133
### Code samples
94
134
95
-
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py)
135
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs-properties-metadata-tags.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs-properties-metadata-tags-async.py) code samples from this article (GitHub)
This article shows how to use blob index tags to manage and find data using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
21
21
22
+
To learn about setting blob index tags using asynchronous APIs, see [Set blob index tags asynchronously](#set-blob-index-tags-asynchronously).
23
+
22
24
## Prerequisites
23
25
24
26
- This article assumes you already have a project set up to work with the Azure Blob Storage client library for Python. To learn about setting up your project, including package installation, adding `import` statements, and creating an authorized client object, see [Get started with Azure Blob Storage and Python](storage-blob-python-get-started.md).
@@ -43,11 +45,11 @@ You can set tags by using the following method:
43
45
44
46
The specified tags in this method will replace existing tags. If old values must be preserved, they must be downloaded and included in the call to this method. The following example shows how to set tags:
The Azure Blob Storage client library for Python supports working with blob index tags asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
84
+
85
+
Follow these steps to set blob index tags using asynchronous APIs:
86
+
87
+
1. Add the following import statements:
88
+
89
+
```python
90
+
import asyncio
91
+
92
+
from azure.identity.aio import DefaultAzureCredential
93
+
from azure.storage.blob.aio import BlobServiceClient
94
+
```
95
+
96
+
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 sets the blob index tags. Note that only the top level client needs to use `asyncwith`, as other clients created from it share the same connection pool.
97
+
98
+
```python
99
+
asyncdefmain():
100
+
sample = BlobSamples()
101
+
102
+
#TODO: Replace <storage-account-name> with your actual storage account name
1. Add code to set the blob index tags. 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 `get_blob_tags`and`set_blob_tags` methods.
With this basic setup in place, you can implement other examples in this article as coroutines using async/await syntax.
78
118
79
119
## Resources
80
120
@@ -90,7 +130,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
90
130
91
131
### Code samples
92
132
93
-
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs.py)
133
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs-properties-metadata-tags.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-blobs-properties-metadata-tags-async.py) code samples from this article (GitHub)
0 commit comments