# File and Filesystem Tasks


Tasks for working with files and filesystems.

# Copy

class

prefect.tasks.files.operations.Copy

(source_path="", target_path="", **kwargs)[source]

Task for copying files or directories within the file system.

Args:

  • source_path (Union[str, Path], optional): the path to the source directory/file.
  • target_path (Union[str, Path], optional): the path to the target directory/file. If copying a directory: the target_path must not exists.
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.files.operations.Copy.run

(source_path="", target_path="")[source]

Task run method.

Args:

  • source_path (Union[str, Path], optional): the path to the source directory/file.
  • target_path (Union[str, Path], optional): the path to the target directory/file. If copying a directory: the target_path must not exists.
Returns:
  • Path: resulting path of the copied file / directory



# Glob

class

prefect.tasks.files.operations.Glob

(path="", pattern="*", **kwargs)[source]

This task returns the content of a given directory matching a given pattern within the file system. Args:

  • path (Union[str, Path], optional): directory path
  • pattern (str, optional): glob pattern, defaults to *
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.files.operations.Glob.run

(path="", pattern="*")[source]

Task run method.

Args:

  • path (Union[str, Path], optional): directory path to search, defaults to "" which targets the current directory
  • pattern (str, optional): glob search pattern, defaults to "*" which lists all files in the path For more details on pattern options, refer to the pathlib documentation
Returns:
  • list: content of the given path as Path objects



# Move

class

prefect.tasks.files.operations.Move

(source_path="", target_path="", **kwargs)[source]

Task for moving files or directories within the file system.

Args:

  • source_path (Union[str, Path], optional): the path to the source directory/file.
  • target_path (Union[str, Path], optional): the path to the target directory/file. Any parent directories of target_path must already exist.
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.files.operations.Move.run

(source_path="", target_path="")[source]

Task run method.

Args:

  • source_path (Union[str, Path], optional): the path to the source directory/file.
  • target_path (Union[str, Path], optional): the path to the target directory/file. Any parent directories of target_path must already exist.
Returns:
  • Path: resulting path of the moved file / directory



# Remove

class

prefect.tasks.files.operations.Remove

(path="", **kwargs)[source]

Task for removing files or directories within the file system.

Args:

  • path (Union[str, Path], optional): file or directory to be removed If deleting a directory, the directory must be empty.
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.files.operations.Remove.run

(path="")[source]

Task run method.

Args:

  • path (Union[str, Path], optional): file or directory to be removed



# Unzip

class

prefect.tasks.files.compression.Unzip

(zip_path="", extract_dir="", **kwargs)[source]

Task for unzipping data.

Args:

  • zip_path (Union[str, Path], optional): the path to the zip file
  • extract_dir (Union[str, Path], optional): directory to extract the zip file into. If not provided, the current working directory will be used. This directory must already exist.
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.files.compression.Unzip.run

(zip_path="", extract_dir="", password=None)[source]

Task run method.

Args:

  • zip_path (Union[str, Path], optional): the path to the zip file
  • extract_dir (Union[str, Path], optional): directory to extract the zip file into. If not provided, the current working directory will be used. This directory must already exist.
  • password (Union[bytes, str], optional): password for unzipping a password-protected zip file. If a str, will be utf-8 encoded.
Returns:
  • Path: path to the extracted directory.



# Zip

class

prefect.tasks.files.compression.Zip

(source_path="", zip_path="", compression_method="deflate", compression_level=None, **kwargs)[source]

Task to create a zip archive.

Args:

  • source_path (Union[str, Path, List[str], List[Path]], optional): path or paths to compress into a single zip archive.
  • zip_path (Union[str, Path], optional): path to the output archive file. Any parent directories of zip_path must already exist.
  • compression_method (str, optional): the compression method to use. Options are "deflate", "store", "bzip2", and "lzma". Defaults to "deflate".
  • compression_level (int, optional): Compression level to use, see https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile for more info. Python 3.7+ only.
  • **kwargs (dict, optional): additional keyword arguments to pass to the Task constructor.

methods:                                                                                                                                                       

prefect.tasks.files.compression.Zip.run

(source_path="", zip_path="")[source]

Task run method.

Args:

  • source_path (Union[str, Path, List[str], List[Path]], optional): path or paths to compress into a single zip archive.
  • zip_path (Union[str, Path], optional): path to the output archive file. Any parent directories of zip_path must already exist.



This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC