|
| 1 | +--- |
| 2 | +title: Set or change a blob's access tier with Python |
| 3 | +titleSuffix: Azure Storage |
| 4 | +description: Learn how to set or change a blob's access tier in your Azure Storage account using the Python client library. |
| 5 | +services: storage |
| 6 | +author: pauljewellmsft |
| 7 | +ms.author: pauljewell |
| 8 | + |
| 9 | +ms.service: storage |
| 10 | +ms.topic: how-to |
| 11 | +ms.date: 07/05/2023 |
| 12 | +ms.subservice: blobs |
| 13 | +ms.devlang: python |
| 14 | +ms.custom: devx-track-python, devguide-python |
| 15 | +--- |
| 16 | + |
| 17 | +# Set or change a block blob's access tier with Python |
| 18 | + |
| 19 | +This article shows how to set or change the access tier for a block blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage). |
| 20 | + |
| 21 | +## Prerequisites |
| 22 | + |
| 23 | +To work with the code examples in this article, make sure you have: |
| 24 | + |
| 25 | +- An authorized client object to connect to Blob Storage data resources. To learn more, see [Create and manage client objects that interact with data resources](storage-blob-client-management.md). |
| 26 | +- Permissions to perform an operation to set the blob's access tier. To learn more, see the authorization guidance for the following REST API operation: |
| 27 | + - [Set Blob Tier](/rest/api/storageservices/set-blob-tier#authorization) |
| 28 | +- The package **azure-storage-blob** installed to your project directory. To learn more about setting up your project, see [Get Started with Azure Storage and Python](storage-blob-python-get-started.md#set-up-your-project). |
| 29 | + |
| 30 | +[!INCLUDE [storage-dev-guide-about-access-tiers](../../../includes/storage-dev-guides/storage-dev-guide-about-access-tiers.md)] |
| 31 | + |
| 32 | +> [!NOTE] |
| 33 | +> To set the access tier to `Cold` using Python, you must use a minimum [client library](/python/api/azure-storage-blob) version of 12.15.0. |
| 34 | +
|
| 35 | +## Set a blob's access tier during upload |
| 36 | + |
| 37 | +You can set a blob's access tier on upload by passing the `standard_blob_tier` keyword argument to [upload_blob](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-upload-blob) or [upload_blob_from_url](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-upload-blob-from-url). |
| 38 | + |
| 39 | +The following code example shows how to set the access tier when uploading a blob: |
| 40 | + |
| 41 | +:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-upload.py" id="Snippet_upload_blob_access_tier"::: |
| 42 | + |
| 43 | +To learn more about uploading a blob with Python, see [Upload a blob with Python](storage-blob-upload-python.md). |
| 44 | + |
| 45 | +## Change the access tier for an existing block blob |
| 46 | + |
| 47 | +You can change the access tier of an existing block blob by using the following function: |
| 48 | + |
| 49 | +- [set_standard_blob_tier](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-set-standard-blob-tier) |
| 50 | + |
| 51 | +The following code example shows how to change the access tier for an existing blob to `Cool`: |
| 52 | + |
| 53 | +:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-access-tiers.py" id="Snippet_change_blob_access_tier"::: |
| 54 | + |
| 55 | +If you're rehydrating an archived blob, you can optionally pass the `rehydrate_priority` keyword argument as `HIGH` or `STANDARD`. |
| 56 | + |
| 57 | +## Copy a blob to a different access tier |
| 58 | + |
| 59 | +You can change the access tier of an existing block blob by specifying an access tier as part of a copy operation. To change the access tier during a copy operation, pass the `standard_blob_tier` keyword argument to [start_copy_from_url](/python/api/azure-storage-blob/azure.storage.blob.blobclient#azure-storage-blob-blobclient-start-copy-from-url). If you're rehydrating a blob from the archive tier using a copy operation, you can optionally pass the `rehydrate_priority` keyword argument as `HIGH` or `STANDARD`. |
| 60 | + |
| 61 | +The following code example shows how to rehydrate an archived blob to the `Hot` tier using a copy operation: |
| 62 | + |
| 63 | +:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob-devguide-access-tiers.py" id="Snippet_rehydrate_using_copy"::: |
| 64 | + |
| 65 | +To learn more about copying a blob with Python, see [Copy a blob with Python](storage-blob-copy-python.md). |
| 66 | + |
| 67 | +## Resources |
| 68 | + |
| 69 | +To learn more about setting access tiers using the Azure Blob Storage client library for Python, see the following resources. |
| 70 | + |
| 71 | +### REST API operations |
| 72 | + |
| 73 | +The Azure SDK for Python contains libraries that build on top of the Azure REST API, allowing you to interact with REST API operations through familiar Python paradigms. The client library methods for setting access tiers use the following REST API operation: |
| 74 | + |
| 75 | +- [Set Blob Tier](/rest/api/storageservices/set-blob-tier) (REST API) |
| 76 | + |
| 77 | +[!INCLUDE [storage-dev-guide-resources-python](../../../includes/storage-dev-guides/storage-dev-guide-resources-python.md)] |
| 78 | + |
| 79 | +### Code samples |
| 80 | + |
| 81 | +- [View code samples from this article (GitHub)](https://github.com/Azure-Samples/AzureStorageSnippets/blob/master/blobs/howto/python/blob-devguide-py/blob-devguide-access-tiers.py) |
| 82 | + |
| 83 | +### See also |
| 84 | + |
| 85 | +- [Access tiers best practices](access-tiers-best-practices.md) |
| 86 | +- [Blob rehydration from the Archive tier](archive-rehydrate-overview.md) |
0 commit comments