codegraph-python
Python parser plugin for CodeGraph - extracts code entities and relationships from Python source files into a queryable graph database.
Version 0.3.0 - Cyclomatic Complexity Analysis
codegraph-python v0.3.0 adds AST-based cyclomatic complexity calculation for all functions.
Complexity Metrics
Functions now include detailed complexity analysis:
use CodeParser;
use PythonParser;
let parser = new;
let ir = parser.parse_source?;
for func in &ir.functions
Grading Scale
- A (1-5): Simple, low risk
- B (6-10): Moderate complexity
- C (11-20): Complex, moderate risk
- D (21-50): Very complex, high risk
- F (51+): Untestable, very high risk
Features
- 🚀 Fast: Parse 1000 Python files in under 10 seconds
- 🎯 Accurate: Extract functions, classes, methods, decorators, type hints
- 🔗 Relationships: Track function calls, imports, inheritance hierarchies
- ⚙️ Configurable: Filter by visibility, file size, enable parallel processing
- 🛡️ Safe: No panics, graceful error handling, continues on failures
- 📊 Complete: 67 tests, 90%+ code coverage
- 🐍 Python 3.8+: Full support for async/await, decorators, type hints, match statements
What it Extracts
Entities
- Functions: Names, signatures, parameters, return types, decorators, async flag
- Classes: Names, base classes, methods, fields, decorators, abstract flag
- Methods: Instance methods, static methods, class methods, properties
- Modules: File-level metadata and documentation
Relationships
- Calls: Function and method call relationships (who calls whom)
- Imports: Module dependencies (import statements, from imports, wildcards)
- Inheritance: Class hierarchies (single and multiple inheritance)
- Implementations: Protocol/ABC implementations
Installation
Add to your Cargo.toml:
[]
= "0.1.1"
= "0.1.0"
Quick Start
Parse a Single File
use Parser;
use CodeGraph;
Parse an Entire Project
use Parser;
use CodeGraph;
Custom Configuration
use ;
use CodeGraph;
Parse from String
use Parser;
use CodeGraph;
```rust
use Parser;
use CodeGraph;
Configure Parser Behavior
use ;
let config = ParserConfig ;
let parser = with_config;
Examples
See the examples/ directory for more:
basic_parse.rs- Parse a single fileproject_stats.rs- Parse a project and show statisticscall_graph.rs- Extract function call relationshipsdependency_analysis.rs- Analyze import dependencies
Run examples with:
Performance
Performance targets (measured on modern hardware):
- Single file (<1000 lines): <10ms
- Single file (1000-10000 lines): <100ms
- Project (100 files): <1 second
- Project (1000 files): <10 seconds
- Memory usage (1000 files): <500MB
Python Support
Supports Python 3.8+ syntax including:
- ✅ Functions and async functions
- ✅ Classes with inheritance
- ✅ Decorators
- ✅ Type hints
- ✅ Match statements (Python 3.10+)
- ✅ Protocols and Abstract Base Classes
- ✅ Import statements (including wildcards)
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed under the Apache-2.0 license, without any additional terms or conditions.