|
Add this skill
npx mdskills install sickn33/azure-storage-file-share-pyComprehensive SDK reference with excellent code examples and auth patterns, but lacks agent trigger logic
1---2name: azure-storage-file-share-py3description: |4 Azure Storage File Share SDK for Python. Use for SMB file shares, directories, and file operations in the cloud.5 Triggers: "azure-storage-file-share", "ShareServiceClient", "ShareClient", "file share", "SMB".6---78# Azure Storage File Share SDK for Python910Manage SMB file shares for cloud-native and lift-and-shift scenarios.1112## Installation1314```bash15pip install azure-storage-file-share16```1718## Environment Variables1920```bash21AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...22# Or23AZURE_STORAGE_ACCOUNT_URL=https://<account>.file.core.windows.net24```2526## Authentication2728### Connection String2930```python31from azure.storage.fileshare import ShareServiceClient3233service = ShareServiceClient.from_connection_string(34 os.environ["AZURE_STORAGE_CONNECTION_STRING"]35)36```3738### Entra ID3940```python41from azure.storage.fileshare import ShareServiceClient42from azure.identity import DefaultAzureCredential4344service = ShareServiceClient(45 account_url=os.environ["AZURE_STORAGE_ACCOUNT_URL"],46 credential=DefaultAzureCredential()47)48```4950## Share Operations5152### Create Share5354```python55share = service.create_share("my-share")56```5758### List Shares5960```python61for share in service.list_shares():62 print(f"{share.name}: {share.quota} GB")63```6465### Get Share Client6667```python68share_client = service.get_share_client("my-share")69```7071### Delete Share7273```python74service.delete_share("my-share")75```7677## Directory Operations7879### Create Directory8081```python82share_client = service.get_share_client("my-share")83share_client.create_directory("my-directory")8485# Nested directory86share_client.create_directory("my-directory/sub-directory")87```8889### List Directories and Files9091```python92directory_client = share_client.get_directory_client("my-directory")9394for item in directory_client.list_directories_and_files():95 if item["is_directory"]:96 print(f"[DIR] {item['name']}")97 else:98 print(f"[FILE] {item['name']} ({item['size']} bytes)")99```100101### Delete Directory102103```python104share_client.delete_directory("my-directory")105```106107## File Operations108109### Upload File110111```python112file_client = share_client.get_file_client("my-directory/file.txt")113114# From string115file_client.upload_file("Hello, World!")116117# From file118with open("local-file.txt", "rb") as f:119 file_client.upload_file(f)120121# From bytes122file_client.upload_file(b"Binary content")123```124125### Download File126127```python128file_client = share_client.get_file_client("my-directory/file.txt")129130# To bytes131data = file_client.download_file().readall()132133# To file134with open("downloaded.txt", "wb") as f:135 data = file_client.download_file()136 data.readinto(f)137138# Stream chunks139download = file_client.download_file()140for chunk in download.chunks():141 process(chunk)142```143144### Get File Properties145146```python147properties = file_client.get_file_properties()148print(f"Size: {properties.size}")149print(f"Content type: {properties.content_settings.content_type}")150print(f"Last modified: {properties.last_modified}")151```152153### Delete File154155```python156file_client.delete_file()157```158159### Copy File160161```python162source_url = "https://account.file.core.windows.net/share/source.txt"163dest_client = share_client.get_file_client("destination.txt")164dest_client.start_copy_from_url(source_url)165```166167## Range Operations168169### Upload Range170171```python172# Upload to specific range173file_client.upload_range(data=b"content", offset=0, length=7)174```175176### Download Range177178```python179# Download specific range180download = file_client.download_file(offset=0, length=100)181data = download.readall()182```183184## Snapshot Operations185186### Create Snapshot187188```python189snapshot = share_client.create_snapshot()190print(f"Snapshot: {snapshot['snapshot']}")191```192193### Access Snapshot194195```python196snapshot_client = service.get_share_client(197 "my-share",198 snapshot=snapshot["snapshot"]199)200```201202## Async Client203204```python205from azure.storage.fileshare.aio import ShareServiceClient206from azure.identity.aio import DefaultAzureCredential207208async def upload_file():209 credential = DefaultAzureCredential()210 service = ShareServiceClient(account_url, credential=credential)211212 share = service.get_share_client("my-share")213 file_client = share.get_file_client("test.txt")214215 await file_client.upload_file("Hello!")216217 await service.close()218 await credential.close()219```220221## Client Types222223| Client | Purpose |224|--------|---------|225| `ShareServiceClient` | Account-level operations |226| `ShareClient` | Share operations |227| `ShareDirectoryClient` | Directory operations |228| `ShareFileClient` | File operations |229230## Best Practices2312321. **Use connection string** for simplest setup2332. **Use Entra ID** for production with RBAC2343. **Stream large files** using chunks() to avoid memory issues2354. **Create snapshots** before major changes2365. **Set quotas** to prevent unexpected storage costs2376. **Use ranges** for partial file updates2387. **Close async clients** explicitly239
Full transparency — inspect the skill content before installing.