API¶
Hooks¶
Module containing various file system hooks.
-
class
airflow_fs.hooks.
FsHook
[source]¶ Base FsHook defining the FsHook interface and providing some basic functionality built on this interface.
-
copy
(src_path, dest_path, src_hook=None)[source]¶ Copies file(s) into the hooks file system.
By default, source files are assumed to be on the same file system as the destination (the hooks file system). To copy between different file systems or file systems in different locations, a source file hook can be provided using the src_hook argument.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=493, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
open
(file_path, mode='rb')[source]¶ Returns file_obj for given file path.
Parameters: - file_path (str) – Path to the file to open.
- mode (str) – Mode to open the file in.
Returns: An opened file object.
-
-
class
airflow_fs.hooks.
FtpHook
(conn_id)[source]¶ Hook for interacting with files over FTP.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=493, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
open
(file_path, mode='rb')[source]¶ Returns file_obj for given file path.
Parameters: - file_path (str) – Path to the file to open.
- mode (str) – Mode to open the file in.
Returns: An opened file object.
-
-
class
airflow_fs.hooks.
HdfsHook
(conn_id=None)[source]¶ Hook for interacting with files over HDFS.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=0.0, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
open
(file_path, mode='rb')[source]¶ Returns file_obj for given file path.
Parameters: - file_path (str) – Path to the file to open.
- mode (str) – Mode to open the file in.
Returns: An opened file object.
-
-
class
airflow_fs.hooks.
S3Hook
(conn_id=None)[source]¶ Hook for interacting with files in S3.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=493, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
open
(file_path, mode='rb')[source]¶ Returns file_obj for given file path.
Parameters: - file_path (str) – Path to the file to open.
- mode (str) – Mode to open the file in.
Returns: An opened file object.
-
-
class
airflow_fs.hooks.
SftpHook
(conn_id)[source]¶ Hook for interacting with files over SFTP.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=493, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
-
class
airflow_fs.hooks.
LocalHook
[source]¶ Hook for interacting with local files on the local file system.
-
exists
(file_path)[source]¶ Checks whether the given file path exists.
Parameters: file_path (str) – File path. Returns: True if the file exists, else False. Return type: bool
-
isdir
(path)[source]¶ Returns true if the given path points to a directory.
Parameters: path (str) – File or directory path.
-
makedirs
(dir_path, mode=493, exist_ok=True)[source]¶ Creates directory, creating intermediate directories if needed.
Parameters: - dir_path (str) – Path to the directory to create.
- mode (int) – Mode to use for directory (if created).
- exist_ok (bool) – Whether the directory is already allowed to exist. If false, an IOError is raised if the directory exists.
-
mkdir
(dir_path, mode=493, exist_ok=True)[source]¶ Creates the directory, without creating intermediate directories.
-
open
(file_path, mode='rb')[source]¶ Returns file_obj for given file path.
Parameters: - file_path (str) – Path to the file to open.
- mode (str) – Mode to open the file in.
Returns: An opened file object.
-
Operators¶
File system operators, built on the file system hook interface.
-
class
airflow_fs.operators.
CopyFileOperator
(src_path, dest_path, src_hook=None, dest_hook=None, **kwargs)[source]¶ Operator for copying files between file systems.
Parameters: - src_path (str) – File path to copy files from. Can be any valid file path or glob pattern. Note that if a glob pattern is given, dest_path is taken to be a destination directory, rather than a destination file path.
- dest_path (str) – File path top copy files to.
- src_hook (FsHook) – File system hook to copy files from.
- dest_hook (FsHook) – File system hook to copy files to.
Sensors¶
Module containing file system sensors.