Azure Storage Account
Azure Blob Storage is a cloud storage solution for data storage and retrieval that is highly available, secure, durable, and scalable. cshelve can be configured to use Azure Blob Storage as a provider for storing and retrieving data.
Installation
Section titled “Installation”To install the cshelve package with Azure Blob support, run the following command:
pip install cshelve[azure-blob]
Configuration Options
Section titled “Configuration Options”The following table lists the configuration options available for the Azure Blob Storage provider:
Scope | Option | Description | Required |
---|---|---|---|
default | account_url | URL of the Azure Blob Storage account | No |
default | auth_type | Authentication method: access_key , connection_string , passwordless , or anonymous . | Yes |
default | container_name | Container name in the Azure storage account | Yes |
logging | http | Enable HTTP logging | No |
logging | credentials | Enable logging for credential operations | No |
Permissions
Section titled “Permissions”Flag | Description | Permissions Needed |
---|---|---|
r | Open existing container for read-only access. | Storage Blob Data Reader |
w | Open existing container for read/write access. | Storage Blob Data Contributor |
c | Open container with read/write access, creating it if necessary. | Storage Blob Data Contributor |
Logging Configuration
Section titled “Logging Configuration”The logging configuration allows enabling HTTP logging for blob storage operations and credential operations. To view logging output, you must configure the logging handler as explained in the Azure SDK logging documentation.
Example: Passwordless Authentication
Section titled “Example: Passwordless Authentication”cat passwordless.ini[default]provider = azure-blobaccount_url = https://myaccount.blob.core.windows.netauth_type = passwordlesscontainer_name = mycontainer
[logging]http = true
import cshelveimport sysimport logging
logger = logging.getLogger()logger.setLevel(logging.DEBUG)handler = logging.StreamHandler(stream=sys.stdout)logger.addHandler(handler)
with cshelve.open('passwordless.ini') as db: ...
Example: Access Key Authentication
Section titled “Example: Access Key Authentication”cat access-key.ini[default]provider = azure-blobaccount_url = https://myaccount.blob.core.windows.netauth_type = access_key# Environment variables: AZURE_STORAGE_ACCESS_KEYcontainer_name = containerkey_id = AZURE_STORAGE_KEY_IDkey_secret = AZURE_STORAGE_KEY_SECRET
Example: Connection String Authentication
Section titled “Example: Connection String Authentication”cat connection-string.ini[default]provider = azure-blobauth_type = connection_stringenvironment_key = AZURE_STORAGE_CONNECTION_STRINGcontainer_name = test-connection-string
Example: Anonymous Authentication
Section titled “Example: Anonymous Authentication”cat anonymous.ini[default]provider = azure-blobaccount_url = https://myaccount.blob.core.windows.netauth_type = anonymouscontainer_name = public-container
Configure the BlobServiceClient
Section titled “Configure the BlobServiceClient”Behind the scenes, this provider uses the BlobServiceClient.
import cshelve
provider_params = { 'secondary_hostname': 'https://secondary.blob.core.windows.net', 'max_block_size': 4 * 1024 * 1024, # 4 MB 'use_byte_buffer': True}
with cshelve.open('azure-blob.ini', provider_params=provider_params) as db: ...