Skip to content

Commit caf08dd

Browse files
Add include files
1 parent 4d1a362 commit caf08dd

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ Blobs in Azure Storage are organized into containers. Before you can upload a bl
2121

2222
To learn about creating blob containers using asynchronous APIs, see [Create a container asynchronously](#create-a-container-asynchronously).
2323

24-
## Prerequisites
24+
[!INCLUDE [storage-dev-guide-prereqs-python](../../../includes/storage-dev-guides/storage-dev-guide-prereqs-python.md)]
2525

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).
27-
- The [authorization mechanism](../common/authorize-data-access.md) must have permissions to create a blob container. To learn more, see the authorization guidance for the following REST API operation:
28-
- [Create Container](/rest/api/storageservices/create-container#authorization)
26+
## Set up your environment
27+
28+
[!INCLUDE [storage-dev-guide-project-setup-python](../../../includes/storage-dev-guides/storage-dev-guide-project-setup-python.md)]
29+
30+
#### Authorization
31+
32+
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).
2933

3034
[!INCLUDE [storage-dev-guide-about-container-naming](../../../includes/storage-dev-guides/storage-dev-guide-about-container-naming.md)]
3135

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
## Prerequisites
14+
15+
- Azure subscription - [create one for free](https://azure.microsoft.com/free/)
16+
- Azure storage account - [create a storage account](../../articles/storage/common/storage-account-create.md)
17+
- [Python](https://www.python.org/downloads/) 3.8+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
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).
14+
15+
#### Install packages
16+
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.
18+
19+
```console
20+
pip install azure-storage-blob azure-identity
21+
```
22+
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)