OpenParable
Skip to content
← Back to skills

Check Similarity Py

Testing & Quality
check-similarity-py

Check Similarity Py is an Agent Skill for testing & quality published in the mizchi/similarity repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Detect duplicate Python code using AST-based similarity analysis. Use when working with .py files and looking for code duplication or refactoring opportunities.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/mizchi/similarity/blob/HEAD/.claude/skills/check-similarity-py/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/check-similarity-py, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Python Code Similarity Detection

What to do

Run similarity-py on the target project to detect duplicate functions and classes, then analyze results and propose refactoring.

If similarity-py is not installed:

cargo install similarity-py

Step 1: Run similarity analysis

similarity-py $ARGUMENTS

If no arguments given:

similarity-py . --threshold 0.85 --min-lines 5

Step 2: Analyze results

High-priority

  • 100% similarity: Identical functions with renamed variables -> extract shared function
  • 95-100%: Same algorithm, different names -> parameterize
  • Duplicate class methods: Same logic across classes -> extract mixin or base class

Medium-priority

  • 85-95%: Similar data processing with minor differences -> shared utility
  • Decorated variants: Same function with different decorators -> single function with configurable decoration

Acceptable

  • Short __init__ methods that set attributes
  • Property getters/setters with trivial structure

Step 3: Propose refactoring

For each high-priority pair, show before/after code.

Key Options

OptionDescription
--threshold <0-1>Similarity threshold (default: 0.85)
--min-lines <n>Skip functions shorter than n lines (default: 3)
--printShow actual code snippets
--filter-function <name>Filter by function name
--fail-on-duplicatesExit code 1 if duplicates found
--experimental-overlapEnable partial overlap detection

Common Python refactoring patterns

  • Data processing functions with different field access -> generic with key parameter
  • API endpoint handlers -> shared decorator or base handler
  • Validation methods -> schema-based (pydantic, attrs)
  • Duplicate class methods across classes -> mixin class or standalone function
  • Test setup duplication -> fixtures or shared base test class