pydry is a small Python CLI for finding exact duplicate functions and structurally similar functions in Python code.
- Finds exact duplicate functions using AST normalization.
- Ranks near matches by structural similarity and refactorability.
- Flags likely abstraction candidates and common risk signals.
- Emits text output for quick inspection and JSON output for automation.
- Runs without third-party runtime dependencies.
python -m pip install pydry-cliFor local development from a checkout:
make venv
source venv/bin/activate
make install
make checkRun a compact summary for the current directory:
pydry showcaseFind exact duplicates:
pydry exact ./src --normalize-local-names --normalize-constantsFind near matches:
pydry near ./src --threshold 0.85 --top-k 25Write a full JSON report:
pydry report ./src --output reports/pydry-report.jsonFind exact duplicate functions after AST normalization.
pydry exact ./src
pydry exact ./src --min-count 3
pydry exact ./src --normalize-local-names --normalize-constants
pydry exact ./src --format jsonUseful options:
--min-count: minimum group size, default2.--top-level-only: ignore nested functions and methods.--normalize-local-names: treat local variable renames as equivalent.--normalize-constants: treat many literal value changes as equivalent.--include-canonical: include canonical AST dumps in JSON output.--strict: fail on files that cannot be read or parsed.
Rank structurally similar function pairs.
pydry near ./src
pydry near ./src --threshold 0.85 --top-k 25
pydry near ./src --format json --output reports/near.jsonUseful options:
--threshold: similarity threshold from0to1, default0.8.--top-k: cap the number of returned pairs.--top-level-only: ignore nested functions and methods.--strict: fail on files that cannot be read or parsed.
Filter near matches to pairs that look like plausible refactor candidates.
pydry abstract ./src
pydry abstract ./src --threshold 0.86 --format jsonGenerate one JSON document with exact, near, and abstract sections.
pydry report ./src
pydry report ./src --threshold 0.82 --top-k 250 --output reports/pydry-report.jsonRun a compact terminal summary. Both commands use the same analysis pipeline. With no path, they scan the current directory.
pydry showcase
pydry showcase ./src --top-k 10 --threshold 0.8
pydry showcase ./src --format json
pydry simulate ./srcJSON-capable commands return an envelope:
{
"results": [],
"diagnostics": {
"scan_errors_count": 0,
"scan_error_samples": [],
"plugin_errors_count": 0,
"plugin_error_samples": []
}
}Near and abstract entries include:
similarity_scorerefactorability_scorepattern_labelsshared_structure_summarykey_differencesrisk_flagssuggested_refactor_kindevidence
The CLI is the primary interface, but the core functions are importable:
from pathlib import Path
from pydry.engine import exact_groups, near_matches
groups = exact_groups(
Path("src"),
normalize_local_names=True,
normalize_constants=True,
)
rows = near_matches(Path("src"), threshold=0.85, top_k=25)- Similarity is heuristic. It does not prove semantic equivalence.
- Cross-file import resolution is not attempted.
- Generated abstraction templates are suggestions, not executable patches.
make check
make coverage
make check-distThe package supports Python 3.11 and newer.
pydry is released under the MIT License. See LICENSE.