Skip to main content

Offline static analysis tool for Python - detects bugs, performance issues, and security vulnerabilities

Project description

codeXglitch

๐Ÿ” Offline Static Analysis for Python โ€” Find logic errors, performance issues, and security bugs without cloud services.

codeXglitch is a lightweight static analysis tool that helps beginner and experienced developers catch bugs early. It uses small, efficient pattern-based detectors and doesn't require internet or external ML services.

Features

โœจ Works Offline โ€” No cloud, no internet required

๐Ÿค– Lightweight ML Models โ€” Uses pattern-based detection, not heavy neural networks

๐Ÿ› Detects Multiple Bug Types:

  • Logic Errors (division by zero, always-true conditions, suspicious comparisons)
  • Performance Issues (nested loops, inefficient operations)
  • Security Vulnerabilities (eval/exec usage, hardcoded secrets, unsafe functions)

๐ŸŽ“ Beginner-Friendly โ€” Clear error messages with suggestions

โšก Fast Analysis โ€” Analyzes files and directories in milliseconds

Installation

pip install codexglitch

Usage

Command Line

# Analyze a single file
codeXglitch analyze myfile.py

# Analyze entire directory
codeXglitch analyze src/ --recursive

# Output as JSON
codeXglitch analyze src/ --format json

# Only show critical issues
codeXglitch analyze src/ --severity critical

Python API

from codesense import CodeAnalyzer

analyzer = CodeAnalyzer()

# Analyze a file
issues = analyzer.analyze_file("myfile.py")

# Analyze code directly
code = """
x = 10 / 0  # Division by zero
if y == True:  # Suspicious comparison
    pass
"""

issues = analyzer.analyze_code(code)

for issue in issues:
    print(issue)
    if issue.suggestion:
        print(f"  โ†’ {issue.suggestion}")

Output Examples

Text Format (Default)

myfile.py:1:8 [CRITICAL] L005: Division by zero will cause runtime error
  โ†’ Check denominator before division
myfile.py:2:4 [LOW] L001: Use 'if x:' instead of 'if x == True'
  โ†’ Use 'if x:' for clearer code

Summary:
  Critical: 1
  Low: 1

JSON Format

[
  {
    "file": "myfile.py",
    "line": 1,
    "column": 8,
    "code": "L005",
    "message": "Division by zero will cause runtime error",
    "severity": "critical",
    "rule": "division_by_zero",
    "suggestion": "Check denominator before division"
  }
]

Supported Rules

Logic Errors (L-series)

  • L001: Comparison with True (use if x: instead)
  • L002: Comparison with False (use if not x: instead)
  • L003: Condition is always True
  • L004: Condition is always False
  • L005: Division by zero

Performance Issues (P-series)

  • P001: Nested loop with append() - Consider list comprehension
  • P002: len() called in loop - Store length in variable

Security Issues (S-series)

  • S001: Use of eval() - Use ast.literal_eval() or json.loads() instead
  • S002: Use of exec() - Avoid for security reasons
  • S003: Unvalidated user input() - Validate and sanitize input
  • S004: Use of os.system() - Use subprocess.run() with shell=False
  • S005: Hardcoded secrets - Use environment variables

Miscellaneous (M-series)

  • M001: Typo detection
  • M002: Suspicious variable names

Development

Install Development Dependencies

pip install -e .
pip install -r requirements-dev.txt

Run Tests

python tests/test_analyzer.py

Run Analysis on codeXglitch Itself

codeXglitch analyze src/ --recursive

How It Works

CodeSense-AI uses Python's ast module to parse code into an Abstract Syntax Tree, then applies multiple independent analyzers:

  1. Logic Analyzer โ€” Detects illogical code patterns
  2. Performance Analyzer โ€” Finds inefficient operations
  3. Security Analyzer โ€” Identifies security anti-patterns

Each analyzer uses pattern matching and simple heuristics โ€” no heavy ML models required!

Project Structure

codesense-ai/
โ”œโ”€โ”€ src/codesense/
โ”‚   โ”œโ”€โ”€ __init__.py          # Main package
โ”‚   โ”œโ”€โ”€ analyzer.py          # Main analyzer orchestrator
โ”‚   โ”œโ”€โ”€ issue.py             # Issue representation
โ”‚   โ”œโ”€โ”€ cli.py               # Command-line interface
โ”‚   โ”œโ”€โ”€ analyzers/
โ”‚   โ”‚   โ”œโ”€โ”€ logic_analyzer.py
โ”‚   โ”‚   โ”œโ”€โ”€ performance_analyzer.py
โ”‚   โ”‚   โ””โ”€โ”€ security_analyzer.py
โ”‚   โ””โ”€โ”€ models/
โ”‚       โ””โ”€โ”€ ml_predictor.py  # Simple ML-based pattern detection
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_analyzer.py
โ””โ”€โ”€ README.md

Limitations

  • Analyzes Python code only
  • Pattern-based detection (not AI/ML cloud)
  • Best suited for beginner-to-intermediate code
  • May produce false positives/negatives

License

MIT License - see LICENSE file for details

Contributing

Contributions welcome! Feel free to:

  • Report bugs and issues
  • Suggest new detection rules
  • Improve existing analyzers
  • Add more test cases

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

codexglitch-0.1.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

codexglitch-0.1.2-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file codexglitch-0.1.2.tar.gz.

File metadata

  • Download URL: codexglitch-0.1.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for codexglitch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c4487bad5a1e1671db77b5485a182a5953520115ce7102ef2cbf681c2e07606e
MD5 e099a17966aa55a44adf70f7c0299b0c
BLAKE2b-256 bdbde4344323cc7a02a2fef17d2d7b15e821260bd1a6b6ebd156a482b4e43d2f

See more details on using hashes here.

File details

Details for the file codexglitch-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: codexglitch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for codexglitch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 035f2d9e6b30ae90ec11b4b5dda3baed253a9305610fa22dc67aa6a692070865
MD5 360192e7afe884f1978c5f606ba9a3b5
BLAKE2b-256 c8f9498eb16bb6973baa93257607da703fd9effbd61d597353f1d6393916f671

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