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 create and manage container leases using the [Azure Storage client library for Python](/python/api/overview/azure/storage). You can use the client library to acquire, renew, release and break container leases.
21
21
22
+
To learn about leasing a blob container using asynchronous APIs, see [Lease containers asynchronously](#lease-containers-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).
@@ -83,6 +85,31 @@ The following example breaks the lease on a container:
The Azure Blob Storage client library for Python supports leasing containers asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
91
+
92
+
Follow these steps to lease a container using asynchronous APIs:
93
+
94
+
1. Add the following import statements:
95
+
96
+
```python
97
+
import asyncio
98
+
99
+
from azure.identity.aio import DefaultAzureCredential
100
+
from azure.storage.blob.aio import BlobServiceClient, BlobLeaseClient
101
+
```
102
+
103
+
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 acquires the container lease. 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 acquire a container lease. 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 `acquire` method.
@@ -97,7 +124,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
97
124
98
125
### Code samples
99
126
100
-
-[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)
127
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_lease_container.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_lease_container_async.py) code samples from this article (GitHub)
This article shows how to create and manage blob leases using the [Azure Storage client library for Python](/python/api/overview/azure/storage). You can use the client library to acquire, renew, release, and break blob leases.
21
21
22
+
To learn about leasing a blob using asynchronous APIs, see [Lease blobs asynchronously](#lease-blobs-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).
@@ -83,6 +85,31 @@ The following example breaks the lease on a blob:
The Azure Blob Storage client library for Python supports leasing blobs asynchronously. To learn more about project setup requirements, see [Asynchronous programming](storage-blob-python-get-started.md#asynchronous-programming).
91
+
92
+
Follow these steps to lease a blob using asynchronous APIs:
93
+
94
+
1. Add the following import statements:
95
+
96
+
```python
97
+
import asyncio
98
+
99
+
from azure.identity.aio import DefaultAzureCredential
100
+
from azure.storage.blob.aio import BlobServiceClient, BlobLeaseClient
101
+
```
102
+
103
+
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 acquires the blob lease. 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 acquire a blob lease. 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 `acquire_lease` method.
@@ -97,7 +124,7 @@ The Azure SDK for Python contains libraries that build on top of the Azure REST
97
124
98
125
### Code samples
99
126
100
-
-[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)
127
+
- View [synchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_lease_blobs.py) or [asynchronous](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob_devguide_lease_blobs_async.py) code samples from this article (GitHub)
0 commit comments