API Reference

freezedry.freezedry(directory_path: str | Path | PathLike, output_path: str | Path | PathLike | None = None, ignore_git: bool = False, use_gitignore: bool = False, gitignore_path: str | bytes | PathLike | None = None, extra_ignore: List[str] | None = None, regexp_ignore: List[str] | None = None, ignore_by_directory: bool = True, verbose: bool = True, zipfile_arguments: Dict[str, Any] | None = {})[source]

Create a zip file of the contents of a directory, with filtering options.

This function creates a compressed zip archive of a directory’s contents while providing various filtering options to exclude unwanted files and directories.

Parameters:
  • directory_path (Union[str, Path, os.PathLike]) – Path to the directory to compress

  • output_path (Union[str, Path, os.PathLike]) – Path where the output zip file should be created. If not provided, defaults to ‘<directory_path>/compressed_directory.zip’.

  • ignore_git (bool, default=False) – If True, ignores any files with ‘.git’ in their path.

  • use_gitignore (bool, default=False) – If True, ignores files based on .gitignore rules.

  • gitignore_path (str or os.PathLike, optional) – Path to .gitignore file. If not provided but use_gitignore=True, looks for .gitignore in directory_path.

  • extra_ignore (list of str, optional) – List of strings - files containing any of these strings will be ignored.

  • regexp_ignore (list of str, optional) – List of regular expressions - files matching any of these will be ignored.

  • ignore_by_directory (bool, default=True) – If True, ignores all files in a directory that meets ignore criteria. If False, checks each file individually.

  • verbose (bool, default=True) – If True, prints names of files as they are added to the zip.

  • zipfile_arguments (dict, optional) – Additional keyword arguments passed to zipfile.ZipFile constructor.

Returns:

Creates a zip file at the specified output_path.

Return type:

None

Raises:
  • AssertionError – If directory_path is not a directory or if gitignore file is not found when use_gitignore=True.

  • ValueError – If the input parameters are invalid

  • RuntimeError – If there are issues creating the zip file

Examples

>>> # Basic usage
>>> freezedry("my_project")
>>> # Ignore git files and use .gitignore rules
>>> freezedry("my_project", ignore_git=True, use_gitignore=True)
>>> # Custom ignore patterns
>>> freezedry("my_project", extra_ignore=["__pycache__", ".pyc"])

Supporting Functions

These are used by freezedry to help determine which files should be included or ignored. You probably never need to use these directly.

freezedry.check_ignore(path: str, ignore_git: bool = False, gitparser: object | None = None, extra_ignore: List[str] | None = None, regexp_ignore: List[str] | None = None) bool[source]

Check if a path should be ignored based on multiple filtering criteria.

Parameters:
  • path (str) – File or directory path to check.

  • ignore_git (bool, default=False) – If True, checks for git-related paths.

  • gitparser (Optional[object], default=None) – Gitignore parser object that implements a callable interface.

  • extra_ignore (Optional[List[str]], default=None) – List of strings to check against the path.

  • regexp_ignore (Optional[List[str]], default=None) – List of regular expression patterns to match against the path.

Returns:

True if any of the ignore conditions are met, False otherwise.

Return type:

bool

freezedry.match_git(path: str) bool[source]

Check if a path is a git-related file or directory.

Parameters:

path (str) – File or directory path to check.

Returns:

True if the path contains ‘.git’, False otherwise.

Return type:

bool

freezedry.match_extra(path: str, extra_ignore: List[str])[source]

Check if any strings in extra_ignore are contained in the given path.

Parameters:
  • path (str) – File or directory path to check.

  • extra_ignore (List[str]) – List of strings to check against the path.

Returns:

True if any string in extra_ignore is found in path, False otherwise.

Return type:

bool

Raises:

ValueError – If extra_ignore is not a list or contains non-string elements.

freezedry.match_regexp(path: str, regexp_ignore: List[str])[source]

Check if any regular expressions in regexp_ignore match the given path.

Parameters:
  • path (str) – File or directory path to check.

  • regexp_ignore (List[str]) – List of regular expression patterns to match against the path.

Returns:

True if any pattern in regexp_ignore matches the path, False otherwise.

Return type:

bool

Raises:

ValueError – If regexp_ignore is not a list or contains non-string elements.