About CodePulse
A Python code analysis tool built with Flask and the AST module.
What is CodePulse?
CodePulse is a static analysis tool for Python source code. It parses your code into an Abstract Syntax Tree (AST) and computes a range of quality metrics without ever executing the code.
Metrics Computed
⚙ Cyclomatic Complexity
Measures the number of linearly independent paths through your code.
Higher complexity means more test cases needed. We count branches
from if, for, while,
except, with, and/or,
assert, and comprehensions.
📊 Halstead Metrics
Quantifies code using operators and operands. We compute Volume (size of implementation), Difficulty (how hard to understand), Effort (mental effort to develop), estimated Bugs, and estimated Development Time.
📈 Maintainability Index
A composite score (0-100) based on Halstead Volume, cyclomatic
complexity, and lines of code. Uses the Microsoft variant:
MI = max(0, (171 - 5.2*ln(V) - 0.23*G - 16.2*ln(LOC)) * 100/171)
👃 Code Smell Detection
Identifies common anti-patterns: long functions (>50 lines), too many parameters (>5), deep nesting (>4 levels), high function complexity (>10), missing docstrings, unused imports, magic numbers, god classes (>15 methods), and duplicate code blocks.
Grading Scale
REST API
/api/health
Service health check
/api/analyze
Analyze Python code (JSON body: {"code": "...", "filename": "..."})
/api/analyses
List recent analyses (query: ?limit=20)
/api/analyses/<id>
Get single analysis with full details
/api/analyses/<id>
Delete an analysis record
/api/stats
Aggregate statistics and grade distribution
/api/sample
Get sample code snippet