Skip to content

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.

To install the cshelve package with Azure Blob support, run the following command:

Terminal window
pip install cshelve[azure-blob]

The following table lists the configuration options available for the Azure Blob Storage provider:

ScopeOptionDescriptionRequired
defaultaccount_urlURL of the Azure Blob Storage accountNo
defaultauth_typeAuthentication method: access_key, connection_string, passwordless, or anonymous.Yes
defaultcontainer_nameContainer name in the Azure storage accountYes
logginghttpEnable HTTP loggingNo
loggingcredentialsEnable logging for credential operationsNo
FlagDescriptionPermissions Needed
rOpen existing container for read-only access.Storage Blob Data Reader
wOpen existing container for read/write access.Storage Blob Data Contributor
cOpen container with read/write access, creating it if necessary.Storage Blob Data Contributor

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.

Terminal window
cat passwordless.ini
[default]
provider = azure-blob
account_url = https://myaccount.blob.core.windows.net
auth_type = passwordless
container_name = mycontainer
[logging]
http = true
import cshelve
import sys
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)
with cshelve.open('passwordless.ini') as db:
...
Terminal window
cat access-key.ini
[default]
provider = azure-blob
account_url = https://myaccount.blob.core.windows.net
auth_type = access_key
# Environment variables: AZURE_STORAGE_ACCESS_KEY
container_name = container
key_id = AZURE_STORAGE_KEY_ID
key_secret = AZURE_STORAGE_KEY_SECRET
Terminal window
cat connection-string.ini
[default]
provider = azure-blob
auth_type = connection_string
environment_key = AZURE_STORAGE_CONNECTION_STRING
container_name = test-connection-string
Terminal window
cat anonymous.ini
[default]
provider = azure-blob
account_url = https://myaccount.blob.core.windows.net
auth_type = anonymous
container_name = public-container

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