Skip to content

Commit 6b83daa

Browse files
Edits
1 parent caf08dd commit 6b83daa

File tree

3 files changed

+46
-31
lines changed

3 files changed

+46
-31
lines changed

articles/storage/blobs/storage-blob-container-create-python.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,22 @@ To learn about creating blob containers using asynchronous APIs, see [Create a c
2727

2828
[!INCLUDE [storage-dev-guide-project-setup-python](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-python.md)]
2929

30+
#### Add import statements
31+
32+
Add the following `import` statements:
33+
34+
```python
35+
from azure.core.exceptions import ResourceExistsError
36+
from azure.identity import DefaultAzureCredential
37+
from azure.storage.blob import BlobServiceClient
38+
```
39+
3040
#### Authorization
3141

3242
The authorization mechanism must have the necessary permissions to create a container. For authorization with Microsoft Entra ID (recommended), you need Azure RBAC built-in role **Storage Blob Data Contributor** or higher. To learn more, see the authorization guidance for [Create Container (REST API)](/rest/api/storageservices/create-container#authorization).
3343

44+
[!INCLUDE [storage-dev-guide-create-client-python](../../../includes/storage-dev-guides/storage-dev-guide-create-client-python.md)]
45+
3446
[!INCLUDE [storage-dev-guide-about-container-naming](../../../includes/storage-dev-guides/storage-dev-guide-about-container-naming.md)]
3547

3648
## Create a container
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: "include file"
3+
description: "include file"
4+
services: storage
5+
author: pauljewellmsft
6+
ms.service: azure-blob-storage
7+
ms.topic: include
8+
ms.date: 08/19/2024
9+
ms.author: pauljewell
10+
ms.custom: include file
11+
---
12+
13+
#### Create a client object
14+
15+
To connect an app to Blob Storage, create an instance of [BlobServiceClient](/python/api/azure-storage-blob/azure.storage.blob.blobserviceclient). The following example shows how to create a client object using `DefaultAzureCredential` for authorization:
16+
17+
```python
18+
def get_blob_service_client_token_credential(self):
19+
# TODO: Replace <storage-account-name> with your actual storage account name
20+
account_url = "https://<storage-account-name>.blob.core.windows.net"
21+
credential = DefaultAzureCredential()
22+
23+
# Create the BlobServiceClient object
24+
blob_service_client = BlobServiceClient(account_url, credential=credential)
25+
26+
return blob_service_client
27+
```
28+
29+
You can also create client objects for specific [containers](../../articles/storage/blobs/storage-blob-client-management.md#create-a-blobcontainerclient-object) or [blobs](../../articles/storage/blobs/storage-blob-client-management.md#create-a-blobclient-object). To learn more about creating and managing client objects, see [Create and manage client objects that interact with data resources](../../articles/storage/blobs/storage-blob-client-management.md).
30+

includes/storage-dev-guides/storage-dev-guide-project-setup-python.md

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,15 @@ ms.author: pauljewell
1010
ms.custom: include file
1111
---
1212

13-
If you don't have an existing project, this section shows you how to set up a project to work with the Azure Blob Storage client library for Python. The steps include package installation, adding `import` statements, and creating an authorized client object. For details, see [Get started with Azure Blob Storage and Python](../../articles/storage/blobs/storage-blob-python-get-started.md).
13+
If you don't have an existing project, this section shows you how to set up a project to work with the Azure Blob Storage client library for Python. For more details, see [Get started with Azure Blob Storage and Python](../../articles/storage/blobs/storage-blob-python-get-started.md).
14+
15+
To work with the code examples in this article, follow these steps to set up your project.
1416

1517
#### Install packages
1618

17-
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.
19+
Install the following packages using `pip install`:
1820

1921
```console
2022
pip install azure-storage-blob azure-identity
2123
```
2224

23-
#### Add `import` statements
24-
25-
Add these `import` statements to your code file:
26-
27-
```python
28-
from azure.identity import DefaultAzureCredential
29-
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
30-
```
31-
32-
Some code examples in this article might require additional `import` statements.
33-
34-
#### Create a client object
35-
36-
To connect an app to Blob Storage, create an instance of [BlobServiceClient](/python/api/azure-storage-blob/azure.storage.blob.blobserviceclient). The following example shows how to create a client object using `DefaultAzureCredential` for authorization:
37-
38-
```python
39-
def get_blob_service_client_token_credential(self):
40-
# TODO: Replace <storage-account-name> with your actual storage account name
41-
account_url = "https://<storage-account-name>.blob.core.windows.net"
42-
credential = DefaultAzureCredential()
43-
44-
# Create the BlobServiceClient object
45-
blob_service_client = BlobServiceClient(account_url, credential=credential)
46-
47-
return blob_service_client
48-
```
49-
50-
You can also create client objects for specific [containers](../../articles/storage/blobs/storage-blob-client-management.md#create-a-blobcontainerclient-object) or [blobs](../../articles/storage/blobs/storage-blob-client-management.md#create-a-blobclient-object). To learn more about creating and managing client objects, see [Create and manage client objects that interact with data resources](../../articles/storage/blobs/storage-blob-client-management.md).
51-

0 commit comments

Comments
 (0)