|
用于Azure Blob存储(非结构化数据的对象存储)的客户端库。
bash
pip install azure-storage-blob azure-identity
bash
AZURESTORAGEACCOUNT_NAME=<你的存储账户名称>
python
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
credential = DefaultAzureCredential()
account_url = https://<账户>.blob.core.windows.net
blobserviceclient = BlobServiceClient(account_url, credential=credential)
| 客户端 | 用途 | 获取方式 |
|---|---|---|
| BlobServiceClient | 账户级操作 | 直接实例化 |
| ContainerClient |
python
containerclient = blobserviceclient.getcontainer_client(mycontainer)
containerclient.createcontainer()
python
with open(./local-file.txt, rb) as data:
blobclient.uploadblob(data, overwrite=True)
python
blobclient = blobserviceclient.getblob_client(
container=mycontainer,
blob=sample.txt
)
python
containerclient = blobserviceclient.getcontainer_client(mycontainer)
python
blobclient.deleteblob()
python
python
from datetime import datetime, timedelta, timezone
from azure.storage.blob import generateblobsas, BlobSasPermissions
sastoken = generateblob_sas(
account_name=<账户>,
container_name=mycontainer,
blob_name=sample.txt,
account_key=<账户密钥>, # 或使用用户委托密钥
permission=BlobSasPermissions(read=True),
expiry=datetime.now(timezone.utc) + timedelta(hours=1)
)
python
python
from azure.identity.aio import DefaultAzureCredential
from azure.storage.blob.aio import BlobServiceClient
async def upload_async():
credential = DefaultAzureCredential()
async with BlobServiceClient(account_url, credential=credential) as client:
blobclient = client.getblob_client(mycontainer, sample.txt)
with open(./file.txt, rb) as data:
await blobclient.uploadblob(data, overwrite=True)
stream = await blobclient.downloadblob()
data = await stream.readall()
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 azure-storage-blob-py-1776376178 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 azure-storage-blob-py-1776376178 技能
skillhub install azure-storage-blob-py-1776376178
文件大小: 2.61 KB | 发布时间: 2026-4-17 16:30