Predict where your Python code will crash โ before it does
Project description
๐ฎ PyClairvoyant
Find hidden failure points, estimate crash probability, and improve software reliability before deployment.
๐ Overview
PyClairvoyant is an intelligent Python code analysis framework that predicts where your application is most likely to fail.
Unlike traditional linters that simply flag code smells, PyClairvoyant combines:
- Static AST Analysis
- Runtime Execution Tracing
- Risk Scoring Models
- Crash Probability Estimation
to identify dangerous code paths and estimate the likelihood of runtime failures.
Think of it as a risk radar for Python applications.
๐ฏ Why PyClairvoyant?
Modern software systems often fail because of hidden runtime issues that pass traditional code reviews:
- Accessing
Noneobjects - Division by zero
- Missing dictionary keys
- Unsafe file operations
- Untested execution paths
- SQL injection vulnerabilities
- Dangerous use of
eval()andexec()
PyClairvoyant detects these issues and quantifies their risk level.
Instead of telling you:
"This code might be problematic"
it tells you:
"This line has a 72% probability of causing a runtime failure."
โจ Key Features
๐ Advanced Static Analysis
Scans Python source code using the Abstract Syntax Tree (AST) and identifies high-risk patterns.
Detects:
- Unsafe None access
- Division by zero
- Unsafe indexing
- Direct dictionary access
- Broad exception handling
- SQL injection risks
- File I/O misuse
- Mutable default arguments
- Dangerous recursion
- eval/exec usage
๐ Crash Probability Estimation
Each suspicious line receives a calculated crash probability based on:
- Pattern severity
- Code complexity
- Nesting depth
- Runtime coverage
- Risk multipliers
Example:
Line 42 โ 72.3% Crash Probability
๐ Dynamic Runtime Tracing
Run your application and collect execution coverage:
pyclairvoyant app.py --run
PyClairvoyant identifies:
- Executed code paths
- Untested branches
- Hidden failure zones
and adjusts risk calculations accordingly.
๐ Beautiful Reports
Generate reports in multiple formats:
Terminal Output
Color-coded risk visualization.
JSON Reports
Perfect for CI/CD pipelines.
HTML Reports
Interactive and shareable dashboards.
๐ฆ Installation
Install from PyPI:
pip install pyclairvoyant
Verify installation:
pyclairvoyant --help
โก Quick Start
Analyze a Python file:
pyclairvoyant myapp.py
Analyze and trace execution:
pyclairvoyant myapp.py --run
Generate HTML report:
pyclairvoyant myapp.py -o report.html
Generate JSON report:
pyclairvoyant myapp.py -o report.json
๐ง How It Works
Step 1 โ Parse
PyClairvoyant converts source code into an AST representation.
Python Source
โ
AST Tree
Step 2 โ Detect Risks
The engine scans for dangerous coding patterns.
AST
โ
Risk Detection Engine
โ
Findings
Step 3 โ Score Severity
Every finding receives a severity score.
Example:
| Pattern | Severity |
|---|---|
| SQL Injection | 10 |
| eval() Usage | 10 |
| None Access | 9 |
| Division by Zero | 9 |
| Unsafe Indexing | 8 |
| Broad Except | 6 |
Step 4 โ Estimate Failure Probability
Risk scores are converted into a crash probability model.
Risk Factors
+
Complexity
+
Coverage
โ
Crash Probability
๐ Supported Detection Categories
| Category | Examples |
|---|---|
| ๐ฅ None Safety | Nullable access |
| โ Arithmetic | Division by zero |
| ๐ Collections | Invalid indexing |
| ๐ Dictionaries | Missing keys |
| ๐ File I/O | Unsafe file handling |
| ๐ Network | Unprotected requests |
| ๐ฏ Exceptions | Broad exception blocks |
| ๐๏ธ SQL | String-formatted queries |
| ๐ Code Smells | eval, exec |
| ๐ Recursion | Missing termination conditions |
๐ Example
Input
user = get_user("alice")
email = user["email"]
Output
โ Line 2
Risk Category:
None Safety
Crash Probability:
72%
Suggestion:
Add a None check before accessing user.
๐ Example Workflow
# Analyze source code
pyclairvoyant app.py
# Run dynamic analysis
pyclairvoyant app.py --run
# Export HTML dashboard
pyclairvoyant app.py -o report.html
๐ฌ Use Cases
Software Development
Find hidden bugs before deployment.
DevOps
Integrate risk reports into CI/CD pipelines.
Cybersecurity
Detect unsafe code constructs.
Code Reviews
Prioritize high-risk findings.
Education
Teach defensive programming practices.
๐ Development
Clone repository:
git clone https://github.com/pyclairvoyant/pyclairvoyant.git
cd pyclairvoyant
Install development dependencies:
pip install -e ".[dev]"
Run tests:
pytest
๐ฆ Building & Publishing
Build package:
python -m build
Upload to PyPI:
twine upload dist/*
๐บ Roadmap
Planned features:
- Machine Learning Risk Models
- VSCode Extension
- GitHub Actions Integration
- Historical Risk Tracking
- Team Dashboards
- Security-Focused Rulesets
- AI-Powered Fix Suggestions
๐ค Contributing
Contributions, issues, and feature requests are welcome.
If you'd like to improve PyClairvoyant:
- Fork the repository
- Create a feature branch
- Commit changes
- Submit a pull request
๐จโ๐ป Author
Mohammad Reza Mirtaleb
MSC at Petroleum University of Technology, Abadan Faculty
AI Engineer | Machine Learning & Deep Learning Engineer | Data Scientist | NLP Expert (LLMs and VLMs) | RAG and Multi-Agent Systems Developer
Building intelligent solutions for real-world challenges.
๐ฏ Project Mission
PyClairvoyant was created with one simple goal:
Help developers identify software failures before they happen.
By combining static analysis, runtime intelligence, and probabilistic risk estimation, PyClairvoyant aims to make Python applications safer, more reliable, and easier to maintain.
๐ License
MIT License
Copyright (c) 2026 Mohammad Reza Mirtaleb
Free to use, modify, and distribute.
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 pyclairvoyant-1.0.0.tar.gz.
File metadata
- Download URL: pyclairvoyant-1.0.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65a035b01a30daa3ce3c0add76da05876c2012bafde2b729bd88ba15da714047
|
|
| MD5 |
b0022e9267d01382f0db709bc8e4596c
|
|
| BLAKE2b-256 |
70ac133ff24b50cf4b4a1b8daf0dded8cd0f802c2653d75602f7110acf2ab5f8
|
File details
Details for the file pyclairvoyant-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyclairvoyant-1.0.0-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5bf454779f9c411a92475c88a5fcd1496d327255670be05ecd4f4eed632253e3
|
|
| MD5 |
f08bb57c60ae30d8313ee4e38a00e509
|
|
| BLAKE2b-256 |
07152fbf4095de019b9c9625aff2150bc3b5c471dd20ace28dcbc3aa6458449f
|