DataLakeFileClient class
Definition
A client to interact with the DataLake file, even if the file may not yet exist.
DataLakeFileClient(account_url, file_system_name, file_path, credential=None, **kwargs)
- Inheritance
-
azure.storage.filedatalake._shared.base_client_async.AsyncStorageAccountHostsMixinazure.storage.filedatalake.aio._path_client_async.PathClientDataLakeFileClientazure.storage.filedatalake._path_client.PathClientazure.storage.filedatalake._data_lake_file_client.DataLakeFileClientDataLakeFileClient
Parameters
- account_url
- str
The URI to the storage account.
- file_system_name
- str
The file system for the directory or files.
- file_path
- str
The whole file path, so that to interact with a specific file. eg. "{directory}/{subdirectory}/{file}"
- 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 DataLakeFileClient
DataLakeFileClient.from_connection_string(connection_string, "myfilesystem", "mydirectory", "myfile")
Variables
- url
- str
- primary_endpoint
- str
- primary_hostname
- str
Methods
| append_data |
Append data to the file. |
| create_file |
Create a new file. |
| delete_file |
Marks the specified file for deletion. |
| download_file |
Downloads a file to the StorageStreamDownloader. The readall() method must be used to read all the content, or readinto() must be used to download the file into a stream. |
| flush_data |
Commit the previous appended data. |
| get_file_properties |
Returns all user-defined metadata, standard HTTP properties, and system properties for the file. It does not return the content of the file. |
| rename_file |
Rename the source file. |
| upload_data |
Upload data to a file. |
append_data
Append data to the file.
append_data(data, offset, length=None, **kwargs)
Parameters
- data
Content to be appended to file
- offset
start position of the data to be appended to.
- length
Size of the data in bytes.
Returns
dict of the response header
Examples
Append data to the file.
await file_client.append_data(data=file_content[2048:3072], offset=2048, length=1024)
create_file
Create a new file.
create_file(content_settings=None, metadata=None, **kwargs)
Parameters
- content_settings
- ContentSettings
ContentSettings object used to set path properties.
- metadata
- dict(str, str)
Name-value pairs associated with the file as metadata.
Returns
response dict (Etag and last modified).
Examples
Create file.
file_client = filesystem_client.get_file_client(file_name)
await file_client.create_file()
delete_file
Marks the specified file for deletion.
delete_file(**kwargs)
Returns
None
Examples
Delete file.
await new_client.delete_file()
download_file
Downloads a file to the StorageStreamDownloader. The readall() method must be used to read all the content, or readinto() must be used to download the file into a stream.
download_file(offset=None, length=None, **kwargs)
Parameters
- offset
- int
Start of byte range to use for downloading a section of the file. Must be set if length is provided.
- length
- int
Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
Returns
A streaming object (StorageStreamDownloader)
Return type
Examples
Return the downloaded data.
download = await file_client.download_file()
downloaded_bytes = await download.readall()
flush_data
Commit the previous appended data.
flush_data(offset, retain_uncommitted_data=False, **kwargs)
Parameters
- offset
offset is equal to the length of the file after commit the previous appended data.
- retain_uncommitted_data
- bool
Valid only for flush operations. If "true", uncommitted data is retained after the flush operation completes; otherwise, the uncommitted data is deleted after the flush operation. The default is false. Data at offsets less than the specified position are written to the file when flush succeeds, but this optional parameter allows data after the flush position to be retained for a future flush operation.
Returns
response header in dict
Examples
Commit the previous appended data.
file_client = file_system_client.get_file_client("myfile")
await file_client.create_file()
with open(SOURCE_FILE, "rb") as data:
length = data.tell()
await file_client.append_data(data, 0)
await file_client.flush_data(length)
get_file_properties
Returns all user-defined metadata, standard HTTP properties, and system properties for the file. It does not return the content of the file.
get_file_properties(**kwargs)
Return type
Examples
Getting the properties for a file.
properties = await file_client.get_file_properties()
rename_file
Rename the source file.
rename_file(new_name, **kwargs)
Parameters
- new_name
- str
the new file name the user want to rename to. The value must have the following format: "{filesystem}/{directory}/{subdirectory}/{file}".
Returns
the renamed file client
Return type
Examples
Rename the source file.
new_client = await file_client.rename_file(file_client.file_system_name + '/' + 'newname')
upload_data
Upload data to a file.
upload_data(data, length=None, overwrite=False, **kwargs)
Parameters
- data
Content to be uploaded to file
- length
- int
Size of the data in bytes.
- overwrite
- bool
to overwrite an existing file or not.
Returns
response dict (Etag and last modified).