Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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".
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 18% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 43% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 61% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 107% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 48% | 0% |
Manage SMB file shares for cloud-native and lift-and-shift scenarios.
bashpip install azure-storage-file-share
bashAZURE_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
> 🔑 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.
pythonfrom 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) ...
pythonshare = service.create_share("my-share")
pythonfor share in service.list_shares(): print(f"{share.name}: {share.quota} GB")
pythonshare_client = service.get_share_client("my-share")
pythonservice.delete_share("my-share")
pythonshare_client = service.get_share_client("my-share") share_client.create_directory("my-directory") # Nested directory share_client.create_directory("my-directory/sub-directory")
pythondirectory_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)")
pythonshare_client.delete_directory("my-directory")
pythonfile_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")
pythonfile_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)
pythonproperties = 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}")
pythonfile_client.delete_file()
pythonsource_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)
python# Upload to specific range file_client.upload_range(data=b"content", offset=0, length=7)
python# Download specific range download = file_client.download_file(offset=0, length=100) data = download.readall()
pythonsnapshot = share_client.create_snapshot() print(f"Snapshot: {snapshot['snapshot']}")
pythonsnapshot_client = service.get_share_client( "my-share", snapshot=snapshot["snapshot"] )
pythonfrom 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 | Purpose | |--------|---------| | ShareServiceClient | Account-level operations | | ShareClient | Share operations | | ShareDirectoryClient | Directory operations | | ShareFileClient | File operations |
azure.storage.fileshare sync clients with azure.storage.fileshare.aio async clients in the same call path. Choose one mode per module.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.DefaultAzureCredential for portable auth across local dev and Azure (avoid connection strings / API keys when possible).| 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. |
Other measured skills in the registry, with their headline benchmark lift.