A powerful tool for analyzing Python code complexity, quality, and maintainability
Project description
Python Code Quality Analyzer
A powerful tool for analyzing Python code complexity, quality, and maintainability. Get insights into your codebase with detailed metrics and actionable recommendations for improvement.
Features
- ๐ Complexity Analysis: Calculate cyclomatic complexity for functions and files
- ๐ฏ Quality Metrics: Measure maintainability index and identify problematic areas
- ๐ Detailed Reports: Get comprehensive reports in console, JSON, or CSV format
- โก Fast & Efficient: Analyze large codebases quickly with minimal overhead
- ๐จ Beautiful Output: Rich console output with tables and color-coding
- โ๏ธ Configurable: Customize analysis with exclude patterns and complexity thresholds
- ๐ Actionable Insights: Clear recommendations for code improvement
Installation
pip install python-code-quality-analyzer
Quick Start
Basic usage:
python-code-quality-analyzer analyze .
Examples
Verbose output:
python-code-quality-analyzer analyze . --verbose
Set minimum complexity threshold:
python-code-quality-analyzer analyze . --min-complexity 10
Output to JSON:
python-code-quality-analyzer analyze . --format json > analysis.json
Usage
The basic command structure is:
python-code-quality-analyzer analyze /path/to/your/project
Options
--verbose,-v: Show detailed output--format,-f: Output format (text, json, csv)--min-complexity,-m: Minimum complexity threshold--exclude,-e: Exclude patterns (glob)--config,-c: Path to config file
Examples
# Verbose output
python-code-quality-analyzer analyze . --verbose
# Export to CSV
python-code-quality-analyzer analyze . --format csv > analysis.csv
# Set complexity threshold
python-code-quality-analyzer analyze . --min-complexity 10
# Exclude patterns
python-code-quality-analyzer analyze . --exclude "**/tests/*" --exclude "**/vendor/*"
# Use custom config
python-code-quality-analyzer analyze . --config myconfig.yaml
Configuration
The analyzer can be configured using a YAML configuration file. Create a file named .python-code-quality-analyzer.yaml in your project root:
# Complexity thresholds
complexity:
max: 10
warning: 7
# Output format
format: text
# Exclude patterns
exclude:
- "**/tests/*"
- "**/vendor/*"
- "**/__pycache__/*"
# Analysis options
analyze:
maintainability: true
halstead: true
cyclomatic: true
Output Example
Project Overview
โโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโ
โ Metric โ Value โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Total Files โ 25 โ
โ Total Functions โ 150 โ
โ Average Complexity โ 3.45 โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Code Quality
โโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโ
โ Metric โ Value โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Average MI โ 65.42 โ
โ Total Complexity โ 517 โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโ
Action Items
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โข High Priority: โ
โ - Refactor cli.py (complexity: 202, MI: 0.0) โ
โ - Split performance.py into smaller modules โ
โ โ
โ โข Medium Priority: โ
โ - Improve maintainability of history.py โ
โ - Break down complex functions in ai.py โ
โ โ
โ โข Consider: โ
โ - Reducing dependencies in network.py โ
โ - Adding documentation to low MI files โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
JSON Output Structure
The JSON output provides detailed metrics for programmatic analysis:
{
"summary": {
"total_files": 25,
"total_functions": 150,
"average_complexity": 3.45,
"average_maintainability": 65.42
},
"complex_files": [...],
"low_maintainability_files": [...],
"recommendations": [...],
"detailed_metrics": {
"file.py": {
"complexity": 10,
"maintainability": 65.4,
"dependencies": [...],
"functions": 5
}
}
}
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
-
Clone the repository:
git clone https://github.com/kareemaly/python-code-quality-analyzer.git cd python-code-quality-analyzer
-
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install development dependencies:
pip install -e .[dev]
-
Run tests:
pytest
Release Process
Releases are managed through GitHub Actions. To create a new release:
- Go to the Actions tab in the repository
- Select the "Release" workflow
- Click "Run workflow"
- Choose the version bump type (patch, minor, or major)
- Enter the release notes
- Click "Run workflow"
The workflow will:
- Update version numbers
- Run tests
- Build the package
- Publish to PyPI
- Create a GitHub release
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_code_quality_analyzer-3.0.8.tar.gz.
File metadata
- Download URL: python_code_quality_analyzer-3.0.8.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4aa08b971e8ffe96ec5454a69a4c66973de8efe831a37a010fc7c63604a144ca
|
|
| MD5 |
a041c161ccf430657caf4cfd6e569b5f
|
|
| BLAKE2b-256 |
cf5fe9d2751e981464b304257647ed006d785d6a684f96fd17fda21788a43d24
|
File details
Details for the file python_code_quality_analyzer-3.0.8-py3-none-any.whl.
File metadata
- Download URL: python_code_quality_analyzer-3.0.8-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6bd221d0765b79c8cec5272c3c43764cb76c9ed2221dd95202f170b3fa6f6fb
|
|
| MD5 |
51851390cedd667f93c9d7bd00fdbaf9
|
|
| BLAKE2b-256 |
a01f9d9a0fca90720a5b10a0daa8b04305aeca5fc9dc30074e0cd7c93666c376
|