Skip to main content

Advanced Code Mood Analyzer with sentiment analysis, optimization suggestions, custom model training, and comprehensive code quality assessment

Project description

Codemood

PyPI version PyPI downloads License Build

Advanced code analysis platform that combines AI sentiment analysis with comprehensive code quality assessment and custom model training.

Codemood provides multi-dimensional code analysis including mood detection, security vulnerability scanning, performance bottleneck identification, optimization suggestions, and code quality metrics. Features custom model training pipeline and automatic fallback systems. Built for developers who want actionable insights into their codebase.

Key Features

🧠 Advanced Sentiment Analysis

  • 12 feature categories: Elegant patterns, documentation, type hints, code smells
  • AST-based analysis for Python structure understanding
  • Emotional tone detection: 7 distinct emotional states from "Delighted" to "Distressed"
  • Custom model training: Train your own models with provided pipeline
  • Automatic fallback: Rule-based → Custom model → Hugging Face API

🔧 Optimization Engine

  • 6 optimization categories: Nested loops, string concatenation, linear searches
  • Specific fix suggestions: Working code examples for each issue
  • Impact assessment: High/Medium/Low priority classification
  • Performance improvements: O(n²) → O(n) optimizations

🔒 Security Analysis

  • 5 vulnerability types: SQL injection, hardcoded secrets, shell injection
  • Severity classification: Critical, High, Medium, Low
  • Line-by-line detection with remediation suggestions

📊 Comprehensive Scoring

  • Multi-layered analysis: Sentiment + Security + Performance + Quality
  • Confidence scoring with reasoning explanations
  • Weighted metrics: Balanced assessment across all dimensions

Installation

pip install codemood

Quick Start

Advanced Sentiment Analysis

from codemood import analyze_sentiment_advanced

code = '''
def fibonacci_generator(n: int):
    """Generate fibonacci sequence up to n terms."""
    a, b = 0, 1
    for _ in range(n):
        yield a
        a, b = b, a + b
'''

sentiment = analyze_sentiment_advanced(code)
print(f"Overall Score: {sentiment.overall_score:.2f}")
print(f"Emotional Tone: {sentiment.emotional_tone}")
print(f"Confidence: {sentiment.confidence:.2f}")
# Output: Score: 7.20, Tone: Delighted - This code sparks joy!

Optimization Suggestions

from codemood import get_optimization_suggestions

problematic_code = '''
result = []
for i in range(len(items)):
    for j in range(len(items)):  # Nested loops - O(n²)
        if items[i] == items[j]:
            result.append(items[i])
'''

suggestions = get_optimization_suggestions(problematic_code)
for suggestion in suggestions:
    print(f"Issue: {suggestion.issue_type}")
    print(f"Fix: {suggestion.suggested_fix}")
    print(f"Impact: {suggestion.impact}")
# Output: Issue: nested_loops, Fix: Use set operations, Impact: High

Custom Model Training

# Train your own sentiment model
cd model_training
python model_trainer.py

# Model automatically integrates with codemood
from codemood import analyze_sentiment_advanced
result = analyze_sentiment_advanced(code)  # Uses your custom model + rules

Advanced Usage

Individual Analyzers

from codemood import (
    AdvancedCodeAnalyzer,
    SecurityAnalyzer,
    PerformanceAnalyzer
)

# Specialized analysis
security = SecurityAnalyzer()
issues = security.analyze(code)

performance = PerformanceAnalyzer()
bottlenecks = performance.analyze(code)

advanced = AdvancedCodeAnalyzer()
mood_result = advanced.analyze(code)

Custom Model Configuration

from codemood import CodeMoodAnalyzer

# Use custom Hugging Face model
analyzer = CodeMoodAnalyzer(model="your-custom-model")
result = analyzer.analyze(code)

Configuration

Hugging Face Integration

Codemood works offline by default. For cloud inference:

export HF_TOKEN="your_hugging_face_token"

Language Support

  • Python: Full AST analysis with comprehensive metrics
  • Other languages: Pattern-based analysis with generic scoring

API Reference

Core Functions

  • analyze_sentiment_advanced(snippet) - Advanced sentiment with emotional tone
  • get_optimization_suggestions(snippet) - Specific code improvements
  • analyze_comprehensive(snippet, language) - Full analysis suite
  • analyze_code(snippet, model) - Basic Hugging Face sentiment
  • reset_analyzers() - Clear cached models

Analysis Results

@dataclass
class ComprehensiveAnalysis:
    mood_analysis: AdvancedMoodResult
    security_issues: List[SecurityIssue]
    performance_issues: List[PerformanceIssue]
    security_score: float
    performance_score: float
    overall_score: float
    sentiment: Dict[str, Any]
    summary: str

Use Cases

  • Code Reviews: Automated sentiment analysis with optimization suggestions
  • Developer Education: Learn from emotional feedback and specific improvements
  • Performance Optimization: Identify and fix O(n²) algorithms with examples
  • Custom Model Training: Build domain-specific code quality models
  • CI/CD Integration: Quality gates with detailed explanations
  • Security Audits: Vulnerability detection with remediation guidance
  • Technical Debt Analysis: Emotional understanding of code quality issues

Contributing

Contributions welcome! Please read our contributing guidelines and submit pull requests for improvements.

License

MIT License - see LICENSE file for details.

Roadmap

v0.3.0 - Language Expansion

  • JavaScript/TypeScript AST support
  • Java bytecode analysis
  • Go static analysis

v0.4.0 - Advanced Features

  • Machine learning-based quality prediction
  • Real-time code analysis
  • Custom rule definitions

v1.0.0 - Production Ready

  • IDE plugins (VS Code, IntelliJ)
  • Team analytics dashboard
  • Enterprise integrations
  • Performance benchmarking

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

codemood-0.2.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

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

codemood-0.2.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file codemood-0.2.0.tar.gz.

File metadata

  • Download URL: codemood-0.2.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codemood-0.2.0.tar.gz
Algorithm Hash digest
SHA256 914920f42e6621929679180f373469b8d45cd007bb2f52cc364f11d33a02f533
MD5 2be1596e87c4e538ba3b048953104f89
BLAKE2b-256 4e55db74d1aba68fa132a7fb85cbea359f05de63d2cd504305b6359837a29c38

See more details on using hashes here.

File details

Details for the file codemood-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: codemood-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codemood-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2e9e0a8d233f2e38253f5e31dfc03c34e20ffd257fac94da107ba4ef1a42ffe7
MD5 ada3666f92ddd4ab5ec9502df4b06064
BLAKE2b-256 7981cccb5f025af9e541ac83f706923d2b04da30af22665d750ebf2788e198cf

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