AZ

azure-storage-file-share-py

A Python SDK for managing Azure Storage File Shares.

Install

mkdir -p .claude/skills/azure-storage-file-share-py && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5496" && unzip -o skill.zip -d .claude/skills/azure-storage-file-share-py && rm skill.zip

Installs to .claude/skills/azure-storage-file-share-py

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Azure Storage File Share SDK for Python. Use for SMB file shares, directories, and file operations in the cloud. Triggers: "azure-storage-file-share", "ShareServiceClient", "ShareClient", "file share", "SMB".
208 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Create and manage SMB file shares
  • Perform directory and file operations
  • Upload and download files
  • Create share snapshots

How it works

The SDK provides clients for service, share, directory, and file levels to interact with SMB file shares in Azure Storage.

Inputs & outputs

You give it
File path or data
You get back
File stream or properties

When to use azure-storage-file-share-py

  • Upload files to cloud storage
  • Manage directory structures programmatically
  • Mount cloud file shares for applications
  • Automate file synchronization

About this skill

Azure Storage File Share SDK for Python

Manage SMB file shares for cloud-native and lift-and-shift scenarios.

Installation

pip install azure-storage-file-share

Environment Variables

AZURE_STORAGE_ACCOUNT_URL=https://<account>.file.core.windows.net  # Required for Entra ID auth
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production

Authentication & Lifecycle

