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 delete containers with the [Azure Storage client library for Python](/python/api/overview/azure/storage). If you've enabled [container soft delete](soft-delete-container-overview.md), you can restore deleted containers.
21
21
22
+
To learn about deleting a blob container using asynchronous APIs, see [Delete a container asynchronously](#delete-a-container-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).
@@ -40,11 +42,11 @@ After you delete a container, you can't create a container with the same name fo
40
42
41
43
The following example uses a `BlobServiceClient` object to delete the specified container:
@@ -54,7 +56,32 @@ When container soft delete is enabled for a storage account, a deleted container
54
56
55
57
The following example finds a deleted container, gets the version of that deleted container, and then passes the version into the `undelete_container` method to restore the container.
The Azure Blob Storage client library for Python supports deleting a blob container asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
64
+
65
+
Follow these steps to delete a container using asynchronous APIs:
66
+
67
+
1. Add the following import statements:
68
+
69
+
```python
70
+
import asyncio
71
+
72
+
from azure.identity.aio import DefaultAzureCredential
73
+
from azure.storage.blob.aio import BlobServiceClient
74
+
```
75
+
76
+
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 deletes the container. Note that only the top level client needs to use `asyncwith`, as other clients created from it share the same connection pool.
1. Add code to delete the container. 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 `delete_container` method.
With this basic setup in place, you can implement other examples in this article as coroutines using async/await syntax.
58
85
59
86
## Resources
60
87
@@ -69,7 +96,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
69
96
70
97
### Code samples
71
98
72
-
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_containers.py)
99
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_delete_container.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_delete_container_async.py) code samples from this article (GitHub)
Blob containers support system properties and user-defined metadata, in addition to the data they contain. This article shows how to manage system properties and user-defined metadata with 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 container metadata asynchronously](#set-container-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).
@@ -43,7 +45,7 @@ To retrieve container properties, use the following method:
43
45
44
46
The following code example fetches a container's system properties and writes the property values to a console window:
The Azure Blob Storage client library for Python supports managing container properties and metadata asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
73
+
74
+
Follow these steps to set container metadata using asynchronous APIs:
75
+
76
+
1. Add the following import statements:
77
+
78
+
```python
79
+
import asyncio
80
+
81
+
from azure.identity.aio import DefaultAzureCredential
82
+
from azure.storage.blob.aio import BlobServiceClient
83
+
```
84
+
85
+
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 container metadata. Note that only the top level client needs to use `asyncwith`, as other clients created from it share the same connection pool.
86
+
87
+
```python
88
+
asyncdefmain():
89
+
sample = ContainerSamples()
90
+
91
+
#TODO: Replace <storage-account-name> with your actual storage account name
1. Add code to set the container 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_container_properties`and`set_container_metadata` methods.
The `get_container_properties` method retrieves container 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.
120
+
The `get_container_properties` method retrieves container properties and metadata by calling both the [Get Container Properties](/rest/api/storageservices/get-container-properties) operation and the [Get Container Metadata](/rest/api/storageservices/get-container-metadata) operation.
81
121
82
122
### Code samples
83
123
84
-
-[View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_containers.py)
124
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_container_properties_metadata.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_container_properties_metadata_async.py) code samples from this article (GitHub)
0 commit comments