Microsoft Azure File DataLake Storage Client Library for Python
Overall
score
92%
Account-level operations for managing file systems, user delegation keys, and service properties. The DataLakeServiceClient provides the entry point for accessing Data Lake Storage Gen2 resources and managing account-wide settings.
Main service client for Data Lake Storage Gen2 operations at the account level. Manages file systems and provides factory methods for creating other client types.
class DataLakeServiceClient:
"""
A client to interact with Azure Data Lake Storage Gen2 account.
Attributes:
url (str): The full endpoint URL to the datalake service endpoint
primary_endpoint (str): The full primary endpoint URL
primary_hostname (str): The hostname of the primary endpoint
"""
def __init__(
self,
account_url: str,
credential=None,
**kwargs
):
"""
Initialize the DataLakeServiceClient.
Args:
account_url (str): The URL to the DataLake storage account
credential: Authentication credential (account key, SAS token, etc.)
**kwargs: Additional client configuration options
"""
@classmethod
def from_connection_string(
cls,
conn_str: str,
credential=None,
**kwargs
) -> 'DataLakeServiceClient':
"""
Create DataLakeServiceClient from connection string.
Args:
conn_str (str): Connection string for the storage account
credential: Optional credential to override connection string auth
**kwargs: Additional client configuration options
Returns:
DataLakeServiceClient: The service client instance
"""
def close(self) -> None:
"""Close the sockets opened by the client."""
def __enter__(self) -> 'DataLakeServiceClient':
"""Context manager entry."""
def __exit__(self, *args) -> None:
"""Context manager exit."""Usage Examples:
from azure.storage.filedatalake import DataLakeServiceClient
# Using account key
service_client = DataLakeServiceClient(
account_url="https://mystorageaccount.dfs.core.windows.net",
credential="<account_key>"
)
# Using connection string
service_client = DataLakeServiceClient.from_connection_string(
"DefaultEndpointsProtocol=https;AccountName=mystorageaccount;AccountKey=<key>;EndpointSuffix=core.windows.net"
)
# Using Azure Identity (requires azure-identity package)
from azure.identity import DefaultAzureCredential
service_client = DataLakeServiceClient(
account_url="https://mystorageaccount.dfs.core.windows.net",
credential=DefaultAzureCredential()
)Operations for creating, listing, and managing file systems within the storage account.
def create_file_system(
self,
file_system: Union[FileSystemProperties, str],
metadata: Dict[str, str] = None,
public_access: PublicAccess = None,
**kwargs
) -> FileSystemClient:
"""
Create a new file system in the account.
Args:
file_system: Name of the file system or FileSystemProperties object
metadata (dict, optional): Metadata key-value pairs
public_access (PublicAccess, optional): Public access level
**kwargs: Additional options
Returns:
FileSystemClient: Client for the created file system
"""
def list_file_systems(
self,
name_starts_with: str = None,
include_metadata: bool = False,
**kwargs
) -> ItemPaged[FileSystemProperties]:
"""
List file systems in the account.
Args:
name_starts_with (str, optional): Filter by prefix
include_metadata (bool): Include metadata in results
**kwargs: Additional options
Returns:
ItemPaged[FileSystemProperties]: Paged list of file systems
"""
def delete_file_system(
self,
file_system: Union[FileSystemProperties, str],
**kwargs
) -> FileSystemClient:
"""
Delete a file system.
Args:
file_system: Name of the file system or FileSystemProperties object
**kwargs: Additional options
Returns:
FileSystemClient: Client for the deleted file system
"""
def undelete_file_system(
self,
name: str,
deleted_version: str,
**kwargs
) -> FileSystemClient:
"""
Restore a soft-deleted file system.
Args:
name (str): Name of the deleted file system
deleted_version (str): Version identifier of the deleted file system
**kwargs: Additional options
Returns:
FileSystemClient: Client for the restored file system
"""
def get_user_delegation_key(
self,
key_start_time: datetime,
key_expiry_time: datetime,
**kwargs
) -> UserDelegationKey:
"""
Get a user delegation key for creating user delegation SAS tokens.
Args:
key_start_time (datetime): Start time for the key validity
key_expiry_time (datetime): Expiry time for the key validity
**kwargs: Additional options
Returns:
UserDelegationKey: The user delegation key for SAS token creation
"""Methods for creating specialized client instances for specific resources.
def get_file_system_client(
self,
file_system: Union[FileSystemProperties, str]
) -> FileSystemClient:
"""
Get a FileSystemClient for a specific file system.
Args:
file_system: Name of the file system or FileSystemProperties object
Returns:
FileSystemClient: Client for the specified file system
"""
def get_directory_client(
self,
file_system: Union[FileSystemProperties, str],
directory: Union[DirectoryProperties, str]
) -> DataLakeDirectoryClient:
"""
Get a DataLakeDirectoryClient for a specific directory.
Args:
file_system: Name of the file system or FileSystemProperties object
directory: Name of the directory or DirectoryProperties object
Returns:
DataLakeDirectoryClient: Client for the specified directory
"""
def get_file_client(
self,
file_system: Union[FileSystemProperties, str],
file_path: Union[FileProperties, str]
) -> DataLakeFileClient:
"""
Get a DataLakeFileClient for a specific file.
Args:
file_system: Name of the file system or FileSystemProperties object
file_path: Path to the file or FileProperties object
Returns:
DataLakeFileClient: Client for the specified file
"""Operations for managing account-level service properties and obtaining user delegation keys for SAS token generation.
def get_service_properties(self, **kwargs) -> Dict[str, Any]:
"""
Get storage account service properties.
Args:
**kwargs: Additional options
Returns:
dict: Service properties including CORS, logging, metrics settings
"""
def set_service_properties(self, **kwargs) -> None:
"""
Set storage account service properties.
Args:
analytics_logging (AnalyticsLogging, optional): Logging configuration
hour_metrics (Metrics, optional): Hour metrics configuration
minute_metrics (Metrics, optional): Minute metrics configuration
cors (List[CorsRule], optional): CORS rules
target_version (str, optional): Target service version
delete_retention_policy (RetentionPolicy, optional): Delete retention policy
static_website (StaticWebsite, optional): Static website configuration
**kwargs: Additional options
"""Usage Examples:
from datetime import datetime, timedelta
# List all file systems
file_systems = service_client.list_file_systems(include_metadata=True)
for fs in file_systems:
print(f"File System: {fs.name}, Modified: {fs.last_modified}")
# Create a file system
fs_client = service_client.create_file_system(
"myfilesystem",
metadata={"project": "data-analysis", "env": "prod"}
)
# Get a user delegation key for SAS token generation
start_time = datetime.utcnow()
expiry_time = start_time + timedelta(hours=1)
user_delegation_key = service_client.get_user_delegation_key(
key_start_time=start_time,
key_expiry_time=expiry_time
)Install with Tessl CLI
npx tessl i tessl/pypi-azure-storage-file-datalakedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10