🔑 Two rules apply to every code sample below:

  1. Prefer DefaultAzureCredential. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.
    • Local dev: DefaultAzureCredential works as-is.
    • Production: set AZURE_TOKEN_CREDENTIALS=prod (or AZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.
  2. Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:
    • Sync: with <Client>(...) as client:
    • Async: async with <Client>(...) as client: and async with DefaultAzureCredential() as credential: (from azure.identity.aio)

Snippets may abbreviate this setup, but production code should always follow both rules.

from azure.storage.fileshare import ShareServiceClient
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential

# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()

with ShareServiceClient(
    account_url=os.environ["AZURE_STORAGE_ACCOUNT_URL"],
    credential=credential
) as service:
    # Use service here (see following sections for operations)
    ...

Share Operations

Create Share

share = service.create_share("my-share")

List Shares

for share in service.list_shares():
    print(f"{share.name}: {share.quota} GB")

Get Share Client

share_client = service.get_share_client("my-share")

Delete Share

service.delete_share("my-share")

Directory Operations

Create Directory

share_client = service.get_share_client("my-share")
share_client.create_directory("my-directory")

# Nested directory
share_client.create_directory("my-directory/sub-directory")

List Directories and Files

directory_client = share_client.get_directory_client("my-directory")

for item in directory_client.list_directories_and_files():
    if item["is_directory"]:
        print(f"[DIR] {item['name']}")
    else:
        print(f"[FILE] {item['name']} ({item['size']} bytes)")

Delete Directory

share_client.delete_directory("my-directory")

File Operations

Upload File

file_client = share_client.get_file_client("my-directory/file.txt")

# From string
file_client.upload_file("Hello, World!")

# From file
with open("local-file.txt", "rb") as f:
    file_client.upload_file(f)

# From bytes
file_client.upload_file(b"Binary content")

Download File

file_client = share_client.get_file_client("my-directory/file.txt")

# To bytes
data = file_client.download_file().readall()

# To file
with open("downloaded.txt", "wb") as f:
    data = file_client.download_file()
    data.readinto(f)

# Stream chunks
download = file_client.download_file()
for chunk in download.chunks():
    process(chunk)

Get File Properties

properties = file_client.get_file_properties()
print(f"Size: {properties.size}")
print(f"Content type: {properties.content_settings.content_type}")
print(f"Last modified: {properties.last_modified}")

Delete File

file_client.delete_file()

Copy File

source_url = "https://account.file.core.windows.net/share/source.txt"
dest_client = share_client.get_file_client("destination.txt")
dest_client.start_copy_from_url(source_url)

Range Operations

Upload Range

# Upload to specific range
file_client.upload_range(data=b"content", offset=0, length=7)

Download Range

# Download specific range
download = file_client.download_file(offset=0, length=100)
data = download.readall()

Snapshot Operations

Create Snapshot

snapshot = share_client.create_snapshot()
print(f"Snapshot: {snapshot['snapshot']}")

Access Snapshot

snapshot_client = service.get_share_client(
    "my-share",
    snapshot=snapshot["snapshot"]
)

Async Client

from azure.storage.fileshare.aio import ShareServiceClient
from azure.identity.aio import DefaultAzureCredential

async def upload_file():
    async with DefaultAzureCredential() as credential:
        async with ShareServiceClient(account_url, credential=credential) as service:
            share = service.get_share_client("my-share")
            file_client = share.get_file_client("test.txt")
            
            await file_client.upload_file("Hello!")

Client Types

ClientPurpose
ShareServiceClientAccount-level operations
ShareClientShare operations
ShareDirectoryClientDirectory operations
ShareFileClientFile operations

Best Practices

  1. Pick sync OR async and stay consistent. Do not mix azure.storage.fileshare sync clients with azure.storage.fileshare.aio async clients in the same call path. Choose one mode per module.
  2. Always use context managers for clients and async credentials. Wrap every client in with ShareServiceClient(...) as client: (sync) or async with ShareServiceClient(...) as client: (async). For async DefaultAzureCredential from azure.identity.aio, also use async with credential: so tokens and transports are cleaned up.
  3. Use DefaultAzureCredential for portable auth across local dev and Azure (avoid connection strings / API keys when possible).
  4. Use Microsoft Entra ID for production with RBAC
  5. Stream large files using chunks() to avoid memory issues
  6. Create snapshots before major changes
  7. Set quotas to prevent unexpected storage costs
  8. Use ranges for partial file updates

Reference Files

FileContents
references/capabilities.mdAdditional non-hero capabilities, operation-group coverage, and production checklists.
references/non-hero-scenarios.mdDedicated non-hero examples for secondary/advanced scenarios.

When not to use it

  • When requiring block storage performance
  • When file share size exceeds storage account limits

Prerequisites

azure-storage-file-share

Limitations

  • Sync and async clients cannot be mixed in the same call path
  • Requires context managers for resource release

How it compares

It allows programmatic management of cloud-native file systems compared to manual mounting.

Compared to similar skills

azure-storage-file-share-py side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
azure-storage-file-share-py (this skill)129dReviewIntermediate
telegram-bot-builder1066moReviewIntermediate
async-python-patterns122moNo flagsIntermediate
modal57moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by microsoft

View all by microsoft

You might also like

telegram-bot-builder

davila7

Expert in building Telegram bots that solve real problems - from simple automation to complex AI-powered bots. Covers bot architecture, the Telegram Bot API, user experience, monetization strategies, and scaling bots to thousands of users. Use when: telegram bot, bot api, telegram automation, chat bot telegram, tg bot.

106130

async-python-patterns

wshobson

Master Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.

1299

modal

davila7

Run Python code in the cloud with serverless containers, GPUs, and autoscaling. Use when deploying ML models, running batch processing jobs, scheduling compute-intensive tasks, or serving APIs that require GPU acceleration or dynamic scaling.

587

python-background-jobs

wshobson

Python background job patterns including task queues, workers, and event-driven architecture. Use when implementing async task processing, job queues, long-running operations, or decoupling work from request/response cycles.

615

opentrons-integration

davila7

Lab automation platform for Flex/OT-2 robots. Write Protocol API v2 protocols, liquid handling, hardware modules (heater-shaker, thermocycler), labware management, for automated pipetting workflows.

314

superpowers-python-automation

anthonylee991

Implements reliable automations in Python for REST APIs: httpx/requests patterns, retries, timeouts, pagination, typing, config, logging, and tests. Use when writing Python scripts/services that call external APIs.

36

Search skills

Search the agent skills registry