Skip to main content

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 None objects
  • Division by zero
  • Missing dictionary keys
  • Unsafe file operations
  • Untested execution paths
  • SQL injection vulnerabilities
  • Dangerous use of eval() and exec()

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:

  1. Fork the repository
  2. Create a feature branch
  3. Commit changes
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyclairvoyant-1.0.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

pyclairvoyant-1.0.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

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

Hashes for pyclairvoyant-1.0.0.tar.gz
Algorithm Hash digest
SHA256 65a035b01a30daa3ce3c0add76da05876c2012bafde2b729bd88ba15da714047
MD5 b0022e9267d01382f0db709bc8e4596c
BLAKE2b-256 70ac133ff24b50cf4b4a1b8daf0dded8cd0f802c2653d75602f7110acf2ab5f8

See more details on using hashes here.

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

Hashes for pyclairvoyant-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bf454779f9c411a92475c88a5fcd1496d327255670be05ecd4f4eed632253e3
MD5 f08bb57c60ae30d8313ee4e38a00e509
BLAKE2b-256 07152fbf4095de019b9c9625aff2150bc3b5c471dd20ace28dcbc3aa6458449f

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