Skip to main content

High-performance dead code elimination analysis tool for Python.

Project description

CytoScnPy - High-Performance Python Static Analysis

CI Coverage codecov Security Audit Docs License Version

A 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.
  • Comprehensive: Dead code, secrets, security, taint analysis, quality metrics
  • Framework Aware: Flask, Django, FastAPI, Pydantic, Azure Functions
  • Benchmarked: Continuous benchmarking with 135-item ground truth suite

Installation

Linux / macOS:

# Install
curl -fsSL https://raw.githubusercontent.com/djinn09/CytoScnPy/main/install.sh | bash

Windows (PowerShell):

# Install
irm https://raw.githubusercontent.com/djinn09/CytoScnPy/main/install.ps1 | iex

Via Pip:

pip install cytoscnpy

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)

CytoScnPy includes an MCP server for AI assistant integration:

# Start MCP server (after pip install)
cytoscnpy mcp-server

For Claude Desktop, Cursor, or GitHub Copilot configuration, see the MCP Server Documentation.

Features

  • Dead Code Detection: Unused functions, classes, imports, and variables with cross-module tracking.
    • Cascading Detection: Methods inside unused classes are automatically flagged as unused.
    • Auto-Fix: Remove dead code automatically with --fix (preview by default, use --apply to execute).
  • Clone Detection: Find duplicate code with --clones.
  • Security Analysis: Taint analysis (SQLi, XSS), secret scanning (API keys, suspicious variables), 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, FastAPI, Pydantic, and Azure Functions v2 patterns.
  • Smart Heuristics: Handles dataclasses, __all__ exports, visitor patterns, and dynamic attributes intelligently.
  • Cross-File Detection: Tracks symbol usage across the entire codebase, including nested packages and complex import chains, to ensure code used in other modules is never incorrectly flagged.

Usage

[!IMPORTANT] Behavioral Change: Starting from version 1.2.2, tests are excluded by default across both the CLI and the library API to reduce noise in production analysis. Use the --include-tests flag or set include_tests = true in your configuration to scan test files.

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 (short flags: -s, -d, -q)
cytoscnpy . --secrets --danger --quality
cytoscnpy . -s -d -q                        # Same with short flags

# 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

# Clone detection (find duplicate code)
cytoscnpy . --clones --clone-similarity 0.8

# Auto-fix dead code (preview first, then apply)
cytoscnpy . --fix                    # Preview changes (dry-run by default)
cytoscnpy . --fix --apply            # Apply changes
cytoscnpy . --fix -a                 # Apply changes (short flag)

# Generate HTML report (quality auto-enabled; add --secrets --danger for security)
cytoscnpy . --html --secrets --danger

Options:

Flag Description
-c, --confidence <N> Set confidence threshold (0-100)
--root <PATH> Project root for analysis (CI/CD mode)
-s, --secrets Scan for API keys, tokens, credentials
-d, --danger Scan for dangerous code + taint analysis
-q, --quality Scan for code quality issues
-n, --no-dead Skip dead code detection (security/quality only)
--html Generate HTML report (auto-enables quality)
--json Output results as JSON
-v, --verbose Enable verbose output for debugging
--quiet Quiet mode: summary only, no tables
--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
--clones Detect duplicate code
--clone-similarity <N> Clone similarity threshold (0.0-1.0)
--fix Preview dead code removal (dry-run by default)
-a, --apply Apply --fix changes to files

CI/CD Gate Options:

Flag Description
--fail-threshold <N> Exit code 1 if unused code % > N
--max-complexity <N> Exit code 1 if any function complexity > N
--min-mi <N> Exit code 1 if maintainability index < N
--fail-on-quality Exit code 1 if any quality issues found
--max-nesting <N> Exit code 1 if any block nesting > N
--max-args <N> Exit code 1 if any function has > N args
--max-lines <N> Exit code 1 if any function has > N lines

Full CLI Reference: See docs/CLI.md for complete command documentation.

Metric Subcommands

cytoscnpy raw .                    # Raw Metrics (LOC, SLOC, Comments)
cytoscnpy cc .                     # Cyclomatic Complexity
cytoscnpy hal .                    # Halstead Metrics
cytoscnpy mi .                     # Maintainability Index
cytoscnpy stats . --all            # Full project report (secrets, danger, quality)
cytoscnpy stats . --all -o report.md  # Save report to file
cytoscnpy files .                  # Per-file metrics table

Tip: Add --json for machine-readable output, --exclude-folder <DIR> to skip directories globally, or --ignore <PATTERN> for subcommand-specific glob filtering.

Feature Flags

The crate supports experimental features that can be enabled at compile time:

Feature Description
cfg Enables Control Flow Graph (CFG) construction and behavioral validation for clone detection

To build with a feature enabled:

cargo build --features cfg

⚙️ Configuration

Create .cytoscnpy.toml (uses [cytoscnpy]) or add to pyproject.toml (uses [tool.cytoscnpy]):

.cytoscnpy.toml example:

