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.object
azure.storage.filedatalake._shared.base_client.StorageAccountHostsMixin
DataLakeServiceClient

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 import DataLakeServiceClient
   datalake_service_client = DataLakeServiceClient.from_connection_string(self.connection_string)

Creating the DataLakeServiceClient with Azure Identity credentials.


   from azure.identity import ClientSecretCredential
   token_credential = ClientSecretCredential(
       self.active_directory_tenant_id,
       self.active_directory_application_id,
       self.active_directory_application_secret,
   )
   datalake_service_client = DataLakeServiceClient("https://{}.dfs.core.windows.net".format(self.account_name),
                                                   credential=token_credential)

Variables

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.

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.

from_connection_string

Create DataLakeServiceClient from a Connection String.

:return a DataLakeServiceClient :rtype ~azure.storage.filedatalake.DataLakeServiceClient

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
Required

The name of the file system to create.

metadata
dict(str, str)
default value: None

A dict with name-value pairs to associate with the file system as metadata. Example: {'Category':'test'}

public_access
PublicAccess
default value: None

Possible values include: file system, file.

Return type

Examples

Creating a file system in the datalake service.


   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
Required

The file system to delete. This can either be the name of the file system, or an instance of FileSystemProperties.

Return type

None

Examples

Deleting a file system in the datalake service.


   datalake_service_client.delete_file_system("filesystem")

from_connection_string

Create DataLakeServiceClient from a Connection String.

:return a DataLakeServiceClient :rtype ~azure.storage.filedatalake.DataLakeServiceClient

from_connection_string(conn_str, credential=None, **kwargs)

Parameters

conn_str
str
Required

A connection string to an Azure Storage account.

credential
Required

The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, and account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

credential
default value: None

Examples

Creating the DataLakeServiceClient from a connection string.


   from azure.storage.filedatalake import DataLakeServiceClient
   datalake_service_client = DataLakeServiceClient.from_connection_string(self.connection_string)

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
Required

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
Required

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
Required

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
Required

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

azure.storage.filedatalake..DataLakeFileClient

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
Required

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 import DataLakeServiceClient
   datalake_service_client = DataLakeServiceClient.from_connection_string(self.connection_string)

   # Instantiate a FileSystemClient
   file_system_client = datalake_service_client.get_file_system_client("mynewfilesystem")

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
Required

A DateTime value. Indicates when the key becomes valid.

key_expiry_time
datetime.datetime
Required

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 = 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
default value: None

Filters the results to return only file systems whose names begin with the specified prefix.

include_metadata
bool
default value: None

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()
   for file_system in file_systems:
       print(file_system.name)