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
Copy file name to clipboardExpand all lines: articles/storage/blobs/storage-blob-container-lease-python.md
+12-8Lines changed: 12 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
-
title: Create and manage blob or container leases with Python
2
+
title: Create and manage container leases with Python
3
3
titleSuffix: Azure Storage
4
-
description: Learn how to manage a lock on a blob or container in your Azure Storage account using the Python client library.
4
+
description: Learn how to manage a lock on a container in your Azure Storage account using the Python client library.
5
5
services: storage
6
6
author: pauljewellmsft
7
7
ms.author: pauljewell
@@ -14,7 +14,7 @@ ms.devlang: python
14
14
ms.custom: devx-track-python, devguide-python
15
15
---
16
16
17
-
# Create and manage blob container leases with Python
17
+
# Create and manage container leases with Python
18
18
19
19
This article shows how to create and manage container leases using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
20
20
@@ -24,11 +24,15 @@ You can use the Python client library to acquire, renew, release and break lease
24
24
25
25
## Acquire a lease
26
26
27
-
When you acquire a lease, you'll obtain a lease ID that your code can use to operate on the blob or container. To acquire a lease, create an instance of the [BlobLeaseClient](/python/api/azure-storage-blob/azure.storage.blob.blobleaseclient) class, and then use the following method:
27
+
When you acquire a lease, you'll obtain a lease ID that your code can use to operate on the container. To acquire a lease, create an instance of the [BlobLeaseClient](/python/api/azure-storage-blob/azure.storage.blob.blobleaseclient) class, and then use the following method:
The following example acquires a 30-second lease for a blob:
31
+
You can also acquire a lease using the following method from the [ContainerClient](/python/api/azure-storage-blob/azure.storage.blob.containerclient) class:
This article shows you how to connect to Azure Blob Storage by using the Azure Blob Storage client library Python. Once connected, your code can operate on containers, blobs, and features of the Blob Storage service.
18
+
This article shows you how to connect to Azure Blob Storage by using the Azure Blob Storage client library for Python. Once connected, your code can operate on containers, blobs, and features of the Blob Storage service.
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
25
25
- Azure storage account - [create a storage account](../common/storage-account-create.md)
26
+
-[Python](https://www.python.org/downloads/) 3.6+
26
27
27
28
## Set up your project
28
29
30
+
This section walks you through preparing a project to work with the Azure Blob Storage client library for Python.
31
+
32
+
From your project directory, install packages for the Azure Blob Storage and Azure Identity client libraries using the `pip install` command. The **azure-identity** package is needed for passwordless connections to Azure services.
33
+
34
+
```console
35
+
pip install azure-storage-blob azure-identity
36
+
```
37
+
38
+
Then open your code file and add the necessary import statements. In this example, we add the following to our *.py* file:
39
+
40
+
```python
41
+
from azure.identity import DefaultAzureCredential
42
+
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
43
+
```
44
+
45
+
Blob client library information:
46
+
-[azure.storage.blob](/python/api/azure-storage-blob/azure.storage.blob): Contains the primary classes (_client objects_) that you can use to operate on the service, containers, and blobs.
47
+
29
48
## Authorize access and connect to Blob Storage
30
49
31
50
To connect to Blob Storage, create an instance of the [BlobServiceClient](/python/api/azure-storage-blob/azure.storage.blob.blobserviceclient) class. This object is your starting point. You can use it to operate on the blob service instance and its containers. You can create a `BlobServiceClient` object by using an Azure Active Directory (Azure AD) authorization token, an account access key, or a shared access signature (SAS).
0 commit comments