Skip to main content

Generate, Compare and Analyse Directory Merkle Trees

Project description

dmerk

PyPI version License

dmerk (pronounced dee-merk) is a program that creates a merkle tree for your directories.

This can be useful in many situations. For example, to detect which files were modified, or to compare two backups for duplicate files. Think hash digest / checksum verification, but instead of comparing just a pair of hash digests, we are comparing two trees of digests.

Table of Contents

Installation

pip install dmerk

Usage / Quickstart

TUI (Terminal User Interface)

Launch the TUI for a more interactive experience:

dmerk tui

The TUI is built with Textual and provides a powerful interface for all dmerk functionality. It's especially useful for the compare operation, allowing you to quickly navigate and compare different submerkles at various hierarchical levels of two merkle trees, which is more cumbersome with the CLI alone.

Generate

Generate a merkle tree for a directory:

dmerk generate /path/to/directory

Options:

  • -p, --print: Print the merkle output to stdout
  • -f FILENAME, --filename FILENAME: Provide a custom filename or file path for saving
  • --fail-on-error: Immediately fail upon encountering errors (such as broken symlinks)
  • --no-save: If specified, the generated merkle tree will not be saved to file (not recommended as generating merkle trees is computationally expensive)

Compare

Compare two directory merkle trees and return the diffs and matches:

dmerk compare -p1 PATH1 -p2 PATH2 [-sp1 SUBPATH1] [-sp2 SUBPATH2]

The paths PATH1 and PATH2 are required and can be either:

  • Paths to directories to compare
  • Paths to .dmerk files created using the generate command

Options:

  • --no-save: If specified, the generated merkle trees will not be saved to file (only applies when comparing directories)

Examples:

dmerk compare -p1=/home/raghuram/Documents -p2=/media/raghuram/BACKUP_DRIVE/Documents
dmerk compare -p1=Documents_e6eaccb4.dmerk -p2=Documents_b2a7cef7.dmerk

When using .dmerk files, you can optionally provide subpaths to compare specific subdirectories:

dmerk compare \
-p1=Documents_e6eaccb4.dmerk \
-p2=Documents_b2a7cef7.dmerk \
-sp1=Receipts/Rent \
-sp2=Receipts/Rent

This is particularly useful because the compare operation performs a "shallow comparison" that only shows diffs/matches among immediate children.

Features and Limitations

Current Support

  • Primary testing on Linux; Windows and macOS support coming soon™
  • Handles regular files, directories, and symlinks to regular files/directories
  • Processes hidden files and directories
  • Uses MD5 as the digest algorithm for speed (configurable options planned)

Requirements

  • Read permission for files
  • Read and execute permissions for directories
  • File and directory names must be valid UTF-8 byte sequences
    • For support of non-UTF-8 filenames, please upvote this issue

Limitations

  • Does not support special files (character/block devices, sockets, pipes)
  • Symlinks to special files will cause exceptions
  • Directory digests are currently based only on file contents, not filenames or metadata (permissions, owner, timestamps, etc.)
    • If you need directory digests that include metadata, please open a new issue explaining your use case

Development

Contributing

If you want to report bugs, request features, or contribute improvements, please file an issue on GitHub. I appreciate your interest in this project and will respond as soon as possible 😁.

Setup

# Clone and set up the repository
git clone https://github.com/krishraghuram/dmerk.git
cd dmerk
python3 -m venv venv
source venv/bin/activate

# Install development dependencies
pip install -e .[dev]

# Verify installation
dmerk --help

Textual Development Tools

The TUI is built with Textual. You can use Textual's development tools:

# Run in dev mode with access to logs and console
textual run --dev dmerk.tui

For more information, see the Textual DevTools documentation.

Code Quality

We maintain code quality through automated checks that run as Git hooks:

  • Pre-commit: lint, format, and type checking
  • Pre-push: unit tests

You can also run these checks manually:

# Run individual checks
nox --session lint
nox --session format
nox --session mypy
nox --session test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dmerk-0.2.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmerk-0.2.0-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file dmerk-0.2.0.tar.gz.

File metadata

  • Download URL: dmerk-0.2.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dmerk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 735967cf6028bef3493640e40ee70b9086ef76e98231680c7f4bb96a7f97bef4
MD5 403787fe51afc2c2bfda29c82d558917
BLAKE2b-256 76d36471cd770ebed3c0005783674946028056e6fc20072d5ea54dd4afcd55b1

See more details on using hashes here.

File details

Details for the file dmerk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dmerk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for dmerk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b6e6ddacd1ba82056c57073e7498ca9a3ee46f96740c01aaab65303f04ecd23
MD5 957ef0c25a3355ab62b329d23498e6b2
BLAKE2b-256 cc4b876f6d65bd4205bee69bf21061f36885324b080ac4abd6062d2f419fdf25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page