AST-based duplicate and structural similarity detector for Python
Project description
pydry
pydry is a small Python CLI for finding exact duplicate functions and structurally similar functions in Python code.
Features
- 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.
Installation
python -m pip install pydry-cli
For local development from a checkout:
make venv
source venv/bin/activate
make install
make check
Quick start
Run a compact summary for the current directory:
pydry showcase
Find exact duplicates:
pydry exact ./src --normalize-local-names --normalize-constants
Find near matches:
pydry near ./src --threshold 0.85 --top-k 25
Write a full JSON report:
pydry report ./src --output reports/pydry-report.json
Commands
pydry exact
Find 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 json
Useful 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.
pydry near
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.json
Useful 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.
pydry abstract
Filter near matches to pairs that look like plausible refactor candidates.
pydry abstract ./src
pydry abstract ./src --threshold 0.86 --format json
pydry report
Generate 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.json
pydry showcase and pydry simulate
Run 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 ./src
JSON output
JSON-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
Python API
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)
Limitations
- Similarity is heuristic. It does not prove semantic equivalence.
- Cross-file import resolution is not attempted.
- Generated abstraction templates are suggestions, not executable patches.
Development
make check
make coverage
make check-dist
The package supports Python 3.11 and newer.
License
pydry is released under the MIT License. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydry_cli-0.0.3.tar.gz.
File metadata
- Download URL: pydry_cli-0.0.3.tar.gz
- Upload date:
- Size: 33.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58fbb8eecbe33c0188eccae27cf8bcc43744460877d3840faf0944c36bd87d44
|
|
| MD5 |
447cdb761966153708e66e08d8f4764b
|
|
| BLAKE2b-256 |
d45995b2729ad26ecedb133e87abc094e6e0fd4b78107c8d411b5cd5a9119a97
|
Provenance
The following attestation bundles were made for pydry_cli-0.0.3.tar.gz:
Publisher:
publish.yml on hesreallyhim/pydry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydry_cli-0.0.3.tar.gz -
Subject digest:
58fbb8eecbe33c0188eccae27cf8bcc43744460877d3840faf0944c36bd87d44 - Sigstore transparency entry: 2069341948
- Sigstore integration time:
-
Permalink:
hesreallyhim/pydry@cf4f7b249d6ef3e2826477c96fa1469b2da6f70a -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/hesreallyhim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf4f7b249d6ef3e2826477c96fa1469b2da6f70a -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydry_cli-0.0.3-py3-none-any.whl.
File metadata
- Download URL: pydry_cli-0.0.3-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f63439aeb0694d392ccc6556078f4633b524aaad40759df587085be90e920206
|
|
| MD5 |
8fba5e3407a676da4f675d3f0d78429b
|
|
| BLAKE2b-256 |
80197e8f023c4e1a624a5a31618475ba9078fb44259ae28311633004ee3e5208
|
Provenance
The following attestation bundles were made for pydry_cli-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on hesreallyhim/pydry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydry_cli-0.0.3-py3-none-any.whl -
Subject digest:
f63439aeb0694d392ccc6556078f4633b524aaad40759df587085be90e920206 - Sigstore transparency entry: 2069342411
- Sigstore integration time:
-
Permalink:
hesreallyhim/pydry@cf4f7b249d6ef3e2826477c96fa1469b2da6f70a -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/hesreallyhim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cf4f7b249d6ef3e2826477c96fa1469b2da6f70a -
Trigger Event:
push
-
Statement type: