A Python library for code analysis and refactoring.
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.
- 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
- Extract constants, simplify conditionals, reduce parameters
- Add docstrings, extract methods
- Preview changes before applying
- Risk scoring for each refactoring
- 14 automated fixers for common issues
- Configurable safety levels
- Automatic backups and rollback support
pip install refactronfrom 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()# 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 --applyStable 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
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 WindowsReport security issues to security@refactron.dev See SECURITY.md for details.
MIT License - see LICENSE for details.