|
| 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