Skip to main content

deletion-policy-tool

Warning: This tool is intentionally built for developers and system administrators who understand that it follows the classic Linux philosophy: "If you want to shoot yourself in the foot, it is this tool's job to do that as efficiently as possible." Use it only with carefully reviewed policies, backups, and explicit operational intent.

This project comes with no warranty. See the LICENSE file for the legal text and warranty disclaimer.

This project provides a small command-line tool for cleaning up files according to configurable deletion policies.

What it does

The tool scans one or more folders for files that match a policy, deletes them when they are old enough, and only removes them when any extra safety conditions are satisfied.

Each policy can require that a file:

  • is older than a specified number of days,
  • has the expected file extension,
  • has a backup copy in a designated backup folder, and/or
  • has a related copy with a different suffix in the same folder.

This makes it useful for retention workflows where files should be removed only after they have been preserved elsewhere.

How it works

The CLI reads a YAML configuration file from the environment variable DELETION_POLICY_CONFIG_FILE.

Each entry in the YAML file is a policy with the following fields:

  • folder: the directory to scan recursively
  • age: minimum age in days before a file may be deleted
  • extension: optional file extension to match (for example .txt)
  • delete_if_backed_up_to: optional backup folder that must contain the same relative path
  • delete_if_copy_exists: optional pair of extensions such as ['.txt', '.new_suffix'] meaning a file with the first extension must have a sibling with the second extension before deletion

Files are processed recursively under the configured folder. Only regular files are considered.

Example configuration

- folder: /path/to/source
  age: 30
  extension: .txt
  delete_if_backed_up_to: /path/to/backup

# deletes .log files if .bak file with same name exists next to it
- folder: /path/to/source
  age: 14
  extension: .log
  delete_if_copy_exists: [.log, .bak]

Installation

pipx

pipx install deletion_policy_tool
python -m pip install deletion_policy_tool

uv

uv tool install deletion_policy_tool

from source

git clone https://github.com/mshafer1/deletion_policy_tool.git
cd deletion_policy_tool
poetry install

Usage

Set the configuration path and run the CLI:

export DELETION_POLICY_CONFIG_FILE=/path/to/deletion_policy.yml
run-deletion-policy
# use default policy (in ~/.config/deletion_policy.yml)
# also remove directories that are empty after files are deleted
run-deletion-policy --remove-empty-folders
# preview deletions without removing anything
run-deletion-policy --dry-run
# ask for confirmation before deleting each matching file or folder
run-deletion-policy --confirm-each-delete
# see all options
run-deletion-policy --help

Optional flags

  • --dry-run: logs the files and folders that would be deleted without making any changes.
  • --confirm-each-delete: prompts the user before each deletion so you can review the action individually.
  • --remove-empty-folders: removes directories that are empty after file deletions.
  • -v: increases log verbosity. The default logging level is INFO; repeating -v raises the level to DEBUG so more detail is shown while policies are evaluated.

Logging behavior

The CLI sets up logging as soon as it starts. Messages are emitted to the console and also written to a rotating log file at ~/logs/deletion_policy_tool.log.

  • Console logging follows the configured verbosity level.
  • The default level is INFO.
  • Each additional -v flag increases logging detail until DEBUG is reached.
  • The file log uses a rotating handler with a 10 MiB limit and keeps the last 5 log files.

This makes it easier to troubleshoot policy matching and file-skipping decisions while still keeping a persistent history of runs.

If you are using the package entry point installed by Poetry, the command can also be run as:

poetry run deletion-policy-tool

Notes

  • The tool deletes files only after all applicable conditions pass.
  • If a policy specifies a backup location, the backup file must exist at the same relative path under that backup folder.
  • If a policy specifies a copy relationship, the corresponding file with the destination extension must exist.
  • The tool is intentionally conservative: files are skipped unless the policy requirements are met.

Metadata

Release files for deletion-policy-tool 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deletion-policy-tool 0.1.3
File Size Uploaded Provenance Actions
deletion_policy_tool-0.1.3.tar.gz 6.6 kB With provenance Details for deletion_policy_tool-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deletion-policy-tool 0.1.3
File Interpreter ABI Platform Actions
deletion_policy_tool-0.1.3-py3-none-any.whl Python 3 none any Details for deletion_policy_tool-0.1.3-py3-none-any.whl

Total release size: 14.5 kB

Release files / deletion_policy_tool-0.1.3.tar.gz

Download URL deletion_policy_tool-0.1.3.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5afc91c9d2d9caa51545d79f7c7c37069bbfc81352905f2996eda849d6c252ed
BLAKE2b-256 checksum
How to use checksums
cc70842490db6e410cfe0d50d6e0b32c9fc92a1977edc8215df879569eecbd86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.

Transparency log

Release files / deletion_policy_tool-0.1.3-py3-none-any.whl

Download URL deletion_policy_tool-0.1.3-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d575b2a6d36b5e8b4aefea20218617f6165b324dbeabc9128df516e52412285
BLAKE2b-256 checksum
How to use checksums
05602c8ef3977909bcc36aa87307396ab1aac5e79deed24f759bed9cc44e42ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.

Transparency log

Security for deletion-policy-tool 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for deletion_policy_tool-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page