Azure
Note
Install with pip install labox[azure]
Blob Storage
The BlobStorage provides a
storage implementation backed by
Azure Blob Storage using
the BlobServiceClient client.
A minimal setup for the BlobStorage requires a blob service client and a "router"
function that tells the storage in what container and under what path each piece of
content should be saved:
from azure.storage.blob.aio import BlobServiceClient
from labox.extra.azure import BlobStorage
from labox.extra.azure import simple_blob_router
blob_storage = BlobStorage(
service_client=BlobServiceClient(
account_url="https://myaccount.blob.core.windows.net", credential="<your-credential>"
),
blob_router=simple_blob_router("my-container"),
)
The simple_blob_router requires a container name and an optional prefix that blobs
should be added under. If no blob_router is provided the storage becomes read-only and
attempts to write to it will produce a NotImplementedError.
Blob Router
A BlobRouter is a function that returns a
BlobPointer dict given:
- a digest
- a tag map
- and a
tempflag indicating whether the content being written will be deleted after use (this happens for streaming uploads).
The simple_blob_router creates paths of the form:
Where:
prefixis the optionally provided path prefixcontent_hashcomes from theDigestpassed to the router functionextis the file extension inferred from thecontent_typewithin theDigest
In the case the temp flag is true simple_blob_router creates a path of the form:
Where uuid is a uuid4 hex string.
Blob Streamed Uploads
When data is being streamed to a BlobStorage, the content is first uploaded to a
temporary location within the container. Since the hash of the content is not known
upfront, a temporary location is requested from the storage's router by
passing it temp=True. When the upload is complete a final location is requested from
the router without the temp flag. The data is then copied from the temporary location
to the final location using Azure's server-side copy operation, and the temporary blob
is deleted.