# 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
```bash
pip install python-code-quality-analyzer
```
## Quick Start
Basic usage:
```bash
python-code-quality-analyzer analyze .
```
## Examples
Verbose output:
```bash
python-code-quality-analyzer analyze . --verbose
```
Set minimum complexity threshold:
```bash
python-code-quality-analyzer analyze . --min-complexity 10
```
Output to JSON:
```bash
python-code-quality-analyzer analyze . --format json > analysis.json
```
## Usage
The basic command structure is:
```bash
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
```bash
# 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:
```yaml
# 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:
```json
{
"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
1. Clone the repository:
```bash
git clone https://github.com/kareemaly/python-code-quality-analyzer.git
cd python-code-quality-analyzer
```
2. Create and activate a virtual environment:
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
3. Install development dependencies:
```bash
pip install -e .[dev]
```
4. Run tests:
```bash
pytest
```
### Release Process
Releases are managed through GitHub Actions. To create a new release:
1. Go to the Actions tab in the repository
2. Select the "Release" workflow
3. Click "Run workflow"
4. Choose the version bump type (patch, minor, or major)
5. Enter the release notes
6. 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](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "python-code-quality-analyzer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "code analysis, complexity, maintainability, metrics, quality, static analysis",
"author": null,
"author_email": "Kareem Elbahrawy <kareemelbahrawy@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/cf/5f/e9d2751e981464b304257647ed006d785d6a684f96fd17fda21788a43d24/python_code_quality_analyzer-3.0.8.tar.gz",
"platform": null,
"description": "# Python Code Quality Analyzer\n\nA powerful tool for analyzing Python code complexity, quality, and maintainability. Get insights into your codebase with detailed metrics and actionable recommendations for improvement.\n\n## Features\n\n- \ud83d\udcca **Complexity Analysis**: Calculate cyclomatic complexity for functions and files\n- \ud83c\udfaf **Quality Metrics**: Measure maintainability index and identify problematic areas\n- \ud83d\udd0d **Detailed Reports**: Get comprehensive reports in console, JSON, or CSV format\n- \u26a1 **Fast & Efficient**: Analyze large codebases quickly with minimal overhead\n- \ud83c\udfa8 **Beautiful Output**: Rich console output with tables and color-coding\n- \u2699\ufe0f **Configurable**: Customize analysis with exclude patterns and complexity thresholds\n- \ud83d\udccb **Actionable Insights**: Clear recommendations for code improvement\n\n## Installation\n\n```bash\npip install python-code-quality-analyzer\n```\n\n## Quick Start\n\nBasic usage:\n\n```bash\npython-code-quality-analyzer analyze .\n```\n\n## Examples\n\nVerbose output:\n```bash\npython-code-quality-analyzer analyze . --verbose\n```\n\nSet minimum complexity threshold:\n```bash\npython-code-quality-analyzer analyze . --min-complexity 10\n```\n\nOutput to JSON:\n```bash\npython-code-quality-analyzer analyze . --format json > analysis.json\n```\n\n## Usage\n\nThe basic command structure is:\n\n```bash\npython-code-quality-analyzer analyze /path/to/your/project\n```\n\n### Options\n\n- `--verbose`, `-v`: Show detailed output\n- `--format`, `-f`: Output format (text, json, csv)\n- `--min-complexity`, `-m`: Minimum complexity threshold\n- `--exclude`, `-e`: Exclude patterns (glob)\n- `--config`, `-c`: Path to config file\n\n### Examples\n\n```bash\n# Verbose output\npython-code-quality-analyzer analyze . --verbose\n\n# Export to CSV\npython-code-quality-analyzer analyze . --format csv > analysis.csv\n\n# Set complexity threshold\npython-code-quality-analyzer analyze . --min-complexity 10\n\n# Exclude patterns\npython-code-quality-analyzer analyze . --exclude \"**/tests/*\" --exclude \"**/vendor/*\"\n\n# Use custom config\npython-code-quality-analyzer analyze . --config myconfig.yaml\n```\n\n## Configuration\n\nThe analyzer can be configured using a YAML configuration file. Create a file named `.python-code-quality-analyzer.yaml` in your project root:\n\n```yaml\n# Complexity thresholds\ncomplexity:\n max: 10\n warning: 7\n\n# Output format\nformat: text\n\n# Exclude patterns\nexclude:\n - \"**/tests/*\"\n - \"**/vendor/*\"\n - \"**/__pycache__/*\"\n\n# Analysis options\nanalyze:\n maintainability: true\n halstead: true\n cyclomatic: true\n```\n\n## Output Example\n\n```\n Project Overview \n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503 Metric \u2503 Value \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 Total Files \u2502 25 \u2502\n\u2502 Total Functions \u2502 150 \u2502\n\u2502 Average Complexity \u2502 3.45 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n Code Quality \n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503 Metric \u2503 Value \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 Average MI \u2502 65.42 \u2502\n\u2502 Total Complexity \u2502 517 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n Action Items\n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503 \u2022 High Priority: \u2503\n\u2503 - Refactor cli.py (complexity: 202, MI: 0.0) \u2503\n\u2503 - Split performance.py into smaller modules \u2503\n\u2503 \u2503\n\u2503 \u2022 Medium Priority: \u2503\n\u2503 - Improve maintainability of history.py \u2503\n\u2503 - Break down complex functions in ai.py \u2503\n\u2503 \u2503\n\u2503 \u2022 Consider: \u2503\n\u2503 - Reducing dependencies in network.py \u2503\n\u2503 - Adding documentation to low MI files \u2503\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n## JSON Output Structure\n\nThe JSON output provides detailed metrics for programmatic analysis:\n\n```json\n{\n \"summary\": {\n \"total_files\": 25,\n \"total_functions\": 150,\n \"average_complexity\": 3.45,\n \"average_maintainability\": 65.42\n },\n \"complex_files\": [...],\n \"low_maintainability_files\": [...],\n \"recommendations\": [...],\n \"detailed_metrics\": {\n \"file.py\": {\n \"complexity\": 10,\n \"maintainability\": 65.4,\n \"dependencies\": [...],\n \"functions\": 5\n }\n }\n}\n```\n\n## Contributing\n\nContributions 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.\n\n### Development Setup\n\n1. Clone the repository:\n ```bash\n git clone https://github.com/kareemaly/python-code-quality-analyzer.git\n cd python-code-quality-analyzer\n ```\n\n2. Create and activate a virtual environment:\n ```bash\n python -m venv .venv\n source .venv/bin/activate # On Windows: .venv\\Scripts\\activate\n ```\n\n3. Install development dependencies:\n ```bash\n pip install -e .[dev]\n ```\n\n4. Run tests:\n ```bash\n pytest\n ```\n\n### Release Process\n\nReleases are managed through GitHub Actions. To create a new release:\n\n1. Go to the Actions tab in the repository\n2. Select the \"Release\" workflow\n3. Click \"Run workflow\"\n4. Choose the version bump type (patch, minor, or major)\n5. Enter the release notes\n6. Click \"Run workflow\"\n\nThe workflow will:\n- Update version numbers\n- Run tests\n- Build the package\n- Publish to PyPI\n- Create a GitHub release\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. ",
"bugtrack_url": null,
"license": "MIT",
"summary": "A powerful tool for analyzing Python code complexity, quality, and maintainability",
"version": "3.0.8",
"project_urls": {
"Bug Tracker": "https://github.com/kareemaly/python-code-quality-analyzer/issues",
"Documentation": "https://github.com/kareemaly/python-code-quality-analyzer#readme",
"Homepage": "https://github.com/kareemaly/python-code-quality-analyzer",
"Repository": "https://github.com/kareemaly/python-code-quality-analyzer"
},
"split_keywords": [
"code analysis",
" complexity",
" maintainability",
" metrics",
" quality",
" static analysis"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a01f9d9a0fca90720a5b10a0daa8b04305aeca5fc9dc30074e0cd7c93666c376",
"md5": "51851390cedd667f93c9d7bd00fdbaf9",
"sha256": "a6bd221d0765b79c8cec5272c3c43764cb76c9ed2221dd95202f170b3fa6f6fb"
},
"downloads": -1,
"filename": "python_code_quality_analyzer-3.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "51851390cedd667f93c9d7bd00fdbaf9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5506,
"upload_time": "2025-02-01T01:50:22",
"upload_time_iso_8601": "2025-02-01T01:50:22.025134Z",
"url": "https://files.pythonhosted.org/packages/a0/1f/9d9a0fca90720a5b10a0daa8b04305aeca5fc9dc30074e0cd7c93666c376/python_code_quality_analyzer-3.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "cf5fe9d2751e981464b304257647ed006d785d6a684f96fd17fda21788a43d24",
"md5": "a041c161ccf430657caf4cfd6e569b5f",
"sha256": "4aa08b971e8ffe96ec5454a69a4c66973de8efe831a37a010fc7c63604a144ca"
},
"downloads": -1,
"filename": "python_code_quality_analyzer-3.0.8.tar.gz",
"has_sig": false,
"md5_digest": "a041c161ccf430657caf4cfd6e569b5f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 4701,
"upload_time": "2025-02-01T01:50:23",
"upload_time_iso_8601": "2025-02-01T01:50:23.722024Z",
"url": "https://files.pythonhosted.org/packages/cf/5f/e9d2751e981464b304257647ed006d785d6a684f96fd17fda21788a43d24/python_code_quality_analyzer-3.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-01 01:50:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kareemaly",
"github_project": "python-code-quality-analyzer",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "click",
"specs": [
[
">=",
"8.1.7"
]
]
},
{
"name": "rich",
"specs": [
[
">=",
"13.7.0"
]
]
},
{
"name": "radon",
"specs": [
[
">=",
"6.0.1"
]
]
},
{
"name": "pathlib",
"specs": [
[
">=",
"1.0.1"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
">=",
"4.9.0"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"8.0.0"
]
]
},
{
"name": "pytest-cov",
"specs": [
[
">=",
"4.1.0"
]
]
},
{
"name": "pytest-mock",
"specs": [
[
">=",
"3.12.0"
]
]
},
{
"name": "pyyaml",
"specs": [
[
">=",
"6.0.1"
]
]
}
],
"lcname": "python-code-quality-analyzer"
}