Bases: airflow.hooks.base.BaseHook
Interacts with Azure FileShare Storage.
Additional options passed in the ‘extra’ field of the connection will be
passed to the FileService() constructor.
- Parameters
wasb_conn_id (str) – Reference to the wasb connection.
-
get_conn
(self)[source]
Return the FileService object.
-
check_for_directory
(self, share_name: str, directory_name: str, **kwargs)[source]
Check if a directory exists on Azure File Share.
- Parameters
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
kwargs (object) – Optional keyword arguments that
FileService.exists() takes.
- Returns
True if the file exists, False otherwise.
- Return type
bool
-
check_for_file
(self, share_name: str, directory_name: str, file_name: str, **kwargs)[source]
Check if a file exists on Azure File Share.
- Parameters
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
kwargs (object) – Optional keyword arguments that
FileService.exists() takes.
- Returns
True if the file exists, False otherwise.
- Return type
bool
-
list_directories_and_files
(self, share_name: str, directory_name: Optional[str] = None, **kwargs)[source]
Return the list of directories and files stored on a Azure File Share.
- Parameters
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
kwargs (object) – Optional keyword arguments that
FileService.list_directories_and_files() takes.
- Returns
A list of files and directories
- Return type
list
-
list_files
(self, share_name: str, directory_name: Optional[str] = None, **kwargs)[source]
Return the list of files stored on a Azure File Share.
- Parameters
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
kwargs (object) – Optional keyword arguments that
FileService.list_directories_and_files() takes.
- Returns
A list of files
- Return type
list
-
create_share
(self, share_name: str, **kwargs)[source]
Create new Azure File Share.
- Parameters
-
- Returns
True if share is created, False if share already exists.
- Return type
bool
-
delete_share
(self, share_name: str, **kwargs)[source]
Delete existing Azure File Share.
- Parameters
-
- Returns
True if share is deleted, False if share does not exist.
- Return type
bool
-
create_directory
(self, share_name: str, directory_name: str, **kwargs)[source]
Create a new directory on a Azure File Share.
- Parameters
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
kwargs (object) – Optional keyword arguments that
FileService.create_directory() takes.
- Returns
A list of files and directories
- Return type
list
-
get_file
(self, file_path: str, share_name: str, directory_name: str, file_name: str, **kwargs)[source]
Download a file from Azure File Share.
- Parameters
file_path (str) – Where to store the file.
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
kwargs (object) – Optional keyword arguments that
FileService.get_file_to_path() takes.
-
get_file_to_stream
(self, stream: str, share_name: str, directory_name: str, file_name: str, **kwargs)[source]
Download a file from Azure File Share.
- Parameters
stream (file-like object) – A filehandle to store the file to.
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
kwargs (object) – Optional keyword arguments that
FileService.get_file_to_stream() takes.
-
load_file
(self, file_path: str, share_name: str, directory_name: str, file_name: str, **kwargs)[source]
Upload a file to Azure File Share.
- Parameters
file_path (str) – Path to the file to load.
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
kwargs (object) – Optional keyword arguments that
FileService.create_file_from_path() takes.
-
load_string
(self, string_data: str, share_name: str, directory_name: str, file_name: str, **kwargs)[source]
Upload a string to Azure File Share.
- Parameters
string_data (str) – String to load.
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
kwargs (object) – Optional keyword arguments that
FileService.create_file_from_text() takes.
-
load_stream
(self, stream: str, share_name: str, directory_name: str, file_name: str, count: str, **kwargs)[source]
Upload a stream to Azure File Share.
- Parameters
stream (file-like) – Opened file/stream to upload as the file content.
share_name (str) – Name of the share.
directory_name (str) – Name of the directory.
file_name (str) – Name of the file.
count (int) – Size of the stream in bytes
kwargs (object) – Optional keyword arguments that
FileService.create_file_from_stream() takes.