Find syntactically equivalent Python code fragments by hashing normalized AST subtrees. This means it can spot duplicates even when variable names or literals change, rather than just matching identical lines of text.
lesspython /path/to/project --min-lines 5Normalize literals to ignore constant differences:
lesspython /path/to/project --min-lines 5 --normalize-literalsExclude paths (repeatable):
lesspython /path/to/project -e .venv -e build -e testsAdd # lesspython: ignore on its own line at the top level inside a block to exclude that block
from duplication detection. For example, to skip a function:
def noisy():
# lesspython: ignore
...For nested blocks (e.g., an if inside a function), only the statements within that if
block are ignored. The enclosing function can still be reported as duplicate if other
parts match.
The CLI prints YAML with these top-level keys:
python_files: number of Python files scannederrors: parse/encoding errorsgroups: duplicate fragment groups with occurrences and spans
Install:
pip install -e .[dev]Run tests:
python -m unittest discover -s tests