A comprehensive Python tool for codebase analysis and code extraction that helps you refactor large Python files and generate insightful reports about your code structure.
pip install git+ssh://git@github.com/maxcrown-britecore/codebase_services.git- Python 3.8+
- Git access to this repository
The package automatically installs:
pandas>=1.3.0- For data analysis and reportingnetworkx>=2.5- For graph analysis and visualizationpyvis>=0.3.0- For interactive HTML graph generation
# Test CLI commands
codebase-extract --help
codebase-report --help
codebase-deps --helpBreak down large Python files into well-organized, modular structures.
Key Capabilities:
- ✂️ Extract functions and classes to separate files or consolidate into target files
- 🔍 AST-based parsing for accurate code analysis
- 📦 Smart import resolution with automatic dependency management
- 🔄 Cut mode to remove entities from source after extraction
- 🐍 Python 2 compatibility imports when needed
Generate detailed analytical reports about your codebase structure and quality.
Key Capabilities:
- 📊 Structured reports using pandas DataFrames
- 📈 Code metrics including line counts, complexity, and documentation coverage
- 🔍 Multi-file analysis for entire projects
- 📋 Summary statistics for executive-level insights
- 💾 Export formats (CSV, JSON, table)
Visualize and understand code relationships across your entire codebase.
Key Capabilities:
- 🌳 Bidirectional dependency trees (upstream and downstream)
- 🎨 Interactive HTML graphs with drag-and-zoom functionality
- 📊 Multiple output formats (tree, graph, list, paths, depths)
- 🔄 Cycle detection and safe handling of circular dependencies
- 🎯 Impact analysis for refactoring planning
Each CLI tool has a detailed guide with examples, workflows, and best practices:
- 📊
codebase-reportCLI Guide - Complete guide for code analysis and quality metrics - 🔍
codebase-depsCLI Guide - Complete guide for dependency analysis and visualization - ✂️
codebase-extractCLI Guide - Complete guide for code extraction and refactoring
# Extract specific entities to separate files
codebase-extract src/models.py --entities UserModel ProductModel
# Generate project quality report
codebase-report src/ --format csv --output project_analysis.csv
# Analyze dependencies with interactive visualization
codebase-deps src/core.py DatabaseManager class --format interactiveFor advanced programmatic usage, see USAGE.md for complete Python library documentation.
from codebase_services import create_extractor, create_report_service, create_dependency_tree_service
# Extract code entities
extractor = create_extractor()
result = extractor.extract_code_entities(source_file=Path("large_file.py"))
# Generate reports
reporter = create_report_service()
df = reporter.generate_code_report(Path("my_module.py"))
# Analyze dependencies
dependency_service = create_dependency_tree_service()
tree = dependency_service.build_dependency_tree(
file_path=Path("src/models.py"),
entity_name="UserModel",
entity_type="class"
)- 🔄 Refactoring - Break down monolithic files into manageable modules
- 📊 Quality Assessment - Analyze code metrics and documentation coverage
- 🔍 Impact Analysis - Understand what will break before making changes
- 📚 Code Documentation - Generate architectural insights and dependency maps
- 🚀 Legacy Modernization - Safely extract and reorganize legacy codebases
- 🏗️ Architecture Planning - Visualize and plan code structure improvements
Built with clean architecture principles:
- Factory Pattern for service creation
- AST-based parsing for accurate code analysis
- Dependency injection for component coordination
- Modular design with clear separation of concerns
MIT License - see LICENSE file for details.