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

# Pre-commit integration
# See https://djinn09.github.io/CytoScnPy/pre-commit/ for setup

Common Options:

Flag Description
-s, --secrets Scan for API keys and hardcoded credentials
-d, --danger Scan for dangerous code + taint analysis
-q, --quality Scan for code quality issues (complexity, etc.)
--clones Activate duplicate code detection
--fix Preview/dry-run dead code removal
-a, --apply Apply fixes to files (use with --fix)
--json Output results in machine-readable JSON

[!TIP] > View the Full CLI Reference for detailed usage, advanced configuration, and quality gate options.

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.

⚙️ 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.

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.5-cp313-cp313-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.13Windows x86-64

cytoscnpy-1.2.5-cp313-cp313-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

cytoscnpy-1.2.5-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.5-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

cytoscnpy-1.2.5-cp311-cp311-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

cytoscnpy-1.2.5-cp310-cp310-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.5-cp310-cp310-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

cytoscnpy-1.2.5-cp39-cp39-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.5-cp39-cp39-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

cytoscnpy-1.2.5-cp38-cp38-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8Windows x86-64

cytoscnpy-1.2.5-cp38-cp38-manylinux_2_39_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.39+ x86-64

cytoscnpy-1.2.5-cp38-cp38-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.5-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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d20d2194920eebce7392b94185befaf01e24a8ebc2c5e704c14e7da156b3b3d6
MD5 5411274fb816ce9d6935e4ccbc6d84fd
BLAKE2b-256 26e8589d522165e6ab435ce114fe18c4692854055602a1c072e28cc7f1ac42a5

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 9d3fd4663ff3340fbcae819c09c2f1a3fe9c326dc26b3e0090293d6bae936ebc
MD5 e1ff83ec65c6edd93cfd2f81abb9afcd
BLAKE2b-256 16d1b4e85412ec941119a11d73721aa44322bcf86fba890bde959a0a959db49d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45ab20fd2f7ab3639f8765b079c1646598b087925ee321742f3bb8bef3d3d9e2
MD5 3cf312a5824c4ce9ddcb383a2e4e7178
BLAKE2b-256 acbbe36561105205e3854d1137e0a642f7c5f1b89cdc7fd9abb7644cc203258d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.5-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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 44aa2ea14e2fe5479bbcb270e259274f75d0ab6746ec3ed2cced6e3be7dba8ad
MD5 57ed7ffb9078bd45cefaeb0f80a89670
BLAKE2b-256 f79372f23d0f2ec5d1e89b044e7f9934ae6cde217a91ea2bc26c004d03ecf2e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 4c70f925593847e5ab724febd44befe9e2673b5083548894e6f401af8936812f
MD5 1c74f6c28669900423d2f9a2ea4e75d1
BLAKE2b-256 ea8983cc063eaca6f4836e3d5130246cdb3d2d50fe2ddb36f9b2cae571ec7b54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 940802992a59ad16e33ac9a42f98350dceda17f0f759b90a76a5ffa7c7074208
MD5 e3ac4893e865805f808205e9716317b8
BLAKE2b-256 d8c904c912ed3c9e8ebd7cf8ba69e4f00f036c5c276675429e8869969ffaab99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e8bd973ef19a363fbc827ddb06742d61007d3ed2dced0a0423ea60de218a4c3c
MD5 9f399af6a80452f9570697400c17af73
BLAKE2b-256 138b958de29d73f34ffc224df12608c28c24051cd2c6a024693e7bd58af27030

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 e8fdde11c5b6d1f41999851c01214f84320933ff3551f1a69e3bb884eb217118
MD5 09c9d6fc405a43b0673ab7466cc0b226
BLAKE2b-256 117565fed000e543b23d11e792073388cf9991a70b9823def1367c26207dbac8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bd49773dcb4c7c3d0e263325266e0ded567b640ae52e0e77e99dfb0f92afdce
MD5 3ff32e4cbb106492016a9269532d1169
BLAKE2b-256 5faa846e698f5c66cff9a5ba6d3a28b46dc32531decb1efe6be9dfb6b2133187

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.5-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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ec17582d30fa1002d28bfa0e3464c303dc7dff41dbb5c306fd5629c29ed2ad5b
MD5 72ca28c1da5ab9a43f2661987172e94f
BLAKE2b-256 a8fbc04232edbdd94116b174aba73034b4dd9e2f8d397fce3456cd76b954c55c

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp310-cp310-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp310-cp310-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 8864b93ef3e4ed8f638dca888a3d7793df92ed791e2c8cd86787b061de482db0
MD5 62b121a23e3109373109188e61705bd2
BLAKE2b-256 478456b0790713e37df883f25be8c1ebb20efc75441472c91ebc981d200af9ed

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76c0fd6c640a3d5685c08c1d620a4db34a25ebc676705c08da02a25da045a260
MD5 1f11cb2ce4cbf5ace29badd4ade02251
BLAKE2b-256 c93509dd56f43a547678436f4764f24b64a949d6404d1d50d18d8055235a9acd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cytoscnpy-1.2.5-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.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ee30c6c9777098907282b878427baf9519377f813784a6bd7ca32014d8c399e3
MD5 2709ecfd5200c99106665a5000d20fd6
BLAKE2b-256 3bcc48da6e60e8bece675b60a7e4231adc25720ea641a8f463e137d2df22cc6a

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp39-cp39-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp39-cp39-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1bd1bb9c0c444b68fe8f38fd8509bc8b317ce1cb8b93c451d3310d593dcead60
MD5 82d105012fbc718f859278fb9045de40
BLAKE2b-256 9ea0f0d6fcc77693b3ac169a88fd2561d7970a9f924f6e8e1f6cac0151d1d32e

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2c5603b904baa04b8c18efc3057b957816ba35b5acd9cf231ded5cd25ebff04
MD5 fb82456a0fd114e4b26fe5da41e1e1dd
BLAKE2b-256 35161bf927612089c35148cf462d640bb6048bcf74bcd0eb006ab512522e7440

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cytoscnpy-1.2.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.1 MB
  • Tags: CPython 3.8, 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.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4b1d81b57a1127a6fffade003faf75cb3d836458b3d4d873b383a4a1495dabec
MD5 b708ec1e93d1edbcd7056f8f5afa385c
BLAKE2b-256 488b6deb1011be60e75ea044049db9ac05f6334a0c8b770a72eab266059d93fa

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp38-cp38-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp38-cp38-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 bf8f9e0aa811a914a532b78b5a43930a110967538d24a7cc476849cff06a4e71
MD5 66007c314d42e10f7084874f83805490
BLAKE2b-256 c02957e0895678f7dd1edd59412c2ebc2571dbf70b1dcc615896f150a286cebc

See more details on using hashes here.

File details

Details for the file cytoscnpy-1.2.5-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cytoscnpy-1.2.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ed0cd3086bd9147e7099287df253169fcd3a1db80a3cd4fc7c1672db9bb8aed
MD5 b1c8e8e0de8f37b6ada028df97524554
BLAKE2b-256 d484876acb176feaac1cbc00f5f3f98e5a9fd439cee30774df0d27ce3e822ba0

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