Azure Storage File Share Py
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Cloud and DevOps
- MIT
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a comprehensive guide to using the Azure Storage File Share SDK for Python. It covers essential operations including managing shares, directories, and files, while emphasizing secure authentication practices using DefaultAzureCredential and proper resource lifecycle management through context managers. The documentation includes both synchronous and asynchronous patterns, as well as advanced operations like snapshots and range-based file access.
What it does
- Create, list, and delete Azure SMB file shares.
- Manage directory structures within file shares.
- Upload, download, and delete files with support for streaming.
- Perform range-based operations for partial file updates or downloads.
- Manage share snapshots for data protection.
- Support both synchronous and asynchronous programming models.
When to use it
- When integrating Azure File Storage into Python-based cloud applications.
- When you need to perform programmatic file system operations in the cloud.
- When migrating existing file-based workflows to Azure SMB shares.
- When building cloud-native applications requiring persistent storage.
Advantages
- Promotes secure authentication via Entra ID and DefaultAzureCredential.
- Ensures resource efficiency by enforcing context manager usage.
- Provides consistent patterns for both sync and async development.
- Includes best practices for handling large files and storage costs.
Usage examples
- “How do I list all files in a specific Azure file share directory using Python?”
- The agent provides a code snippet using ShareClient and get_directory_client to iterate through and print the contents of a directory.
- “Show me how to upload a local file to an Azure file share.”
- The agent demonstrates using ShareFileClient.upload_file with a file object opened in binary mode.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/microsoft/azure-storage-file-share-py/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-storage-file-share-py.zip -d .agents/skills
Documentation by Microsoft
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-shareEnvironment 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 productionAuthentication & Lifecycle
🔑 Two rules apply to every code sample below:
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:
DefaultAzureCredentialworks as-is.Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.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:andasync with DefaultAzureCredential() as credential:(fromazure.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
| Client | Purpose |
|---|---|
ShareServiceClient | Account-level operations |
ShareClient | Share operations |
ShareDirectoryClient | Directory operations |
ShareFileClient | File operations |
Best Practices
Pick sync OR async and stay consistent. Do not mix
azure.storage.filesharesync clients withazure.storage.fileshare.aioasync clients in the same call path. Choose one mode per module.Always use context managers for clients and async credentials. Wrap every client in
with ShareServiceClient(...) as client:(sync) orasync with ShareServiceClient(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up.Use
DefaultAzureCredentialfor portable auth across local dev and Azure (avoid connection strings / API keys when possible).Use Microsoft Entra ID for production with RBAC
Stream large files using chunks() to avoid memory issues
Create snapshots before major changes
Set quotas to prevent unexpected storage costs
Use ranges for partial file updates
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
Files
- ATTRIBUTION.mdAdded by AutoGineer992 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md7.1 KiB
- references/capabilities.md1.4 KiB
- references/non-hero-scenarios.md1.2 KiB
references/capabilities.md
azure-storage-file-share-py capability coverage
SDK/package: azure-storage-file-share
This index maps hero scenarios in SKILL.md and links non-hero scenarios documented in dedicated reference files.
Hero scenarios covered in SKILL.md
Share OperationsDirectory OperationsFile OperationsRange Operations
Non-hero scenarios
Snapshot Operations: Dedicated example and implementation notes.
See:non-hero-scenarios.md#snapshot-operationsAsync Client: Dedicated example and implementation notes.
See:non-hero-scenarios.md#async-clientClient Types: | Client | Purpose |
See:non-hero-scenarios.md#client-types
Related deep-dive references
non-hero-scenarios.md: Dedicated non-hero examples and implementation notes.
API breadth checklist
Verify client/auth mode for the environment before coding.
Confirm operation-group/method names against current Microsoft Learn API reference.
For Python SDKs with both sync and async clients, document both forms without a blanket preference.
Include cleanup/delete paths for created resources in examples.
Prefer idempotent create/update operations where available.
Validate paging/LRO/error-handling patterns for production paths.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs an API key, Needs Python
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-python/skills/azure-storage-file-share-py · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft or Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-storage-file-share-py.zip