airflow.contrib.hooks.azure_fileshare_hook

Module Contents

class airflow.contrib.hooks.azure_fileshare_hook.AzureFileShareHook(wasb_conn_id='wasb_default')[source]

Bases: airflow.hooks.base_hook.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, directory_name, **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, directory_name, file_name, **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, directory_name=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

create_directory(self, share_name, directory_name, **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, share_name, directory_name, file_name, **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, share_name, directory_name, file_name, **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, share_name, directory_name, file_name, **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, share_name, directory_name, file_name, **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, share_name, directory_name, file_name, count, **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.