Skip to main content

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

  1. Clone the repository:

    git clone https://github.com/kareemaly/python-code-quality-analyzer.git
    cd python-code-quality-analyzer
    
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install development dependencies:

    pip install -e .[dev]
    
  4. Run tests:

    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 file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_code_quality_analyzer-3.0.8.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_code_quality_analyzer-3.0.8-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file python_code_quality_analyzer-3.0.8.tar.gz.

File metadata

File hashes

Hashes for python_code_quality_analyzer-3.0.8.tar.gz
Algorithm Hash digest
SHA256 4aa08b971e8ffe96ec5454a69a4c66973de8efe831a37a010fc7c63604a144ca
MD5 a041c161ccf430657caf4cfd6e569b5f
BLAKE2b-256 cf5fe9d2751e981464b304257647ed006d785d6a684f96fd17fda21788a43d24

See more details on using hashes here.

File details

Details for the file python_code_quality_analyzer-3.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for python_code_quality_analyzer-3.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a6bd221d0765b79c8cec5272c3c43764cb76c9ed2221dd95202f170b3fa6f6fb
MD5 51851390cedd667f93c9d7bd00fdbaf9
BLAKE2b-256 a01f9d9a0fca90720a5b10a0daa8b04305aeca5fc9dc30074e0cd7c93666c376

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page