A Python toolkit for static analysis, project understanding, and automated code insights.
Project description
ProjectIntel
ProjectIntel is a high-performance static analysis toolkit designed to transform raw source code into actionable intelligence. By leveraging Python's Abstract Syntax Trees (AST), ProjectIntel maps project structures, resolves complex dependency graphs, and builds semantic call graphs to help developers understand, maintain, and optimize large-scale Python codebases.
Overview
Modern Python projects often suffer from hidden architectural debt: circular dependencies, orphan files, and "dead" functions that are never called. ProjectIntel provides a multi-phase analysis pipeline that "scans" a directory and produces a comprehensive metadata model of the entire project.
Why use ProjectIntel?
- Architectural Clarity: Visualize how modules interact and identify tight coupling.
- Dependency Auditing: Automatically detect circular dependencies and orphan modules.
- Semantic Deep-Dive: Trace execution flows from entry points to leaf functions.
- Code Cleanup: Identify unused functions and modules with high-confidence static analysis.
- Onboarding: Quickly generate reports for new developers to understand the "critical paths" of a repository.
Features
- Recursive Project Scanning: Automatically ignores environments (
venv), caches (__pycache__), and git metadata. - Dependency Analysis:
- Local vs. External import resolution.
- Circular dependency detection (Cycle detection).
- Orphan file detection (files not imported by any other project file).
- Semantic Analysis:
- Project-wide Call Graphs: Maps function-to-function calls across different files.
- Entry Point Detection: Automatically identifies
if __name__ == "__main__":blocks. - Execution Flow: Traces the recursive path of execution from entry points.
- Function Criticality: Ranks functions based on their centrality (in-degree/out-degree) in the call graph.
- Structured Reporting: Generate summaries, dependency maps, and semantic insights directly to the terminal or via API.
Installation
ProjectIntel requires Python 3.10 or higher.
# Clone the repository
git clone https://github.com/Kishorestalin-AIML/ProjectIntel.git
cd ProjectIntel
# Install via pip
pip install .
Quick Start
Using the CLI
Analyze any Python project directory by running:
python run.py /path/to/your/project
Using the Python API
from projectintel.scanner.project_scanner import ProjectScanner
from projectintel.analyzer.dependency.dependency_builder import DependencyBuilder
from projectintel.analyzer.semantic.semantic_analyzer import SemanticAnalyzer
# 1. Scan the project structure
scanner = ProjectScanner("./my_project")
project = scanner.scan_project()
# 2. Run Dependency Analysis
DependencyBuilder(project).build()
# 3. Run Semantic Analysis (Call Graphs, etc.)
SemanticAnalyzer(project).analyze()
# 4. Access the intelligence
print(f"Total Functions: {project.total_functions}")
print(f"Detected Cycles: {project.cycles}")
for func, score in project.critical_functions[:5]:
print(f"Critical Path: {func} (Score: {score})")
Architecture
ProjectIntel operates in four distinct phases:
| Phase | Name | Responsibility |
|---|---|---|
| Phase 1 | Discovery | Recursively finds .py files; extracts classes and function names. |
| Phase 2 | Dependency | Resolves imports; builds file-level directed graphs; detects cycles. |
| Phase 3 | Semantics | Extracts function calls; builds call graphs; identifies entry points. |
| Phase 4 | Intelligence | (In Progress) Data visualization, HTML reports, and dashboard generation. |
API Reference
ProjectScanner
The entry point for scanning a directory.
__init__(root_path: str): Initializes the scanner with the project root.scan_project() -> ProjectMetadata: Executes Phase 1 analysis.- Returns: A
ProjectMetadataobject containing a list ofFileMetadata.
- Returns: A
DependencyBuilder
Constructs the module-level dependency graph.
__init__(metadata: ProjectMetadata): Requires scanned metadata.build() -> dict: Resolves all imports and populatesproject.dependency_graph.
SemanticAnalyzer
Orchestrates the Phase 3 semantic pipeline.
analyze(): Runs the following internal sub-analyzers:CallGraphBuilder: Maps function calls.EntryPointDetector: Finds script start points.CriticalFunctionAnalyzer: Scores functions by importance.UnusedFunctionDetector: Identifies potential dead code.
ProjectMetadata (Model)
The central data structure containing the project's state.
| Attribute | Type | Description |
|---|---|---|
files |
List[FileMetadata] |
Metadata for every individual file. |
dependency_graph |
Dict[str, List[str]] |
Map of file -> [dependencies]. |
call_graph |
Dict[str, List[str]] |
Map of function -> [called_functions]. |
critical_functions |
List[Tuple[str, int]] |
Functions ranked by call frequency. |
cycles |
List[List[str]] |
Lists of files forming circular imports. |
Use Cases
- Refactoring: Identify "Orphan Files" that are no longer imported and can be safely deleted.
- Onboarding: Use the "Execution Flow" to show new developers exactly what happens when the main script runs.
- Risk Management: Find "Critical Functions." If a function has a high score, a bug inside it will likely impact the entire system.
- Architecture Validation: Ensure that your
utilsmodule doesn't accidentally depend on yourmainmodule (Cycle Detection).
Code Examples & Expected Outputs
Detecting Cycles
If A.py imports B.py, and B.py imports A.py:
# Output from project.cycles
[['A.py', 'B.py', 'A.py']]
Critical Functions
Functions are scored by incoming_calls + outgoing_calls.
Critical Functions:
Auth.login Score : 8
Database.connect Score : 5
utils.hash_password Score : 3
Roadmap
- Phase 4 Visualization: Export graphs to Graphviz (DOT) and interactive HTML.
- Framework Support: Specialized entry-point detection for FastAPI, Flask, and Django.
- Type Hint Analysis: Improve call resolution using PEP 484 type hints.
- Complexity Metrics: Integration of Cyclomatic Complexity (McCabe) per function.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your Changes (
git commit -m 'Add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
License
Distributed under the MIT License. See LICENSE for more information.
Author
Kishore Stalin - GitHub Profile
Documentation generated by ProjectIntel - Understanding code, one AST at a time.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file projectintel-0.1.2.tar.gz.
File metadata
- Download URL: projectintel-0.1.2.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
370326a5664046ebd332e76fde4d0e191e423ccc989065757c98622850bb3cce
|
|
| MD5 |
20f628cf41527d14ef525bdbdb70168d
|
|
| BLAKE2b-256 |
72e9675f7d56ddd03c5fcbe7c26e1962ee800a0cb0c603ec103815ede21ef56d
|
File details
Details for the file projectintel-0.1.2-py3-none-any.whl.
File metadata
- Download URL: projectintel-0.1.2-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ef301bee8f49879df74883d9506af903c19b21e85e1495e538e54a788b65b86
|
|
| MD5 |
7221a1ed209d3c372bc11df80aa30656
|
|
| BLAKE2b-256 |
6bbc0403c1c5b283e138969050e2eff4c00ed0710e70dbd5b40812fc5cf0341c
|