Skip to content

Refactron-ai/Refactron_lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Refactron

A Python library for code analysis and refactoring.

CI PyPI version Python Version License: MIT

Overview

Refactron analyzes Python code for security vulnerabilities, performance issues, code smells, and complexity problems. It provides refactoring suggestions with safety previews and supports automated code fixes.

Features

Code Analysis

  • Security scanning: SQL injection, code injection, hardcoded secrets, SSRF vulnerabilities
  • Code quality: magic numbers, long functions, excessive parameters, deep nesting
  • Complexity metrics: cyclomatic complexity, maintainability index, nested loops
  • Type hints: missing or incomplete annotations
  • Dead code detection: unused functions and unreachable code
  • Dependency analysis: circular imports, wildcard imports
  • Performance issues: N+1 queries, inefficient iterations

Refactoring

  • Extract constants, simplify conditionals, reduce parameters
  • Add docstrings, extract methods
  • Preview changes before applying
  • Risk scoring for each refactoring

Auto-Fix

  • 14 automated fixers for common issues
  • Configurable safety levels
  • Automatic backups and rollback support

Installation

pip install refactron

Usage

Python API

from refactron import Refactron

refactron = Refactron()
analysis = refactron.analyze("path/to/code.py")
print(analysis.report())

result = refactron.refactor("path/to/code.py", preview=True)
result.show_diff()

Command Line

# Analyze code
refactron analyze myproject/

# Generate report
refactron report myproject/ --format json -o report.json

# Preview refactoring suggestions
refactron refactor myfile.py --preview

# Auto-fix issues
refactron autofix myfile.py --preview
refactron autofix myfile.py --apply

Documentation

Development Status

Stable release (v1.0.1). Tested on Python 3.8-3.12.

  • 135 tests, 84% code coverage
  • 96.8% analyzer module coverage
  • Validated on 5,800+ lines of production code

Contributing

Contributions are welcome. See CONTRIBUTING.md for guidelines.

git clone https://github.com/Refactron-ai/Refactron_lib.git
cd Refactron_lib
bash setup_dev.sh  # or setup_dev.bat on Windows

Security

Report security issues to security@refactron.dev See SECURITY.md for details.

License

MIT License - see LICENSE for details.

About

The Intelligent Code Refactoring Transformer for Python

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages