Skip to main content

High-performance dead code elimination analysis tool for Python.

Project description

CytoScnPy - High-Performance Python Static Analysis 🦀🐍

CI License Version

A lightning-fast static analysis tool for Python codebases, powered by Rust with hybrid Python integration. Detects dead code, security vulnerabilities (including taint analysis), and code quality issues with extreme speed. Code quality metrics are also provided.

🚀 Why CytoScnPy?

  • 🔥 Blazing Fast: Faster in dead code detection.
  • 💾 Memory Efficient: Uses less memory.
  • 🐍 Python Native: Installable via pip, importable in Python code
  • ⚡ CLI Ready: Standalone command-line tool with rich output
  • 🔍 Comprehensive: Dead code, secrets, security, taint analysis, quality metrics
  • 🎯 Framework Aware: Understands Flask, Django, FastAPI patterns
  • 📊 Benchmarked: Continuous benchmarking with 126-item ground truth suite

📦 Installation

pip install cytoscnpy

# Or install from source
git clone https://github.com/djinn09/CytoScnPy.git
cd CytoScnPy
pip install maturin
maturin develop -m cytoscnpy/Cargo.toml

🤖 MCP Server (for AI Assistants)

To use CytoScnPy MCP Server, see the MCP Server Documentation for installation instructions.

✨ Features

  • Dead Code Detection: Unused functions, classes, imports, and variables with cross-module tracking.
  • Security Analysis: Taint analysis (SQLi, XSS), secret scanning (API keys), and dangerous code patterns (eval, exec).
  • Code Quality Metrics: Cyclomatic complexity, Halstead metrics, Maintainability Index, and raw metrics (LOC, SLOC).
  • Framework Support: Native understanding of Flask, Django, and FastAPI patterns.
  • Smart Heuristics: Handles dataclasses, __all__ exports, visitor patterns, and dynamic attributes intelligently.

🛠️ Usage

Command Line

cytoscnpy [PATHS]... [OPTIONS]

Examples:

# Dead code analysis
cytoscnpy .                                     # Analyze current directory
cytoscnpy /path/to/project --json               # JSON output for CI/CD

# Security checks (--danger includes taint analysis)
cytoscnpy . --secrets --danger --quality

# Confidence threshold (0-100)
cytoscnpy . --confidence 80

# Path filtering
cytoscnpy . --exclude-folder venv --exclude-folder build
cytoscnpy . --include-folder specific_venv      # Override defaults
cytoscnpy . --include-tests

# Jupyter notebooks
cytoscnpy . --include-ipynb --ipynb-cells

Options:

Flag Description
-c, --confidence <N> Set confidence threshold (0-100)
--secrets Scan for API keys, tokens, credentials
--danger Scan for dangerous code + taint analysis
--quality Scan for code quality issues
--json Output results as JSON
--include-tests Include test files in analysis
--exclude-folder <DIR> Exclude specific folders
--include-folder <DIR> Force include folders
--include-ipynb Include Jupyter notebooks
--ipynb-cells Report findings per notebook cell

Metric Subcommands

cytoscnpy raw .                    # Raw Metrics (LOC, SLOC, Comments)
cytoscnpy cc .                     # Cyclomatic Complexity
cytoscnpy hal .                    # Halstead Metrics
cytoscnpy mi .                     # Maintainability Index

Tip: Add --json for machine-readable output, --exclude-folder <DIR> to skip directories.

⚙️ Configuration

Create .cytoscnpy.toml or add to pyproject.toml:

[tool.cytoscnpy]
# General Settings
confidence = 60  # Minimum confidence threshold (0-100)
exclude_folders = ["venv", ".tox", "build", "node_modules", ".git"]
include_folders = ["src", "tests"]  # Optional: whitelist folders
include_tests = false

# Analysis Features
secrets = true
danger = true
quality = true

# Fail Threshold (exit code 1 if exceeded)
fail_threshold = 10.0  # Fail if >10% of code is unused
# fail_threshold = 0.0  # Zero tolerance: fail on any unused code

# Code Quality Thresholds
max_lines = 100       # Max lines per function
max_args = 5          # Max arguments per function
complexity = 10       # Max cyclomatic complexity
nesting = 4           # Max indentation depth
min_mi = 65.0         # Minimum Maintainability Index
ignore = ["R001"]     # Ignore specific rule IDs

# CI/CD Integration
fail_threshold = 5.0  # Exit with code 1 if unused code % exceeds this

# Advanced Secret Scanning
[tool.cytoscnpy.secrets_config]
entropy_enabled = true
entropy_threshold = 4.0  # Higher = more random (API keys usually > 4.0)
min_length = 16          # Min length to check for entropy
scan_comments = true     # Scan comments for secrets

# Custom Secret Patterns
[[tool.cytoscnpy.secrets_config.patterns]]
name = "Slack Token"
regex = "xox[baprs]-([0-9a-zA-Z]{10,48})"
severity = "HIGH"

Fail Threshold

Configure a fail threshold for unused code. If the percentage exceeds this threshold, the CLI exits with code 1.

  • Default: 100.0 (effectively disabled)
  • Zero Tolerance: Set to 0.0 to fail on any unused code

📊 Performance

Speed Comparison

Metric Rust (CytoScnPy)
Time 0.07s
Memory ~14MB

Accuracy (Benchmark Suite: 126 items)

Detection Type Precision Recall F1 Score
Classes 0.75 0.82 0.78
Functions 0.57 0.74 0.64
Methods 1.00 0.59 0.74
Imports 0.50 0.37 0.42
Variables 0.25 0.16 0.19
Overall 0.67 0.59 0.63

See benchmark/README.md for detailed comparison against Vulture, Flake8, Pylint, Ruff, and others.

🏗️ Architecture

See cytoscnpy/README.md for detailed architecture and technology stack information.

🧪 Testing

See CONTRIBUTING.md for testing instructions.

🤝 Contributing

See CONTRIBUTING.md for development setup and guidelines.

📝 License

Apache-2.0 License - see License file for details.

🔗 Links

📚 References

CytoScnPy's design and implementation are inspired by:

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

cytoscnpy-1.0.4-cp314-cp314-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.0.4-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.0.4-cp313-cp313-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.0.4-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.0.4-cp312-cp312-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.0.4-cp312-cp312-manylinux_2_39_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.0.4-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.0.4-cp311-cp311-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.0.4-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.0.4-cp310-cp310-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.0.4-cp39-cp39-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

Details for the file cytoscnpy-1.0.4-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 df9d33ced828378a27a7d4d0390b0a41440f58bdf1d5ff29c580043bb92339cb
MD5 a2a8775ea6f5ec30e7ad3730a556917a
BLAKE2b-256 4fea7c28d641e853e60a16418b776a26ccc3c28282f70c69b8f489407ca28237

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 850d0ce2491d62444a316638878d6842e60335734bb0db363d62a5021135b65a
MD5 f8def0a3ad8fdd4312ca8ec4efc1c763
BLAKE2b-256 9789aede82601f160a9efec7fb3c48aad0b70d93dcff42781abdacb4ab128c6a

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.0.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cytoscnpy-1.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 12dc9457da9878aaaf3788ca7bcfabdccde007e3e68e18b00d9b1e9644948fea
MD5 e2a725115069c455682fde1b376e13ed
BLAKE2b-256 5c3033fcac829faa90dbe57734f8139e1dba7be8c25f5fc3d0743aee38ada933

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8857032a054072ffb9679cbb98bf55ebb46ab6e0c5553c93ab924acfb32dc9dc
MD5 f436ced18b0b26d5d58e614180c238b3
BLAKE2b-256 80fdfa02dd938cb5eda6d50b9a0745aa997ef56bcdfc8c1ed7a194a2abd64e84

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.0.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cytoscnpy-1.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e0356f6b5ded40f2e6b5a0479ec9a9f0f72d1f977082ead5aecfd53f9da35a8a
MD5 1692aba597a0c06a44852d1baaab7ee5
BLAKE2b-256 25655db1a6af433027236b11acc3cc9daa4ba21ef8a4ea273c2cbd2adee8e849

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 79e624e25ca5c6ed2fe90e6112da72b265a1830dae7ea3995374ffb3814e2e14
MD5 e3c3ed4369300b61db867af18f882dd5
BLAKE2b-256 a28d586f11642d7f2a52cc10afd06be1600a87bb7e3e8f4932111ae069ed6ef4

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f576016a0eca2752db5985699199b8472def43365de6aff8a86b8813dcf2d1f7
MD5 70574c5efe0d36a279ad34f449766373
BLAKE2b-256 b376991ea6b80f5480242da70dc2eb2497c9bf8b839aa2e4c5b3de6c3cdaf23d

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.0.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cytoscnpy-1.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9fda83293e181e28bf52907d19b7e76d020b438686a7c142a80868291dec7f77
MD5 6046fb8a3f72a958b21599a2f969a2ba
BLAKE2b-256 35eadce07ebedfd509cfeb53e5133b92420c87ffd55edc4e8f2a3bffba83b605

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.0.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c690e0c9ce013545e247a51a8e8bcfacc06b8cfff5fbba343d25b8a19f3fdf81
MD5 3c7a8d6a332229dddb90bb6bf3ee5114
BLAKE2b-256 2d7115c201255ee4aec2b74d0e32a5b6b1e1c5da8c606fdb1add785122f4a34c

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.0.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cytoscnpy-1.0.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c142ddf3b9f243cff69a48b564a97f9c77338e9dce61be87711b81328539be57
MD5 8eef1f03b651cb84182428ec11d4c691
BLAKE2b-256 8cc914fdf550572eb045544b43fb7f030574585dd5e64bc09766f79acd6e38a3

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.0.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.0.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cytoscnpy-1.0.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f553ec42f9ad80ab975652996a61703b9b4271b5b62ecadc4ece086f6c6880ae
MD5 3d12a137179dfc682b63d17357602ead
BLAKE2b-256 3993be9a0be1d85499113d8703d5592c1c5f810db3fefde88d75a0cb522f7d0a

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