DataLakeServiceClient class
Definition
A client to interact with the DataLake Service at the account level.
This client provides operations to retrieve and configure the account properties as well as list, create and delete file systems within the account. For operations relating to a specific file system, directory or file, clients for those entities can also be retrieved using the get_client functions.
DataLakeServiceClient(account_url, credential=None, **kwargs)
- Inheritance
-
builtins.objectazure.storage.filedatalake._shared.base_client_async.AsyncStorageAccountHostsMixinDataLakeServiceClientazure.storage.filedatalake._shared.base_client.StorageAccountHostsMixinazure.storage.filedatalake._data_lake_service_client.DataLakeServiceClientDataLakeServiceClient
Parameters
- account_url
- str
The URL to the DataLake storage account. Any other entities included in the URL path (e.g. file system or file) will be discarded. This URL can be optionally authenticated with a SAS token.
- credential
The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, and account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.
Examples
Creating the DataLakeServiceClient from connection string.
from azure.storage.filedatalake.aio import DataLakeServiceClient
datalake_service_client = DataLakeServiceClient.from_connection_string(connection_string)
Creating the DataLakeServiceClient with Azure Identity credentials.
from azure.identity.aio import ClientSecretCredential
token_credential = ClientSecretCredential(
active_directory_tenant_id,
active_directory_application_id,
active_directory_application_secret,
)
datalake_service_client = DataLakeServiceClient("https://{}.dfs.core.windows.net".format(account_name),
credential=token_credential)
Variables
- url
- str
- primary_endpoint
- str
- primary_hostname
- str
Methods
| close |
This method is to close the sockets opened by the client. It need not be used when using with a context manager. |
| create_file_system |
Creates a new file system under the specified account. If the file system with the same name already exists, a ResourceExistsError will be raised. This method returns a client with which to interact with the newly created file system. |
| delete_file_system |
Marks the specified file system for deletion. The file system and any files contained within it are later deleted during garbage collection. If the file system is not found, a ResourceNotFoundError will be raised. |
| get_directory_client |
Get a client to interact with the specified directory. The directory need not already exist. |
| get_file_client |
Get a client to interact with the specified file. The file need not already exist. |
| get_file_system_client |
Get a client to interact with the specified file system. The file system need not already exist. |
| get_user_delegation_key |
Obtain a user delegation key for the purpose of signing SAS tokens. A token credential must be present on the service object for this request to succeed. |
| list_file_systems |
Returns a generator to list the file systems under the specified account. The generator will lazily follow the continuation tokens returned by the service and stop when all file systems have been returned. |
close
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
close()
create_file_system
Creates a new file system under the specified account.
If the file system with the same name already exists, a ResourceExistsError will be raised. This method returns a client with which to interact with the newly created file system.
create_file_system(file_system, metadata=None, public_access=None, **kwargs)
Parameters
- file_system
- str
The name of the file system to create.
- metadata
- dict(str, str)
A dict with name-value pairs to associate with the file system as metadata. Example: {'Category':'test'}
Return type
Examples
Creating a file system in the datalake service.
await datalake_service_client.create_file_system("filesystem")
delete_file_system
Marks the specified file system for deletion.
The file system and any files contained within it are later deleted during garbage collection. If the file system is not found, a ResourceNotFoundError will be raised.
delete_file_system(file_system, **kwargs)
Parameters
- file_system
- str or FileSystemProperties
The file system to delete. This can either be the name of the file system, or an instance of FileSystemProperties.
Return type
Examples
Deleting a file system in the datalake service.
await datalake_service_client.delete_file_system("filesystem")
get_directory_client
Get a client to interact with the specified directory.
The directory need not already exist.
get_directory_client(file_system, directory)
Parameters
- file_system
- str or FileSystemProperties
The file system that the directory is in. This can either be the name of the file system, or an instance of FileSystemProperties.
- directory
- str or DirectoryProperties
The directory with which to interact. This can either be the name of the directory, or an instance of DirectoryProperties.
Returns
A DataLakeDirectoryClient.
Return type
Examples
Getting the directory client to interact with a specific directory.
directory_client = datalake_service_client.get_directory_client(file_system_client.file_system_name,
"mydirectory")
get_file_client
Get a client to interact with the specified file.
The file need not already exist.
get_file_client(file_system, file_path)
Parameters
- file_system
- str or FileSystemProperties
The file system that the file is in. This can either be the name of the file system, or an instance of FileSystemProperties.
- file_path
- str or FileProperties
The file with which to interact. This can either be the full path of the file(from the root directory), or an instance of FileProperties. eg. directory/subdirectory/file
Returns
A DataLakeFileClient.
Return type
Examples
Getting the file client to interact with a specific file.
file_client = datalake_service_client.get_file_client(file_system_client.file_system_name, "myfile")
get_file_system_client
Get a client to interact with the specified file system.
The file system need not already exist.
get_file_system_client(file_system)
Parameters
- file_system
- str or FileSystemProperties
The file system. This can either be the name of the file system, or an instance of FileSystemProperties.
Returns
A FileSystemClient.
Return type
Examples
Getting the file system client to interact with a specific file system.
# Instantiate a DataLakeServiceClient using a connection string
from azure.storage.filedatalake.aio import DataLakeServiceClient
datalake_service_client = DataLakeServiceClient.from_connection_string(self.connection_string)
async with datalake_service_client:
# Instantiate a FileSystemClient
file_system_client = datalake_service_client.get_file_system_client("mynewfilesystems")
get_user_delegation_key
Obtain a user delegation key for the purpose of signing SAS tokens. A token credential must be present on the service object for this request to succeed.
get_user_delegation_key(key_start_time, key_expiry_time, **kwargs)
Parameters
- key_start_time
- datetime.datetime
A DateTime value. Indicates when the key becomes valid.
- key_expiry_time
- datetime.datetime
A DateTime value. Indicates when the key stops being valid.
Returns
The user delegation key.
Return type
Examples
Get user delegation key from datalake service client.
from datetime import datetime, timedelta
user_delegation_key = await datalake_service_client.get_user_delegation_key(datetime.utcnow(),
datetime.utcnow() + timedelta(hours=1))
list_file_systems
Returns a generator to list the file systems under the specified account.
The generator will lazily follow the continuation tokens returned by the service and stop when all file systems have been returned.
list_file_systems(name_starts_with=None, include_metadata=None, **kwargs)
Parameters
- name_starts_with
- str
Filters the results to return only file systems whose names begin with the specified prefix.
- include_metadata
- bool
Specifies that file system metadata be returned in the response. The default value is False.
Returns
An iterable (auto-paging) of FileSystemProperties.
Return type
Examples
Listing the file systems in the datalake service.
file_systems = datalake_service_client.list_file_systems()
async for file_system in file_systems:
print(file_system.name)