[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  # Note: include_ipynb and ipynb_cells are CLI-only (use flags)

# 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
max_complexity = 10   # Max cyclomatic complexity
max_nesting = 4       # Max indentation depth
min_mi = 65.0         # Minimum Maintainability Index
ignore = ["R001"]     # Ignore specific rule IDs

# Advanced Secret Scanning
[cytoscnpy.secrets_config]
entropy_enabled = true
entropy_threshold = 4.5  # Higher = more random (API keys usually >4.0)
min_length = 16          # Min length to check for entropy
scan_comments = true     # Scan comments for secrets
skip_docstrings = false  # Skip docstrings in entropy scanning
min_score = 50           # Minimum confidence score (0-100)
suspicious_names = ["db_config", "oauth_token"] # Add custom suspicious variable names

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

Note: Notebook options (include_ipynb, ipynb_cells) are currently CLI-only but will be added to the configuration file in a future release.

CI/CD Quality Gates

Configure quality gates for CI/CD pipelines. Set thresholds and the CLI exits with code 1 if exceeded.

CLI Flags:

# Unused code percentage gate
cytoscnpy . --fail-threshold 5  # Fail if >5% unused

# Complexity gate
cytoscnpy . --max-complexity 10  # Fail if any function >10

# Maintainability Index gate
cytoscnpy . --min-mi 40  # Fail if MI <40

# Quiet mode for clean CI output
cytoscnpy . --fail-threshold 5 --quiet

Priority: CLI flag > config file > environment variable > default

Environment Variable: CYTOSCNPY_FAIL_THRESHOLD=5.0

Performance

Accuracy (Benchmark Suite: 135 items)

Detection Type Precision Recall F1 Score
Classes 0.73 0.79 0.76
Functions 0.71 0.74 0.73
Methods 0.86 0.93 0.89
Imports 0.67 0.40 0.50
Variables 0.30 0.15 0.20
Overall 0.71 0.64 0.68

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.2.2-cp314-cp314-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.2-cp314-cp314-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cytoscnpy-1.2.2-cp313-cp313-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.2.2-cp313-cp313-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cytoscnpy-1.2.2-cp312-cp312-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.2.2-cp312-cp312-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.2-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cytoscnpy-1.2.2-cp311-cp311-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.2.2-cp311-cp311-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cytoscnpy-1.2.2-cp310-cp310-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.2.2-cp39-cp39-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.9Windows x86-64

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 971004fae036c51ea62e618d2a054dc399a965a4820adea377856c5be74e13ce
MD5 e9c590fd7a2f1a50151dc5e5c25f3fa5
BLAKE2b-256 5ac55c234b6f1b71064525616899e413809d86039731736125256f69c7eef24a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58ea9cc0a7db667c89b7cf11ed06b05228b1668761eff8661ea148c101998cd4
MD5 1b7f95c4402f25597d07398f6015d69d
BLAKE2b-256 a82a2e0976f048ad6a1192b9df0d872bf6ad47e121caffa66caa1ce9bd09f598

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.1 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.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 33572d5cc28055537018634893756f77954681a7eaf3719da7d080cc8360757a
MD5 4621187f50a729562a777961306f8290
BLAKE2b-256 8fe25a127b51e4dbed6cab0924b0620f82bed9a4de5b87e3902b9b41531578cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a3bbaf88db9513e80e931884098c49a5d0c9402fbf208169cc15f980a8d361a
MD5 a455d9a04e718d501942ae77ed10856e
BLAKE2b-256 3e4cb285fbb18632f6e7041739720639e26dd33f52f91e783432ea9704632b39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.1 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.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 086519765ff22cdee0f32090a102ee7fb79eb075e3a86f29e7cd66047aca6fc2
MD5 a82e1de60b867272c050143c1f1b95df
BLAKE2b-256 3d65ec0e4cd5f7b5398e940a6ef4be9ca32fb579f65111d7926f56da13d70240

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 836c7feabaf289e599f856de81b695fac4ab2e6cc80a7673c5c4e0fe426e4c87
MD5 067ef09b63d8128d28d41b5b820eeceb
BLAKE2b-256 3d8c1226dbeda4c0f996845f96012af2cde329f0b8eedc2ae23a839bd13e7ef1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef8d1b8b288dd32fc0506f504c82a625855702a5730cdb2ff5bbcc00325d2562
MD5 39da7f8e11c67dc2c292efe4a5ebf321
BLAKE2b-256 4b76509e8826f7a2ad7d3b08f593ab00109d5255587e685df3437eb557c76698

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.1 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.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 256209e58b3b77746b5a72e8c804c491f8fd23baa88c0e73c445e49bf67780db
MD5 14ecba96fe886df501205c3f7753de3f
BLAKE2b-256 efb24c62a243a4067d22c87bbf6f96f0a2bd40fcbebe38531679897d1fe904a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e50329011332ab885c878b8d2197cbdbb65c31f047eff584fe6eab0c17f24ef1
MD5 34178b9037f60b77ae377d6f848e3e07
BLAKE2b-256 bd0ca72a805c536c7febb67d60889e78e3101e374ccc72630b4655aacebbc69c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.1 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.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 864da23b43277370c1fb043d6c8add97f04b4318ec481190cb6c68f69f103dd9
MD5 bd67442d0f3356361d0f5189622558c0
BLAKE2b-256 044470a4b06842d54390732d6694fa6bb862ea479736d1707d48248e081134ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.1 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.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4778a8a480601b334acc3fc7d67740a989a32be0858e3accac77af221929f89b
MD5 6a4a8fba2ccd7212298e33cbd3834f12
BLAKE2b-256 67557944e70f664058e079d084f741bada8746b1af52da821dff2eee90c4e7e2

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